Skip to content

Commit

Permalink
Update init_db.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pdr21001 authored Apr 23, 2025
1 parent 825bc46 commit 0f3388d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions backend/init_db.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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)

0 comments on commit 0f3388d

Please sign in to comment.