Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
db debug logging
  • Loading branch information
LucifersCircle committed Dec 7, 2024
1 parent 50675f0 commit fe3c5e1
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,27 @@

# Function to initialize the database if it doesn't exist
def initialize_db():
print(f"Initializing database at: {DB_FILE}")
if os.path.exists(DB_FILE) and not os.path.isfile(DB_FILE):
print(f"Error: {DB_FILE} exists but is not a file and cannot be removed automatically.")
print("Please remove it manually and restart the application.")
return # Exit initialization to prevent further errors

if not os.path.exists(DB_FILE):
try:
conn = sqlite3.connect(DB_FILE)
conn.execute('''
CREATE TABLE IF NOT EXISTS keys (
id INTEGER PRIMARY KEY AUTOINCREMENT,
encrypted_key BLOB NOT NULL
)
''')
conn.commit()
conn.close()
print("Database initialized")
except Exception as e:
print(f"Error initializing database: {e}")
print(f"Database file does not exist. Creating a new one at: {DB_FILE}")
try:
conn = sqlite3.connect(DB_FILE)
conn.execute('''
CREATE TABLE IF NOT EXISTS keys (
id INTEGER PRIMARY KEY AUTOINCREMENT,
encrypted_key BLOB NOT NULL
)
''')
conn.commit()
conn.close()
print("Database initialized successfully.")
except Exception as e:
print(f"Error initializing database: {e}")

# Initialize database on startup
initialize_db()
Expand Down

0 comments on commit fe3c5e1

Please sign in to comment.