Ejemplo n.º 1
0
def _generateMigrationScript(dryrun):
    newVersion = findMaxAvailableVersion() + 1
    migration = SQLALCHEMY_MIGRATE_REPO + \
                '/versions/%03d_migration.py' % (newVersion)
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(SQLALCHEMY_DATABASE_URI,
                                 SQLALCHEMY_MIGRATE_REPO)

    exec old_model in tmp_module.__dict__
    script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI,
                                              SQLALCHEMY_MIGRATE_REPO,
                                              tmp_module.meta,
                                              db.metadata)
    if not dryrun:
        open(migration, "wt").write(script)
        api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
        print 'New migration saved as ' + migration
        print 'Current database version: ' + \
              str(api.db_version(SQLALCHEMY_DATABASE_URI,
                                 SQLALCHEMY_MIGRATE_REPO))
    else:
        print 'Dryrun:'
        print '\nNew migration will be as ' + migration
        print '\nNew migration script will be:\n"\n%s"' % str(script)
        print '\nNew database version will be: ' + str(newVersion)
Ejemplo n.º 2
0
def migrate(args):
    """
    Create DB migrations for current version
    """

    # Get the configruation
    config = get_config()
    DB_URI = config.DATABASE_URI
    M_REPO = config.MIGRATIONS

    v = api.db_version(DB_URI, M_REPO)
    m = os.path.join(M_REPO, 'versions', '%03d_migration.py' % (v + 1))

    tmpmod = imp.new_module('old_model')
    oldmod = api.create_model(DB_URI, M_REPO)
    exec(oldmod, tmpmod.__dict__)

    script = api.make_update_script_for_model(
        DB_URI, M_REPO, tmpmod.meta, elmr.db.metadata
    )

    with open(m, 'wt') as f:
        f.write(script)

    v = api.db_version(DB_URI, M_REPO)

    return "New migration saved as %s\nCurrent database version: %d" % (m, v)
Ejemplo n.º 3
0
def migratedb():
    """ Updates the database and SQLAlchemy-migrate repository
        to a new version containing all of the tables defined
        in the SQLAlchemy data models.
    """

    # Obtain Current Verison
    ver = api.db_version(app.config['SQLALCHEMY_DATABASE_URI'],
                         app.config['SQLALCHEMY_MIGRATE_REPO'])

    # Create Migration Script To Apply Model Changes
    mgr = app.config['SQLALCHEMY_MIGRATE_REPO'] +\
        ('/versions/%03d_migration.py' % (ver+1))
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(app.config['SQLALCHEMY_DATABASE_URI'],
                                 app.config['SQLALCHEMY_MIGRATE_REPO'])
    exec(old_model, tmp_module.__dict__)
    script = api.make_update_script_for_model(
        app.config['SQLALCHEMY_DATABASE_URI'],
        app.config['SQLALCHEMY_MIGRATE_REPO'],
        tmp_module.meta, db.metadata)
    open(mgr, "wt").write(script)

    # Update Database With Migration Script
    api.upgrade(app.config['SQLALCHEMY_DATABASE_URI'],
                app.config['SQLALCHEMY_MIGRATE_REPO'])

    # Obtain & Display Current Version & Migration
    ver = api.db_version(app.config['SQLALCHEMY_DATABASE_URI'],
                         app.config['SQLALCHEMY_MIGRATE_REPO'])
    print('New migration saved as: ' + mgr)
    print('Current databse version: ' + str(ver))
Ejemplo n.º 4
0
 def __init__(self,database):
     migration=SQLALCHEMY_MIGRATE_CONT+"/versions/%03d_migration.py" % (api.db_version(SQLALCHEMY_DATABASE_URI,SQLALCHEMY_MIGRATE_CONT)+1)
     tmp_module=imp.new_module("old_model")
     old_model=api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_CONT)
     exec old_model in tmp_module.__dict__
     script=api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_CONT, tmp_module.meta, database.metadata)
     open(migration,"wt").write(script)
     a=api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_CONT)
