From 4a79cefdf5d71715b6c575d5c8bb4fea418c2ba6 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Mon, 29 Jun 2020 16:06:35 +0200 Subject: Prepare opendc repository for monorepo This change prepares the opendc repository for a monorepo setup by moving all files to the core/ directory. After all repositories have been merged into this repository, we will move the correct files back. --- core/database/rebuild-database.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 core/database/rebuild-database.py (limited to 'core/database/rebuild-database.py') diff --git a/core/database/rebuild-database.py b/core/database/rebuild-database.py new file mode 100644 index 00000000..0cbeb27a --- /dev/null +++ b/core/database/rebuild-database.py @@ -0,0 +1,32 @@ +import os +import sqlite3 +import sys + +sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) + +try: + BASE_DIR = directory_name=sys.argv[1] +except: + BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +db_location = os.path.join(BASE_DIR, 'opendc.db') + +if os.path.exists(db_location): + print "Removing old database..." + os.remove(db_location) + +print "Connecting to new database..." +conn = sqlite3.connect(db_location) +c = conn.cursor() + +print "Importing schema..." +with open('schema.sql') as schema: + c.executescript(schema.read()) + +print "Importing test data..." +with open('test.sql') as test: + c.executescript(test.read()) + +conn.commit() +conn.close() + +print "Done." -- cgit v1.2.3