Пример #1
0
def test_migrations(app_before_init_db):
    """The database migrations complete successfully."""
    app, conf_obj = app_before_init_db

    dbp.connect()

    if conf_obj.database.engine == "PostgresqlDatabase":
        dbp.execute_sql("DROP SCHEMA public CASCADE;")
        dbp.execute_sql("CREATE SCHEMA public;")
        dbp.execute_sql("GRANT ALL ON SCHEMA public TO public;")

    router = Router(dbp, migrate_dir="migrations", ignore=["basemodel"])
    router.run()

    applied_migrations = list(router.done)
    applied_migrations.reverse()

    # Shut up a warning in rollback that we can't do anything about.
    logging.getLogger("peewee_migrate").warn = Mock()

    # Make sure new rollbacks work.  The existing ones are what they are.
    for m in applied_migrations:
        if m == "029_message_read":
            break
        router.rollback(m)

    dbp.close()
Пример #2
0
def get_router():
    database.connect()
    logger = logging.getLogger('migration')
    logger.setLevel(logging.DEBUG)

    return Router(database,
                  migrate_dir='migrations',
                  ignore=['basemodel'],
                  logger=logger)
Пример #3
0
def get_router():
    database.connect()
    logger = logging.getLogger("migration")
    logger.setLevel(logging.DEBUG)

    return Router(database,
                  migrate_dir="migrations",
                  ignore=["basemodel"],
                  logger=logger)
Пример #4
0
def get_router(migrate_dir):
    database.connect()
    logger = logging.getLogger("migration")
    logger.setLevel(logging.DEBUG)
    migrate_table = (
        "migratehistory" if migrate_dir == "migrations" else migrate_dir + "_history"
    )

    return Router(
        database,
        migrate_table=migrate_table,
        migrate_dir=migrate_dir,
        ignore=["basemodel"],
        logger=logger,
    )
Пример #5
0
#!/usr/bin/env python3
import __fix
from peewee_migrate import Router
import os
import argparse
from app import create_app
from app.models import dbp as database

app = create_app()
database.connect()

router = Router(database, migrate_dir='../migrations' if os.getcwd().endswith('scripts') else 'migrations',
                ignore=['basemodel'])

parser = argparse.ArgumentParser(description='Apply or manage database migrations.')
parser.add_argument('-c', '--create', metavar='NAME', help='Creates a new migration')
parser.add_argument('-a', '--auto', metavar='NAME', help='Creates a new migration (automatic)')
parser.add_argument('-r', '--rollback', metavar='NAME', help='Rolls back a migration')
parser.add_argument('-l', '--list', action='store_true', help='List migration table')

args = parser.parse_args()

if args.create:
    router.create(args.create)
elif args.auto:
    router.create(args.auto, 'app')
elif args.rollback:
    router.rollback(args.rollback)
elif args.list:
    print("\n".join(m.name for m in router.model.select()))
else: