-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathcreatedb.py
More file actions
58 lines (44 loc) · 1.65 KB
/
Copy pathcreatedb.py
File metadata and controls
58 lines (44 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""createdb"""
import os
from argparse import ArgumentParser
from pathlib import Path
from alembic import command
from alembic.config import Config
from anitya.app import create
from anitya.config import load
from anitya.db import db
parser = ArgumentParser()
script_dir = Path(__file__).parent.absolute()
parser.add_argument("--debug", action="store_true", default=False, dest="verbose")
parser.add_argument("--alembic-config", default=None)
parser.add_argument(
"--db-uri",
default=None,
help="This will override the URLs specified in alembic and anitya",
)
args = parser.parse_args()
alembic_config = args.alembic_config
anitya_config = load()
anitya_config["SQL_DEBUG"] = args.verbose
if args.db_uri:
anitya_config["DB_URL"] = args.db_uri
anitya_config["SQLALCHEMY_DATABASE_URI"] = args.db_uri
# An app object is required for social_auth tables to be created properly
anitya_app = create(config=anitya_config)
# Create the database itself
with anitya_app.app_context():
db.manager.sync()
# Set the alembic_version based on the current migrations available.
# This presupposes the models haven't changed outside of a migration.
#
# Default to the side-by-side alembic.ini.
if alembic_config is None:
alembic_config = os.path.join(script_dir, "alembic.ini")
if args.verbose and os.path.isfile(alembic_config):
print(f"No alembic config specified, defaulting to: {alembic_config}")
if alembic_config and os.path.isfile(alembic_config):
alembic_cfg = Config(alembic_config)
alembic_cfg.set_main_option("sqlalchemy.url", anitya_config["DB_URL"])
command.stamp(alembic_cfg, "head")