diff --git a/backend/init_db.py b/backend/init_db.py index 84d5475..c70bbde 100644 --- a/backend/init_db.py +++ b/backend/init_db.py @@ -1,6 +1,11 @@ -"""Script to initialize the database and populate with initial data.""" +"""Script to initialize the database and populate it with initial data.""" import sqlite3 +import os + +# 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.""" @@ -28,6 +33,7 @@ def create_database_tables(conn): ''') conn.commit() + def populate_initial_data(conn): """Populate the database with initial data for testing.""" cursor = conn.cursor() @@ -47,6 +53,7 @@ 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) @@ -60,7 +67,6 @@ def initialize_database(db_path): conn.close() print("Database initialized successfully with initial data.") + if __name__ == "__main__": - # Path to the database - db_path = 'animal_shelter.db' - initialize_database(db_path) + initialize_database(DB_PATH)