Skip to content

Commit

Permalink
Merge pull request #22 from CSE2102-Spring25/develop-prince
Browse files Browse the repository at this point in the history
Develop prince
  • Loading branch information
sed19015 authored Apr 18, 2025
2 parents d739054 + f696da3 commit a12a7d3
Show file tree
Hide file tree
Showing 4 changed files with 459 additions and 308 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/backend/animal_shelter.db
/backend/test_animal_shelter.db
/frontend/node_modules

# ignore sqlite db file
animal_shelter.db
43 changes: 43 additions & 0 deletions backend/db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import sqlite3
import os

def init_db():
"""Initialize the database, creating tables and inserting initial data."""
db_path = os.path.join(os.path.dirname(__file__), 'animal_shelter.db')

if os.path.exists(db_path):
print("Database already initialized.")
return

# Connect to SQLite database (it will create the file if it doesn't exist)
conn = sqlite3.connect(db_path)
cursor = conn.cursor()

# Create tables
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
)''')

# Insert initial data (e.g., a test animal)
cursor.execute('''INSERT INTO animals (name, species, breed, age, personality, image_path)
VALUES (?, ?, ?, ?, ?, ?)''',
('TestDog', 'Dog', 'Mixed', 2, 'Friendly', '/images/test.jpg'))

conn.commit()
conn.close()
print("Database initialized and initial data inserted.")
Loading

0 comments on commit a12a7d3

Please sign in to comment.