Ejemplo n.º 5
0
def migrate_database():
    migration = c.SQLALCHEMY_MIGRATE_REPO + '/versions/%03d_migration.py' % (api.db_version(c.SQLALCHEMY_DATABASE_URI, c.SQLALCHEMY_MIGRATE_REPO) + 1)
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(c.SQLALCHEMY_DATABASE_URI, c.SQLALCHEMY_MIGRATE_REPO)
    exec old_model in tmp_module.__dict__
    script = api.make_update_script_for_model(c.SQLALCHEMY_DATABASE_URI, c.SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
    open(migration, "wt").write(script)
    api.upgrade(c.SQLALCHEMY_DATABASE_URI, c.SQLALCHEMY_MIGRATE_REPO)
    print 'New migration saved as ' + migration
    print 'Current database version: ' + str(api.db_version(c.SQLALCHEMY_DATABASE_URI, c.SQLALCHEMY_MIGRATE_REPO))
Ejemplo n.º 6
0
def migratedb():
    """Creates a migration file and version."""
    migration = app.config.get('SQLALCHEMY_MIGRATE_REPO') + '/versions/%03d_migration.py' % (api.db_version(app.config.get('SQLALCHEMY_DATABASE_URI'), app.config.get('SQLALCHEMY_MIGRATE_REPO')) + 1)
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(app.config.get('SQLALCHEMY_DATABASE_URI'), app.config.get('SQLALCHEMY_MIGRATE_REPO'))
    exec old_model in tmp_module.__dict__
    script = api.make_update_script_for_model(app.config.get('SQLALCHEMY_DATABASE_URI'), app.config.get('SQLALCHEMY_MIGRATE_REPO'), tmp_module.meta, db.metadata)
    open(migration, "wt").write(script)
    api.upgrade(app.config.get('SQLALCHEMY_DATABASE_URI'), app.config.get('SQLALCHEMY_MIGRATE_REPO'))
    print 'New migration saved as ' + migration
    print 'Current database version: ' + str(api.db_version(app.config.get('SQLALCHEMY_DATABASE_URI'), app.config.get('SQLALCHEMY_MIGRATE_REPO')))
Ejemplo n.º 7
0
def migrate():
    from migrate.versioning import api
    migration = SQLALCHEMY_MIGRATE_REPO + '/versions/%03d_migration.py' % (api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) + 1)
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    exec old_model in tmp_module.__dict__
    script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
    open(migration, "wt").write(script)
    api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    print u'Миграция успешна: ' + migration
    print u'Версия базы данных: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO))
Ejemplo n.º 8
0
def migrate_db():
    migration = os.path.join(MG_REPO, 'versions', '%03d_migration.py' % (api.db_version(DB_URI, MG_REPO) + 1))
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(DB_URI, MG_REPO)
    exec(old_model, tmp_module.__dict__)
    script = api.make_update_script_for_model(DB_URI, MG_REPO, tmp_module.meta, db.metadata)
    # ?
    open(migration, 'wt').write(script)
    api.upgrade(DB_URI, MG_REPO)
    print('New migration saved as ' + migration)
    print('Current database version: ' + str(api.db_version(DB_URI, MG_REPO)))
Ejemplo n.º 9
0
def migrate_db():
    import imp
    v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    migration = SQLALCHEMY_MIGRATE_REPO + ('/versions/%03d_migration.py' % (v+1))
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    exec(old_model, tmp_module.__dict__)
    script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, Base.metadata)
    open(migration, "wt").write(script)
    api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
Ejemplo n.º 10
0
def db_migrate():
    import imp
    migration = SQLALCHEMY_MIGRATE_REPO + '/versions/%03d_migration.py' % (api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) + 1)
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    #exec old_model in tmp_module.__dict__ # python2
    exec (old_model, tmp_module.__dict__)
    script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
    open(migration, "wt").write(script)
    api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    print ('New migration saved as ' + migration)
    print ('Current database version: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)))
Ejemplo n.º 11
0
def migrate_db():
    v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    migration = SQLALCHEMY_MIGRATE_REPO + ('/versions/%03d_migration.py' % (v + 1))
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    exec(old_model, tmp_module.__dict__)
    script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
    open(migration, "wt").write(script)
    api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    print('New migration saved as ' + migration)
    print('Current database version: ' + str(v))
Ejemplo n.º 12
0
def db_migrate():
    import imp
    import re
    from migrate.versioning import api
    from wpcgi.db import db
    migration = SQLALCHEMY_MIGRATE_REPO + '/versions/%04d_migration.py' % (api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) + 1)
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    exec old_model in tmp_module.__dict__
    script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
    script = re.sub('INTEGER\(.*?\)', 'INTEGER', script)
    open(migration, "wt").write(script)
    print 'New migration saved as ' + migration
