Skip to content

Commit

Permalink
Update db.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pdr21001 authored Apr 23, 2025
1 parent d6277a1 commit 767c8d9
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions backend/db.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""Database utility functions for managing the pet adoption database."""

import sqlite3
import os

Expand All @@ -16,30 +14,34 @@ def init_db():
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
)''')
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'))
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()
Expand Down

0 comments on commit 767c8d9

Please sign in to comment.