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