-
Notifications
You must be signed in to change notification settings - Fork 0
/
createdb.py
44 lines (32 loc) · 1.02 KB
/
createdb.py
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
#!/usr/bin/env python
from __future__ import print_function, unicode_literals
import argparse
import os
from sqlalchemy import create_engine
import pagure.config
from pagure_taiga.model import BASE, PagureTaiga, PagureTaigaMapping
parser = argparse.ArgumentParser(
description="Create/Update the Pagure database"
)
parser.add_argument(
"--config",
"-c",
dest="config",
help="Configuration file to use for pagure.",
)
args = parser.parse_args()
if args.config:
config = args.config
if not config.startswith("/"):
here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
config = os.path.join(here, config)
os.environ["PAGURE_CONFIG"] = config
pagure.config.reload_config()
db_url = pagure.config.config.get("DB_URL")
if db_url.startswith("postgres"):
engine = create_engine(db_url, echo=True, client_encoding="utf8")
else:
engine = create_engine(db_url, echo=True)
BASE.metadata.create_all(
engine, tables=[PagureTaiga.__table__, PagureTaigaMapping.__table__]
)