|
@@ -82,29 +82,32 @@ handle_peewee_migration(DATABASE_URL)
|
|
SQLALCHEMY_DATABASE_URL = DATABASE_URL
|
|
SQLALCHEMY_DATABASE_URL = DATABASE_URL
|
|
|
|
|
|
# Handle SQLCipher URLs
|
|
# Handle SQLCipher URLs
|
|
-if SQLALCHEMY_DATABASE_URL.startswith('sqlite+sqlcipher://'):
|
|
|
|
|
|
+if SQLALCHEMY_DATABASE_URL.startswith("sqlite+sqlcipher://"):
|
|
database_password = os.environ.get("DATABASE_PASSWORD")
|
|
database_password = os.environ.get("DATABASE_PASSWORD")
|
|
if not database_password or database_password.strip() == "":
|
|
if not database_password or database_password.strip() == "":
|
|
- raise ValueError("DATABASE_PASSWORD is required when using sqlite+sqlcipher:// URLs")
|
|
|
|
-
|
|
|
|
|
|
+ raise ValueError(
|
|
|
|
+ "DATABASE_PASSWORD is required when using sqlite+sqlcipher:// URLs"
|
|
|
|
+ )
|
|
|
|
+
|
|
# Extract database path from SQLCipher URL
|
|
# Extract database path from SQLCipher URL
|
|
- db_path = SQLALCHEMY_DATABASE_URL.replace('sqlite+sqlcipher://', '')
|
|
|
|
- if db_path.startswith('/'):
|
|
|
|
|
|
+ db_path = SQLALCHEMY_DATABASE_URL.replace("sqlite+sqlcipher://", "")
|
|
|
|
+ if db_path.startswith("/"):
|
|
db_path = db_path[1:] # Remove leading slash for relative paths
|
|
db_path = db_path[1:] # Remove leading slash for relative paths
|
|
-
|
|
|
|
|
|
+
|
|
# Create a custom creator function that uses sqlcipher3
|
|
# Create a custom creator function that uses sqlcipher3
|
|
def create_sqlcipher_connection():
|
|
def create_sqlcipher_connection():
|
|
import sqlcipher3
|
|
import sqlcipher3
|
|
|
|
+
|
|
conn = sqlcipher3.connect(db_path, check_same_thread=False)
|
|
conn = sqlcipher3.connect(db_path, check_same_thread=False)
|
|
conn.execute(f"PRAGMA key = '{database_password}'")
|
|
conn.execute(f"PRAGMA key = '{database_password}'")
|
|
return conn
|
|
return conn
|
|
-
|
|
|
|
|
|
+
|
|
engine = create_engine(
|
|
engine = create_engine(
|
|
"sqlite://", # Dummy URL since we're using creator
|
|
"sqlite://", # Dummy URL since we're using creator
|
|
creator=create_sqlcipher_connection,
|
|
creator=create_sqlcipher_connection,
|
|
- echo=False
|
|
|
|
|
|
+ echo=False,
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
log.info("Connected to encrypted SQLite database using SQLCipher")
|
|
log.info("Connected to encrypted SQLite database using SQLCipher")
|
|
|
|
|
|
elif "sqlite" in SQLALCHEMY_DATABASE_URL:
|
|
elif "sqlite" in SQLALCHEMY_DATABASE_URL:
|