Skip to content

Commit

Permalink
only create file if it doesn't exist yet
Browse files Browse the repository at this point in the history
  • Loading branch information
cmelone committed Apr 23, 2024
1 parent 6b9f5e0 commit 90af485
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion db/init_db.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import os
import sqlite3
import sys

# Usage: python init_db.py <db_path>
# loads in default tables and future schema changes into the database
db_path = sys.argv[1]

# check if the database exists as a file
if os.path.isfile(db_path):
print(f"database {db_path} already exists")
sys.exit(0)

try:
conn = sqlite3.connect(db_path)
c = conn.cursor()
Expand All @@ -16,4 +22,4 @@
print(e)
sys.exit(1)

print(f"Database initialized successfully to {db_path}")
print(f"database initialized successfully to {db_path}")

0 comments on commit 90af485

Please sign in to comment.