Revision e3240ba0
b/snf-pithos-backend/pithos/backends/migrate.py | ||
---|---|---|
52 | 52 |
from pithos.backends.lib import sqlalchemy as sqlalchemy_backend |
53 | 53 |
from pithos.backends.lib.sqlalchemy import node, groups, public, xfeatures |
54 | 54 |
|
55 |
from synnefo.settings import PITHOS_BACKEND_DB_CONNECTION |
|
56 |
|
|
55 | 57 |
import sqlalchemy as sa |
56 | 58 |
|
57 | 59 |
DEFAULT_ALEMBIC_INI_PATH = os.path.join( |
58 | 60 |
os.path.abspath(os.path.dirname(sqlalchemy_backend.__file__)), |
59 | 61 |
'alembic.ini') |
60 | 62 |
|
63 |
|
|
61 | 64 |
def initialize_db(): |
62 | 65 |
alembic_cfg = Config(DEFAULT_ALEMBIC_INI_PATH) |
66 |
|
|
67 |
db = alembic_cfg.get_main_option("sqlalchemy.url", PITHOS_BACKEND_DB_CONNECTION) |
|
68 |
alembic_cfg.set_main_option("sqlalchemy.url", db) |
|
69 |
|
|
63 | 70 |
engine = sa.engine_from_config( |
64 |
alembic_cfg.get_section(alembic_cfg.config_ini_section), prefix='sqlalchemy.') |
|
71 |
alembic_cfg.get_section(alembic_cfg.config_ini_section), |
|
72 |
prefix='sqlalchemy.') |
|
73 |
|
|
65 | 74 |
node.create_tables(engine) |
66 | 75 |
groups.create_tables(engine) |
67 | 76 |
public.create_tables(engine) |
68 | 77 |
xfeatures.create_tables(engine) |
69 |
|
|
78 |
|
|
70 | 79 |
# then, load the Alembic configuration and generate the |
71 | 80 |
# version table, "stamping" it with the most recent rev: |
72 | 81 |
command.stamp(alembic_cfg, "head") |
... | ... | |
76 | 85 |
def main(argv=None, **kwargs): |
77 | 86 |
if not argv: |
78 | 87 |
argv = sys.argv |
79 |
|
|
88 |
|
|
80 | 89 |
# clean up args |
81 | 90 |
argv.pop(0) |
82 |
|
|
83 |
if argv[0] == 'initdb': |
|
91 |
|
|
92 |
if len(argv) >= 1 and argv[0] == 'initdb': |
|
93 |
print "Initializing db." |
|
84 | 94 |
initialize_db() |
85 |
return |
|
95 |
print "DB initialized." |
|
96 |
exit(1) |
|
97 |
|
|
86 | 98 |
|
87 | 99 |
# default config arg, if not already set |
88 | 100 |
if not '-c' in argv: |
Also available in: Unified diff