Ejemplo n.º 13
0
def migrate():
    migration = SQLALCHEMY_MIGRATE_REPO + "/versions/%03d_migration.py" % (
        api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) + 1
    )
    tmp_module = imp.new_module("old_model")
    old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    exec old_model in tmp_module.__dict__
    script = api.make_update_script_for_model(
        SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata
    )
    open(migration, "wt").write(script)
    api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    print "New migration saved as " + migration
    print "Current database version: " + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO))
Ejemplo n.º 14
0
def db_migrate():
    # This is used for database migration. Newly created database should go through this as well.
    migration = SQLALCHEMY_MIGRATE_REPO + '/versions/%03d_migration.py' % (api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) + 1)
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)

    exec old_model in tmp_module.__dict__
    script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)

    open(migration, "wt").write(script)
    api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)

    print 'New migration saved as ' + migration
    print 'Current database version: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)) + '\n'
Ejemplo n.º 15
0
	def db_migrate(self):
		print "DataBase Migrate"
		import imp
		from migrate.versioning import api
		from fpost.app import db
		from fpost.config import SQLALCHEMY_DATABASE_URI
		from fpost.config import SQLALCHEMY_MIGRATE_REPO
		migration = SQLALCHEMY_MIGRATE_REPO + '/versions/%03d_migration.py' % (api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) + 1)
		tmp_module = imp.new_module('old_model')
		old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
		exec old_model in tmp_module.__dict__
		script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
		open(migration, "wt").write(script)
		api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
		print 'New migration saved as ' + migration
		print 'Current database version: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO))
Ejemplo n.º 16
0
def migrateDB():
    repo = app.config['SQLALCHEMY_MIGRATE_REPO']
    uri = app.config['SQLALCHEMY_DATABASE_URI']

    v = api.db_version(uri, repo)
    migration = repo + ('/versions/%03d_migration.py' % (v+1))
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(uri, repo)
    exec(old_model, tmp_module.__dict__)
    script = api.make_update_script_for_model(uri, repo, 
                                    tmp_module.meta, db.metadata)
    open(migration, "wt").write(script)
    api.upgrade(uri, repo)
    v = api.db_version(uri, repo)
    print('New migration saved as ' + migration)
    print('Current database version: ' + str(v))
Ejemplo n.º 17
0
def migrate():
    """Compare the database against the app models and make a migration
    and upgrade to that version"""

    version = api.db_version(uri, repo) + 1
    migration = repo + '/versions/%03d_migration.py' % version
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(uri, repo)
    exec old_model in tmp_module.__dict__
    script = api.make_update_script_for_model(uri,
                                              repo,
                                              tmp_module.meta, db.metadata)
    open(migration, "wt").write(script)
    api.upgrade(uri, repo)

    print 'New migration saved as ' + migration
    show_version()
Ejemplo n.º 18
0
def migrate_db(db_uri, migrate_repo):
    v = api.db_version(db_uri, migrate_repo)
    migration = migrate_repo + ('/versions/%03d_migration.py' % (v+1))
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(db_uri, migrate_repo)

    exec(old_model, tmp_module.__dict__)

    script = api.make_update_script_for_model(db_uri, migrate_repo, tmp_module.meta, db.metadata)

    open(migration, "wt").write(script)

    api.upgrade(db_uri, migrate_repo)

    v = api.db_version(db_uri, migrate_repo)
    print('New migration saved as ' + migration)
    print('Current database version: ' + str(v))
