From 86a0b5f539d62620ee97daa61e4d6ea92353fedc Mon Sep 17 00:00:00 2001 From: Sean Dombrofski Date: Thu, 17 Apr 2025 18:00:34 -0400 Subject: [PATCH] Adding rough draft db initialization file and updated .gitignore to prevent including db itself or future front-end node modules --- backend/init_db.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 backend/init_db.py diff --git a/backend/init_db.py b/backend/init_db.py new file mode 100644 index 0000000..e26870a --- /dev/null +++ b/backend/init_db.py @@ -0,0 +1,53 @@ +import sqlite3 +import random + +def create_database_tables(conn): + cursor = conn.cursor() + cursor.execute(''' + CREATE TABLE IF NOT EXISTS animals ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + species TEXT NOT NULL, + breed TEXT, + age INTEGER, + personality TEXT, + image_path TEXT, + adoption_status TEXT DEFAULT 'Available' + ) + ''') + cursor.execute(''' + CREATE TABLE IF NOT EXISTS adopters ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + username TEXT UNIQUE NOT NULL, + password TEXT NOT NULL, + email TEXT UNIQUE, + join_date TEXT DEFAULT CURRENT_TIMESTAMP + ) + ''') + conn.commit() + +def populate_initial_data(conn): + cursor = conn.cursor() + + # Sample animals data + animals = [ + ('Luna', 'Dog', 'Labrador Mix', 2, 'Playful and energetic', '/images/luna.jpg', 'Available'), + ('Oliver', 'Cat', 'Tabby', 4, 'Independent but affectionate', '/images/oliver.jpg', 'Available'), + ('Max', 'Dog', 'German Shepherd', 3, 'Loyal and intelligent', '/images/max.jpg', 'Available') + ] + + for animal in animals: + cursor.execute(''' + INSERT INTO animals (name, species, breed, age, personality, image_path, adoption_status) + VALUES (?, ?, ?, ?, ?, ?, ?) + ''', animal) + + conn.commit() + +if __name__ == "__main__": + print("Initializing pet adoption database...") + conn = sqlite3.connect('animal_shelter.db') + create_database_tables(conn) + populate_initial_data(conn) + print("Database setup complete!") + conn.close() \ No newline at end of file