Add gitsrht-initdb (file missing)

This commit is contained in:
Drew DeVault 2020-03-26 08:53:05 -04:00
parent 4bd42f0e1e
commit d5d8fccfb4
1 changed files with 26 additions and 0 deletions

26
gitsrht-initdb Executable file
View File

@ -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")