diff --git a/backend/db.py b/backend/db.py index 3b88968..994231d 100644 --- a/backend/db.py +++ b/backend/db.py @@ -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.""" @@ -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()