From e007e4facb16f0defc56acccbf8eccef73fa756e Mon Sep 17 00:00:00 2001 From: Prince D Rusweka Rwabongoya Date: Wed, 23 Apr 2025 18:37:26 -0400 Subject: [PATCH] Update init_db.py --- backend/init_db.py | 38 ++------------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/backend/init_db.py b/backend/init_db.py index 98195e5..7b63e84 100644 --- a/backend/init_db.py +++ b/backend/init_db.py @@ -2,43 +2,11 @@ import sqlite3 import os +from utils import create_tables # Constants DB_PATH = os.path.join(os.path.dirname(__file__), 'animal_shelter.db') - -def create_database_tables(conn): - """Create tables for the database if they do not exist.""" - cursor = conn.cursor() - - # Animals table creation - 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' - ) - ''') - - # Adopters table creation - 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): """Populate the database with initial data for testing.""" cursor = conn.cursor() @@ -58,13 +26,12 @@ def populate_initial_data(conn): conn.commit() - def initialize_database(db_path): """Initialize the database by creating tables and populating initial data.""" conn = sqlite3.connect(db_path) # Create the database tables - create_database_tables(conn) + create_tables(conn) # Populate the database with initial data populate_initial_data(conn) @@ -72,6 +39,5 @@ def initialize_database(db_path): conn.close() print("Database initialized successfully with initial data.") - if __name__ == "__main__": initialize_database(DB_PATH)