Revision 6a82f89f snf-pithos-backend/pithos/backends/migrate.py
b/snf-pithos-backend/pithos/backends/migrate.py | ||
---|---|---|
46 | 46 |
import sys |
47 | 47 |
import os |
48 | 48 |
|
49 |
from alembic.config import main as alembic_main |
|
49 |
from alembic.config import main as alembic_main, Config |
|
50 |
from alembic import context, command |
|
51 |
|
|
50 | 52 |
from pithos.backends.lib import sqlalchemy as sqlalchemy_backend |
53 |
from pithos.backends.lib.sqlalchemy import node, groups, public, xfeatures |
|
54 |
|
|
55 |
import sqlalchemy as sa |
|
51 | 56 |
|
52 | 57 |
DEFAULT_ALEMBIC_INI_PATH = os.path.join( |
53 | 58 |
os.path.abspath(os.path.dirname(sqlalchemy_backend.__file__)), |
54 | 59 |
'alembic.ini') |
55 | 60 |
|
61 |
def initialize_db(): |
|
62 |
alembic_cfg = Config(DEFAULT_ALEMBIC_INI_PATH) |
|
63 |
engine = sa.engine_from_config( |
|
64 |
alembic_cfg.get_section(alembic_cfg.config_ini_section), prefix='sqlalchemy.') |
|
65 |
node.create_tables(engine) |
|
66 |
groups.create_tables(engine) |
|
67 |
public.create_tables(engine) |
|
68 |
xfeatures.create_tables(engine) |
|
69 |
|
|
70 |
# then, load the Alembic configuration and generate the |
|
71 |
# version table, "stamping" it with the most recent rev: |
|
72 |
command.stamp(alembic_cfg, "head") |
|
73 |
|
|
74 |
|
|
75 |
|
|
56 | 76 |
def main(argv=None, **kwargs): |
57 | 77 |
if not argv: |
58 | 78 |
argv = sys.argv |
59 |
|
|
79 |
|
|
60 | 80 |
# clean up args |
61 | 81 |
argv.pop(0) |
82 |
|
|
83 |
if argv[0] == 'initdb': |
|
84 |
initialize_db() |
|
85 |
return |
|
62 | 86 |
|
63 | 87 |
# default config arg, if not already set |
64 | 88 |
if not '-c' in argv: |
Also available in: Unified diff