stgleb | 75c7041 | 2015-02-17 02:52:00 +0200 | [diff] [blame^] | 1 | import imp |
| 2 | from migrate.versioning import api |
| 3 | from config import SQLALCHEMY_MIGRATE_REPO, DATABASE_URI |
| 4 | from web_app.app import db |
| 5 | |
| 6 | |
| 7 | v = api.db_version(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(DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) |
| 11 | |
| 12 | exec old_model in tmp_module.__dict__ |
| 13 | script = api.make_update_script_for_model(DATABASE_URI, |
| 14 | SQLALCHEMY_MIGRATE_REPO, |
| 15 | tmp_module.meta, db.metadata) |
| 16 | open(migration, "wt").write(script) |
| 17 | api.upgrade(DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) |
| 18 | v = api.db_version(DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) |
| 19 | print('New migration saved as ' + migration) |
| 20 | print('Current database version: ' + str(v)) |