blob: 7f2b1303e17b531056778f0cbbfafcffd935bfab [file] [log] [blame]
stgleb75c70412015-02-17 02:52:00 +02001import imp
2from migrate.versioning import api
3from config import SQLALCHEMY_MIGRATE_REPO, DATABASE_URI
4from web_app.app import db
5
6
7v = api.db_version(DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
8migration = SQLALCHEMY_MIGRATE_REPO + ('/versions/%03d_migration.py' % (v+1))
9tmp_module = imp.new_module('old_model')
10old_model = api.create_model(DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
11
12exec old_model in tmp_module.__dict__
13script = api.make_update_script_for_model(DATABASE_URI,
14 SQLALCHEMY_MIGRATE_REPO,
15 tmp_module.meta, db.metadata)
16open(migration, "wt").write(script)
17api.upgrade(DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
18v = api.db_version(DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
19print('New migration saved as ' + migration)
20print('Current database version: ' + str(v))