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 604d71e commit e007e4f
Showing 1 changed file with 2 additions and 36 deletions.
38 changes: 2 additions & 36 deletions backend/init_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -58,20 +26,18 @@ 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)

conn.close()
print("Database initialized successfully with initial data.")


if __name__ == "__main__":
initialize_database(DB_PATH)

0 comments on commit e007e4f

Please sign in to comment.