Ejemplo n.º 19
0
    def migrate(self):
        # DB迁移,空数据库或原始数据库的版本号是 0,每迁移一次版本加 1
        # 每次修改数据库模型的时候就需要生成新的记录(migration)
        
        dversion = self.get_current_db_version() + 1
        
        # 生成迁移脚本
        migration = self.SQLALCHEMY_MIGRATE_REPO + '/versions/%03d_migration.py' % (dversion)        
        tmp_module = imp.new_module('old_model')
        old_model = api.create_model(self.SQLALCHEMY_DATABASE_URI, self.SQLALCHEMY_MIGRATE_REPO)
        exec old_model in tmp_module.__dict__        
        script = api.make_update_script_for_model(self.SQLALCHEMY_DATABASE_URI, self.SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, self.__dba.db.metadata)
#         script = api.make_update_script_for_model(self.SQLALCHEMY_DATABASE_URI, self.SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, Base.metadata)
        open(migration, "wt").write(script)
        
        # 升级
        api.upgrade(self.SQLALCHEMY_DATABASE_URI, self.SQLALCHEMY_MIGRATE_REPO)
        print 'New migration saved as ' + migration
        print 'Current database version: ' + str(self.get_current_db_version())
Ejemplo n.º 20
0
def migrate_db():
    import imp
    from migrate.versioning import api
    from database.model import db
    
    print("Migrating the database...")
    v = api.db_version(app.config.get('SQLALCHEMY_DATABASE_URI'), app.config.get('SQLALCHEMY_MIGRATE_REPO'))
    migration = app.config.get('SQLALCHEMY_MIGRATE_REPO') + ('/versions/%03d_migration.py' % (v+1))

    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(app.config.get('SQLALCHEMY_DATABASE_URI'), app.config.get('SQLALCHEMY_MIGRATE_REPO'))
    exec(old_model, tmp_module.__dict__)

    script = api.make_update_script_for_model(app.config.get('SQLALCHEMY_DATABASE_URI'), app.config.get('SQLALCHEMY_MIGRATE_REPO'), tmp_module.meta, db.metadata)
    open(migration, "wt").write(script)

    api.upgrade(app.config.get('SQLALCHEMY_DATABASE_URI'), app.config.get('SQLALCHEMY_MIGRATE_REPO'))
    v = api.db_version(app.config.get('SQLALCHEMY_DATABASE_URI'), app.config.get('SQLALCHEMY_MIGRATE_REPO'))
    print("New migration saved as " + migration)
    print("Current database version: " + str(v))
Ejemplo n.º 21
0
def db_migrate():
    ''' Migrate the DB creating a new version '''
    import imp
    from migrate.versioning import api
    from app import db
    migration = (app.config['SQLALCHEMY_MIGRATE_REPO'] + '/versions/%03d_migration.py' %
                 (api.db_version(app.config['SQLALCHEMY_DATABASE_URI'],
                                 app.config['SQLALCHEMY_MIGRATE_REPO']) + 1))
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(app.config['SQLALCHEMY_DATABASE_URI'],
                                 app.config['SQLALCHEMY_MIGRATE_REPO'])
    exec old_model in tmp_module.__dict__
    script = api.make_update_script_for_model(app.config['SQLALCHEMY_DATABASE_URI'],
                                              app.config['SQLALCHEMY_MIGRATE_REPO'],
                                              tmp_module.meta, db.metadata)
    open(migration, "wt").write(script)
    api.upgrade(app.config['SQLALCHEMY_DATABASE_URI'], app.config['SQLALCHEMY_MIGRATE_REPO'])
    print 'New migration saved as ' + migration
    print 'Current database version: ' + str(api.db_version(
        app.config['SQLALCHEMY_DATABASE_URI'],
        app.config['SQLALCHEMY_MIGRATE_REPO']))
Ejemplo n.º 22
0
def migrate():
    # 创建迁移文件
    migration = SQLALCHEMY_MIGRATE_REPO + "/versions/%03d_migration.py" % (
        api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) + 1
    )
    # 新建模型
    tmp_module = imp.new_module("old_model")
    # 原来的模型
    old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    exec old_model in tmp_module.__dict__
    # 生成迁移脚本
    script = api.make_update_script_for_model(
        SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata
    )
    # 将更新脚本写入迁移文件
    open(migration, "wt").write(script)
    # 更新数据库到最新版本
    api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    print u"New migration saved as " + migration + u"Current database version:" + str(
        api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    )
