2020-04-02 00:36:17 +02: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.
|
|
|
|
"""
|
2020-04-29 19:25:49 +02:00
|
|
|
import hubsrht.alembic
|
2020-04-02 00:36:17 +02:00
|
|
|
import hubsrht.types
|
|
|
|
|
2020-04-29 19:25:49 +02:00
|
|
|
from alembic import command
|
|
|
|
from alembic.config import Config
|
2020-04-02 00:36:17 +02:00
|
|
|
from srht.config import cfg
|
|
|
|
from srht.database import DbSession
|
|
|
|
|
|
|
|
connection_string = cfg("hub.sr.ht", "connection-string")
|
2020-04-29 19:25:49 +02:00
|
|
|
alembic_path = list(hubsrht.alembic.__path__)[0]
|
2020-04-02 00:36:17 +02:00
|
|
|
|
|
|
|
db = DbSession(connection_string)
|
|
|
|
db.create()
|
|
|
|
|
2020-04-29 19:25:49 +02:00
|
|
|
config = Config()
|
|
|
|
config.set_main_option("sqlalchemy.url", connection_string)
|
|
|
|
config.set_main_option("script_location", alembic_path)
|
|
|
|
command.stamp(config, "head")
|