From 0d2cfd56cb3761e2025a75313216ee78eeee1e98 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 28 Aug 2024 08:17:05 +0000 Subject: [PATCH] Add missing create_db.py script --- create_db.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 create_db.py diff --git a/create_db.py b/create_db.py new file mode 100755 index 0000000..2c1c6f9 --- /dev/null +++ b/create_db.py @@ -0,0 +1,35 @@ +#!/usr/bin/python3 + +from sqlalchemy.schema import CreateIndex, CreateTable + +from matcher import database, model + +DB_URL = "postgresql:///matcher" +database.init_db(DB_URL) + + +def create_db(): + model.Base.metadata.create_all(database.session.get_bind()) + + +def print_create_table(classes): + database.init_db(DB_URL) + + engine = database.session.get_bind() + + for cls in classes: + sql = str(CreateTable(cls.__table__).compile(engine)) + print(sql.strip() + ";") + + for index in cls.__table__.indexes: + sql = str(CreateIndex(index).compile(engine)) + print(sql.strip() + ";") + + +# print_create_table([model.ItemIsA]) +# print_create_table([model.EditSession]) +# print_create_table([model.Changeset, model.ChangesetEdit, model.SkipIsA]) +# print_create_table([model.User]) +# print_create_table([model.Extract]) + +create_db()