From 51c9fed15381421c4b7e8ba95af60b5204483d50 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sun, 5 Jun 2022 14:20:40 +0200 Subject: First commit :baby: --- initialize_database.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 initialize_database.py (limited to 'initialize_database.py') diff --git a/initialize_database.py b/initialize_database.py new file mode 100644 index 0000000..7b7226b --- /dev/null +++ b/initialize_database.py @@ -0,0 +1,24 @@ +# -*- mode: python; -*- + +import os +from app import create_app, db + + +app = create_app() +DB_NAME = "mdl.db" +app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + DB_NAME +db_path = f"app/{DB_NAME}" + + +if os.path.exists(db_path): + os.remove(db_path) + print(f"Existing database {db_path} has been deleted successfully.") +else: + print(f"Database {db_path} does not exist yet, creating now.") + +with app.app_context(): + print(f"Creating database {db_path}...") + db.create_all() + + +print(f"Database {db_path} created successfully.") -- cgit v1.2.3