def main(main_uri, rb_uri, sqla_uri, photo_path, drop, merged_avatars):
    update_session_options(db)  # get rid of the zope transaction extension
    main_root, rb_root, app = setup(main_uri, rb_uri, sqla_uri)
    global tz
    try:
        tz = pytz.timezone(main_root['MaKaCInfo']['main'].getTimezone())
    except KeyError:
        tz = pytz.utc

    start = time.clock()
    with app.app_context():
        if drop:
            print cformat('%{yellow!}*** DANGER')
            print cformat('%{yellow!}***%{reset} '
                          '%{red!}ALL DATA%{reset} in your database %{yellow!}{!r}%{reset} will be '
                          '%{red!}PERMANENTLY ERASED%{reset}!').format(db.engine.url)
            if raw_input(cformat('%{yellow!}***%{reset} To confirm this, enter %{yellow!}YES%{reset}: ')) != 'YES':
                print 'Aborting'
                sys.exit(1)
            delete_all_tables(db)
        stamp()
        db.create_all()
        if Location.find().count():
            # Usually there's no good reason to migrate with data in the DB. However, during development one might
            # comment out some migration tasks and run the migration anyway.
            print cformat('%{yellow!}*** WARNING')
            print cformat('%{yellow!}***%{reset} Your database is not empty, migration will most likely fail!')
            if raw_input(cformat('%{yellow!}***%{reset} To confirm this, enter %{yellow!}YES%{reset}: ')) != 'YES':
                print 'Aborting'
                sys.exit(1)
        migrate(main_root, rb_root, photo_path, merged_avatars)
    print 'migration took {} seconds'.format((time.clock() - start))
Пример #2
0
from sqlalchemy import engine_from_config, pool

from indico.core.db import db
from indico.core.db.sqlalchemy.util import update_session_options


# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
logging.config.fileConfig(config.config_file_name)

config.set_main_option('sqlalchemy.url', current_app.config.get('SQLALCHEMY_DATABASE_URI'))
target_metadata = current_app.extensions['migrate'].db.metadata

# Get rid of the ZODB transaction manager
update_session_options(db)


def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option('sqlalchemy.url')