]>
Commit | Line | Data |
---|---|---|
047d4d29 MR |
1 | #!flask/bin/python |
2 | import imp | |
3 | from migrate.versioning import api | |
4 | from app import db | |
5 | from config import SQLALCHEMY_DATABASE_URI | |
6 | from config import SQLALCHEMY_MIGRATE_REPO | |
7 | v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) | |
8 | migration = SQLALCHEMY_MIGRATE_REPO + ('/versions/%03d_migration.py' % (v+1)) | |
9 | tmp_module = imp.new_module('old_model') | |
10 | old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) | |
11 | exec(old_model, tmp_module.__dict__) | |
12 | script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata) | |
13 | open(migration, "wt").write(script) | |
14 | api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) | |
15 | v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) | |
16 | print('New migration saved as ' + migration) | |
17 | print('Current database version: ' + str(v)) |