Skip to content

Commit

Permalink
Adding rough draft db initialization file and updated .gitignore to p…
Browse files Browse the repository at this point in the history
…revent including db itself or future front-end node modules
  • Loading branch information
sed19015 committed Apr 17, 2025
1 parent 0a97588 commit 86a0b5f
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions backend/init_db.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 86a0b5f

Please sign in to comment.