man.sr.ht/mansrht-initdb

34 lines
882 B
Plaintext
Raw Permalink Normal View History

2020-03-26 14:07:15 +01:00
#!/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 mansrht.alembic
import mansrht.types
2020-08-10 19:03:43 +02:00
import srht.alembic
2020-03-26 14:07:15 +01:00
from alembic import command
from alembic.config import Config
from srht.config import cfg
from srht.database import DbSession
connection_string = cfg("man.sr.ht", "connection-string")
alembic_path = list(mansrht.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")
2020-08-10 19:03:43 +02:00
alembic_path = list(srht.alembic.__path__)[0]
config.set_main_option("script_location", alembic_path)
command.stamp(config, "head")