-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding rough draft db initialization file and updated .gitignore to p…
…revent including db itself or future front-end node modules
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import sqlite3 | ||
import random | ||
|
||
def create_database_tables(conn): | ||
cursor = conn.cursor() | ||
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 | ||
) | ||
''') | ||
conn.commit() | ||
|
||
def populate_initial_data(conn): | ||
cursor = conn.cursor() | ||
|
||
# Sample animals data | ||
animals = [ | ||
('Luna', 'Dog', 'Labrador Mix', 2, 'Playful and energetic', '/images/luna.jpg', 'Available'), | ||
('Oliver', 'Cat', 'Tabby', 4, 'Independent but affectionate', '/images/oliver.jpg', 'Available'), | ||
('Max', 'Dog', 'German Shepherd', 3, 'Loyal and intelligent', '/images/max.jpg', 'Available') | ||
] | ||
|
||
for animal in animals: | ||
cursor.execute(''' | ||
INSERT INTO animals (name, species, breed, age, personality, image_path, adoption_status) | ||
VALUES (?, ?, ?, ?, ?, ?, ?) | ||
''', animal) | ||
|
||
conn.commit() | ||
|
||
if __name__ == "__main__": | ||
print("Initializing pet adoption database...") | ||
conn = sqlite3.connect('animal_shelter.db') | ||
create_database_tables(conn) | ||
populate_initial_data(conn) | ||
print("Database setup complete!") | ||
conn.close() |