Ejemplo n.º 23
0
def migrate_db(*opts):
    '''
    Migrates the Database to what the current codebase expects.
    '''
    migration = ''.join([SQLALCHEMY_MIGRATE_REPO, 
                        '/versions/%03d_migration.py' % (\
                            api.db_version(SQLALCHEMY_DATABASE_URI, 
                                           SQLALCHEMY_MIGRATE_REPO) + 1)])

    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(SQLALCHEMY_DATABASE_URI, 
                                 SQLALCHEMY_MIGRATE_REPO)

    exec old_model in tmp_module.__dict__
    script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, 
                                              SQLALCHEMY_MIGRATE_REPO, 
                                              tmp_module.meta, 
                                              db.metadata)
    open(migration, "wt").write(script)
    api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)

    print 'New migration saved as ' + migration
    print 'Current database version: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, 
                                                            SQLALCHEMY_MIGRATE_REPO))
Ejemplo n.º 24
0
#!flask/bin/python
import imp
from migrate.versioning import api
from app import db, app

migration = app.config['SQLALCHEMY_MIGRATE_REPO'] + '/versions/%03d_migration.py' % (api.db_version(app.config['SQLALCHEMY_DATABASE_URI'], app.config['SQLALCHEMY_MIGRATE_REPO']) + 1)
tmp_module = imp.new_module('old_model')
old_model = api.create_model(app.config['SQLALCHEMY_DATABASE_URI'], app.config['SQLALCHEMY_MIGRATE_REPO'])
exec old_model in tmp_module.__dict__
script = api.make_update_script_for_model(app.config['SQLALCHEMY_DATABASE_URI'], app.config['SQLALCHEMY_MIGRATE_REPO'], tmp_module.meta, db.metadata)
open(migration, "wt").write(script)
api.upgrade(app.config['SQLALCHEMY_DATABASE_URI'], app.config['SQLALCHEMY_MIGRATE_REPO'])
print 'New migration saved as ' + migration
print 'Current database version: ' + str(api.db_version(app.config['SQLALCHEMY_DATABASE_URI'], app.config['SQLALCHEMY_MIGRATE_REPO']))
Ejemplo n.º 25
0
'''
Created on 15 Oct 2015

@author: mbrandaoca
'''
import imp
from migrate.versioning import api
from dashboard_app import db
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
migration = SQLALCHEMY_MIGRATE_REPO + ('/versions/%03d_migration.py' % (v+1))
tmp_module = imp.new_module('old_model')
old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
exec(old_model, tmp_module.__dict__)
script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
open(migration, "wt").write(script)
api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
print('New migration saved as ' + migration)
print('Current database version: ' + str(v))
Ejemplo n.º 26
0
Copyright 2013 Patrick J. Franz
"""

from os import path

import imp
from migrate.versioning import api

import config
from app import db

if __name__ == '__main__':
    migration = path.join(config.SQLALCHEMY_MIGRATE_REPO, 'versions',
                          '%03d_migration.py' % (api.db_version(config.SQLALCHEMY_DATABASE_URI,
                                                                config.SQLALCHEMY_MIGRATE_REPO) + 1))
    tmp_module = imp.new_module('old_model')
    old_model = api.create_model(config.SQLALCHEMY_DATABASE_URI, config.SQLALCHEMY_MIGRATE_REPO)

    exec old_model in tmp_module.__dict__

    script = api.make_update_script_for_model(config.SQLALCHEMY_DATABASE_URI, config.SQLALCHEMY_MIGRATE_REPO,
                                              tmp_module.meta, db.metadata)
    with open(migration, "wt") as fp:
        fp.write(script)

    api.upgrade(config.SQLALCHEMY_DATABASE_URI, config.SQLALCHEMY_MIGRATE_REPO)

    print "New migration: %s" % migration
    print "Current database version: %s" % api.db_version(config.SQLALCHEMY_DATABASE_URI,
                                                          config.SQLALCHEMY_MIGRATE_REPO)
Ejemplo n.º 27
0
 def test_create_model(self):
     model = api.create_model(self.url, self.repo)
Ejemplo n.º 28
0
import os, sys
import migrate.versioning.api as dbm

sys.path.append(os.curdir + "\\src\\UI")
sys.path.append(os.curdir + "\\src\\DB")
sys.path.append(os.curdir + "\\src\\models")

repoName= "DB_REPO"

dbm.create(repoName, "tn")
dbm.version_control("sqlite:///src/DB/Data/stocks.db", repoName)
dbm.create_model("sqlite:///src/DB/Data/stocks.db", repoName)
Ejemplo n.º 29
0
import imp
from migrate.versioning import api
from app import db
from config import SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO

sqlalchemy_params = SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO

migration = SQLALCHEMY_MIGRATE_REPO + '/versions/%03d_migration.py' % \
            (api.db_version(*sqlalchemy_params) + 1)

tmp_module = imp.new_module('old_model')
old_model = api.create_model(*sqlalchemy_params)

exec old_model in tmp_module.__dict__
script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO,
                                          tmp_module.meta, db.metadata)

open(migration, 'wt').write(script)
api.upgrade(*sqlalchemy_params)
print 'New migration saved a' + migration
print 'Current database version: ' + str(api.db_version(*sqlalchemy_params))
Ejemplo n.º 30
0
#!~/venv/py34f/bin/python3.4
import imp
from migrate.versioning import api
from app import db
from flask import Flask
app = Flask(__name__)
# app.config.from_object(os.environ['APP_SETTINGS'])
app.config.from_object('config.DevelopmentConfig')
cfg = app.config

v = api.db_version(cfg['SQLALCHEMY_DATABASE_URI'], cfg['SQLALCHEMY_MIGRATE_REPO'])
migration = cfg['SQLALCHEMY_MIGRATE_REPO'] + ('/versions/%03d_migration.py' % (v+1))
tmp_module = imp.new_module('old_model')
old_model = api.create_model(cfg['SQLALCHEMY_DATABASE_URI'], cfg['SQLALCHEMY_MIGRATE_REPO'])
exec(old_model, tmp_module.__dict__)
script = api.make_update_script_for_model(cfg['SQLALCHEMY_DATABASE_URI'], cfg['SQLALCHEMY_MIGRATE_REPO'], tmp_module.meta, db.metadata)
open(migration, "wt").write(script)
api.upgrade(cfg['SQLALCHEMY_DATABASE_URI'], cfg['SQLALCHEMY_MIGRATE_REPO'])
v = api.db_version(cfg['SQLALCHEMY_DATABASE_URI'], cfg['SQLALCHEMY_MIGRATE_REPO'])
print('New migration saved as ' + migration)
print('Current database version: ' + str(v))
Ejemplo n.º 31
0
import imp
from migrate.versioning import api
from app import db
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO

migration = SQLALCHEMY_MIGRATE_REPO + '/versions/%03d_migration.py' % (api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) + 1)
tmp_module = imp.new_module('old_model')
old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
exec old_model in tmp_module.__dict__
script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta,
db.metadata)
open(migration, 'wt').write(script)
a = api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
print 'New migration saved as ' + migration
print 'Current database version: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO))

Ejemplo n.º 32
0
#!flask/bin/python
import types
from migrate.versioning import api
from app.database import Base
from app import app

v = api.db_version(app.config['SQLALCHEMY_DATABASE_URI'],
                   app.config['SQLALCHEMY_MIGRATE_REPO'])
migration = app.config['SQLALCHEMY_MIGRATE_REPO'] + (
    '/versions/%03d_migration.py' % (v + 1))
tmp_module = types.ModuleType('old_model')
old_model = api.create_model(app.config['SQLALCHEMY_DATABASE_URI'],
                             app.config['SQLALCHEMY_MIGRATE_REPO'])
exec(old_model, tmp_module.__dict__)
script = api.make_update_script_for_model(
    app.config['SQLALCHEMY_DATABASE_URI'],
    app.config['SQLALCHEMY_MIGRATE_REPO'], tmp_module.meta, Base.metadata)
open(migration, "wt").write(script)
api.upgrade(app.config['SQLALCHEMY_DATABASE_URI'],
            app.config['SQLALCHEMY_MIGRATE_REPO'])
v = api.db_version(app.config['SQLALCHEMY_DATABASE_URI'],
                   app.config['SQLALCHEMY_MIGRATE_REPO'])
print('New migration saved as ' + migration)
print('Current database version: ' + str(v))