From 90af485a1bfee53b12e22fda02f4696585e2e21f Mon Sep 17 00:00:00 2001 From: caetano melone Date: Tue, 23 Apr 2024 13:44:39 -0700 Subject: [PATCH] only create file if it doesn't exist yet --- db/init_db.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/db/init_db.py b/db/init_db.py index 53ae179..35f7bfc 100644 --- a/db/init_db.py +++ b/db/init_db.py @@ -1,3 +1,4 @@ +import os import sqlite3 import sys @@ -5,6 +6,11 @@ # 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() @@ -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}")