From d5d8fccfb429c655318a0bad82d7f14a6cddceeb Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 26 Mar 2020 08:53:05 -0400 Subject: [PATCH] Add gitsrht-initdb (file missing) --- gitsrht-initdb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 gitsrht-initdb diff --git a/gitsrht-initdb b/gitsrht-initdb new file mode 100755 index 0000000..ecc007a --- /dev/null +++ b/gitsrht-initdb @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +""" +Create the initial database schema and stamp the `head` revision. + +The target database needs to exist, as defined in the config file. + +Idempotent. If the tables already exist, they will not be re-created. +""" +import gitsrht.alembic +import gitsrht.types + +from alembic import command +from alembic.config import Config +from srht.config import cfg +from srht.database import DbSession + +connection_string = cfg("git.sr.ht", "connection-string") +alembic_path = list(gitsrht.alembic.__path__)[0] + +db = DbSession(connection_string) +db.create() + +config = Config() +config.set_main_option("sqlalchemy.url", connection_string) +config.set_main_option("script_location", alembic_path) +command.stamp(config, "head") -- 2.38.4