From 604d71e1f9edb58d4f8550b701447734fa0e525f Mon Sep 17 00:00:00 2001 From: Prince D Rusweka Rwabongoya Date: Wed, 23 Apr 2025 18:35:50 -0400 Subject: [PATCH] utils.py for refactoring --- backend/utils.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 backend/utils.py diff --git a/backend/utils.py b/backend/utils.py new file mode 100644 index 0000000..cfe1eaf --- /dev/null +++ b/backend/utils.py @@ -0,0 +1,31 @@ +# utils.py +import sqlite3 + +def create_tables(conn): + """Create tables for the database if they do not exist.""" + 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()