From 384c6f1c8c6ea9b0b28276c2f975436357b89f2b Mon Sep 17 00:00:00 2001 From: Marius Robert Macamete Date: Wed, 17 Sep 2025 10:39:58 +0300 Subject: [PATCH] add db path --- client/models/applications.py | 16 ++++++++++------ client/models/users.py | 14 +++++++++----- docker-compose.yml | 2 ++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/client/models/applications.py b/client/models/applications.py index f19b492..99d2dfe 100644 --- a/client/models/applications.py +++ b/client/models/applications.py @@ -1,12 +1,16 @@ import sqlite3 +import os class DBApplications: def __init__(self): - self.db_path = 'instance/dev.db' + # Allow DB path override via env, default to /app/instance/dev.db inside container + default_path = os.getenv("DB_PATH", "instance/dev.db") + self.db_path = os.path.abspath(default_path) + os.makedirs(os.path.dirname(self.db_path), exist_ok=True) self.create_table() def create_table(self): - with sqlite3.connect(self.db_path) as conn: + with sqlite3.connect(self.db_path, check_same_thread=False) as conn: cursor = conn.cursor() cursor.execute(""" CREATE TABLE IF NOT EXISTS applications ( @@ -23,7 +27,7 @@ class DBApplications: def insert_application(self, user_id, name, access_code: str) -> bool: try: - with sqlite3.connect(self.db_path) as conn: + with sqlite3.connect(self.db_path, check_same_thread=False) as conn: cursor = conn.cursor() cursor.execute(""" INSERT INTO applications (user_id, name, access_code) @@ -35,7 +39,7 @@ class DBApplications: return False def get_application_by_id(self, id): - with sqlite3.connect(self.db_path) as conn: + with sqlite3.connect(self.db_path, check_same_thread=False) as conn: cursor = conn.cursor() cursor.execute(""" SELECT * FROM applications @@ -55,7 +59,7 @@ class DBApplications: return None def get_applications(self, user_id): - with sqlite3.connect(self.db_path) as conn: + with sqlite3.connect(self.db_path, check_same_thread=False) as conn: cursor = conn.cursor() cursor.execute(""" SELECT * FROM applications @@ -79,7 +83,7 @@ class DBApplications: return all_rows def delete(self, id): - with sqlite3.connect(self.db_path) as conn: + with sqlite3.connect(self.db_path, check_same_thread=False) as conn: cursor = conn.cursor() cursor.execute(""" DELETE FROM applications WHERE id = ? diff --git a/client/models/users.py b/client/models/users.py index 36cc96b..cba87ae 100644 --- a/client/models/users.py +++ b/client/models/users.py @@ -1,12 +1,16 @@ import sqlite3 +import os class Users: def __init__(self): - self.db_path = 'instance/dev.db' + # Allow DB path override via env, default to /app/instance/dev.db inside container + default_path = os.getenv("DB_PATH", "instance/dev.db") + self.db_path = os.path.abspath(default_path) + os.makedirs(os.path.dirname(self.db_path), exist_ok=True) self.create_table() def create_table(self): - with sqlite3.connect(self.db_path) as conn: + with sqlite3.connect(self.db_path, check_same_thread=False) as conn: cursor = conn.cursor() cursor.execute(""" CREATE TABLE IF NOT EXISTS users ( @@ -22,7 +26,7 @@ class Users: def insert_user(self, email, password: str) -> bool: try: - with sqlite3.connect(self.db_path) as conn: + with sqlite3.connect(self.db_path, check_same_thread=False) as conn: cursor = conn.cursor() cursor.execute(""" INSERT INTO users (email, password) @@ -34,7 +38,7 @@ class Users: return False def get_user_by_id(self, id): - with sqlite3.connect(self.db_path) as conn: + with sqlite3.connect(self.db_path, check_same_thread=False) as conn: cursor = conn.cursor() cursor.execute(""" SELECT * FROM users @@ -53,7 +57,7 @@ class Users: return None def get_user_by_email(self, email): - with sqlite3.connect(self.db_path) as conn: + with sqlite3.connect(self.db_path, check_same_thread=False) as conn: cursor = conn.cursor() cursor.execute(""" SELECT * FROM users diff --git a/docker-compose.yml b/docker-compose.yml index eb92775..db9c307 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -47,8 +47,10 @@ services: API_BASE_URL: https://${SOLARDB_API_HOST} # If your entry file differs, uncomment and set it: # FLET_ENTRY: client/main.py + USERS_DB_PATH: /app/instance/dev.db volumes: - solardb_uploads:/app/uploads + - solardb_ui_data:/app/instance expose: - "5555" depends_on: