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 4cd6929 commit 1c1bdb2
Showing 1 changed file with 7 additions and 32 deletions.
39 changes: 7 additions & 32 deletions backend/db.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""
Database utility functions for managing the pet adoption database.
"""
"""Database utility functions for managing the pet adoption database."""

import sqlite3
import os
from utils import create_tables

def init_db():
"""Initialize the database, creating tables and inserting initial data."""
Expand All @@ -15,37 +14,13 @@ def init_db():

# 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
)
''')
create_tables(conn)

# 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 = conn.cursor()
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 1c1bdb2

Please sign in to comment.