示例#1
0
    def cmd_rollback(self, name):
        """Rollback migrations."""
        from peewee_migrate.router import Router, LOGGER

        LOGGER.setLevel('INFO')
        LOGGER.propagate = 0

        router = Router(self.database, self.app.config['PEEWEE_MIGRATIONS'])
        router.rollback(name)
示例#2
0
    def cmd_migrate(self, name=None, fake=False):
        """Run migrations."""
        from peewee_migrate.router import Router, LOGGER

        LOGGER.setLevel('INFO')
        LOGGER.propagate = 0

        router = Router(self.database, self.app.config['PEEWEE_MIGRATIONS'])
        migrations = router.run(name, fake=fake)
        if migrations:
            LOGGER.warn('Migrations are completed: %s' % ', '.join(migrations))
示例#3
0
    def cmd_merge(self):
        """Merge migrations."""
        from peewee_migrate.router import Router, LOGGER

        LOGGER.setLevel('DEBUG')
        LOGGER.propagate = 0

        router = Router(self.database,
                        migrate_dir=self.app.config['PEEWEE_MIGRATE_DIR'],
                        migrate_table=self.app.config['PEEWEE_MIGRATE_TABLE'])

        router.merge()
示例#4
0
文件: __init__.py 项目: klen/flask-pw
    def cmd_rollback(self, name):
        """Rollback migrations."""
        from peewee_migrate.router import Router, LOGGER

        LOGGER.setLevel('INFO')
        LOGGER.propagate = 0

        router = Router(self.database,
                        migrate_dir=self.app.config['PEEWEE_MIGRATE_DIR'],
                        migrate_table=self.app.config['PEEWEE_MIGRATE_TABLE'])

        router.rollback(name)
示例#5
0
    def cmd_create(self, name, auto=False):
        """Create a new migration."""

        LOGGER.setLevel('INFO')
        LOGGER.propagate = 0

        router = Router(self.database, self.app.config['PEEWEE_MIGRATIONS'])

        if auto:
            auto = self.models

        router.create(name, auto=auto)
示例#6
0
    def cmd_rollback(self, name):
        """
        Rollback migrations.
        """
        LOGGER.setLevel('INFO')
        LOGGER.propagate = 0

        router = Router(self.database,
                        migrate_dir=self.app.config['PEEWEE_MIGRATE_DIR'],
                        migrate_table=self.app.config['PEEWEE_MIGRATE_TABLE'])

        router.rollback(name)
示例#7
0
文件: __init__.py 项目: klen/flask-pw
    def cmd_migrate(self, name=None, fake=False):
        """Run migrations."""
        from peewee_migrate.router import Router, LOGGER

        LOGGER.setLevel('INFO')
        LOGGER.propagate = 0

        router = Router(self.database,
                        migrate_dir=self.app.config['PEEWEE_MIGRATE_DIR'],
                        migrate_table=self.app.config['PEEWEE_MIGRATE_TABLE'])

        migrations = router.run(name, fake=fake)
        if migrations:
            LOGGER.warn('Migrations are completed: %s' % ', '.join(migrations))
示例#8
0
文件: __init__.py 项目: klen/flask-pw
    def cmd_create(self, name, auto=False):
        """Create a new migration."""

        LOGGER.setLevel('INFO')
        LOGGER.propagate = 0

        router = Router(self.database,
                        migrate_dir=self.app.config['PEEWEE_MIGRATE_DIR'],
                        migrate_table=self.app.config['PEEWEE_MIGRATE_TABLE'])

        if auto:
            auto = self.models

        router.create(name, auto=auto)
示例#9
0
    def cmd_migrate(self, name=None, fake=False):
        """
        Run migrations.
        """
        LOGGER.setLevel('INFO')
        LOGGER.propagate = 0

        router = Router(self.database,
                        migrate_dir=self.app.config['PEEWEE_MIGRATE_DIR'],
                        migrate_table=self.app.config['PEEWEE_MIGRATE_TABLE'])

        migrations = router.run(name, fake=fake)
        if migrations:
            LOGGER.warn('Migrations are completed: %s' % ', '.join(migrations))
示例#10
0
def get_router(directory, database, verbose=0):
    from peewee_migrate import LOGGER
    from peewee_migrate.compat import exec_in
    from peewee_migrate.router import Router

    logging_level = VERBOSE[verbose]
    config = {}
    try:
        with open(os.path.join(directory, 'conf.py')) as cfg:
            exec_in(cfg.read(), config, config)
            database = config.get('DATABASE', database)
            logging_level = config.get('LOGGING_LEVEL', logging_level).upper()
    except IOError:
        pass

    if isinstance(database, string_types):
        database = connect(database)

    LOGGER.setLevel(logging_level)

    try:
        return Router(database, migrate_dir=directory)
    except RuntimeError as exc:
        LOGGER.error(exc)
        return sys.exit(1)
示例#11
0
def get_router(directory, database, verbose=0):
    from peewee_migrate import LOGGER
    from peewee_migrate.compat import exec_in
    from peewee_migrate.router import Router

    logging_level = VERBOSE[verbose]
    config = {}
    migrate_table = 'migratehistory'
    ignore = schema = None
    try:
        with open(os.path.join(directory, 'conf.py')) as cfg:
            exec_in(cfg.read(), config, config)
            database = config.get('DATABASE', database)
            ignore = config.get('IGNORE', ignore)
            schema = config.get('SCHEMA', schema)
            migrate_table = config.get('MIGRATE_TABLE', migrate_table)
            logging_level = config.get('LOGGING_LEVEL', logging_level).upper()
    except IOError:
        pass

    if isinstance(database, string_types):
        database = connect(database)

    LOGGER.setLevel(logging_level)

    try:
        return Router(database, migrate_table=migrate_table, migrate_dir=directory,
                      ignore=ignore, schema=schema)
    except RuntimeError as exc:
        LOGGER.error(exc)
        return sys.exit(1)
示例#12
0
    def cmd_list(self):
        """List migrations."""
        from peewee_migrate.router import Router, LOGGER

        LOGGER.setLevel('DEBUG')
        LOGGER.propagate = 0

        router = Router(self.database, self.app.config['PEEWEE_MIGRATIONS'])
        LOGGER.info('Migrations are done:')
        LOGGER.info('\n'.join(router.done))
        LOGGER.info('')
        LOGGER.info('Migrations are undone:')
        LOGGER.info('\n'.join(router.diff))
示例#13
0
def run_db_migration(database):
    db_storage_dir = os.path.dirname(pavlov_central.storage.__file__)
    print(f'db_storage_dir={db_storage_dir}')
    db_migrations_dir = os.path.join(db_storage_dir, 'migrations')
    print(f'db_migrations_dir={db_migrations_dir}')

    router = Router(database,
                    migrate_dir=db_migrations_dir,
                    migrate_table='migration',
                    logger=logging.getLogger(),
                    ignore=[
                        'basemodel', 'basedatamodel', 'frs5model',
                        'virtualmodel', 'baseftsmodel', 'ftsmodel', 'lsmtable'
                    ])
    print('Run migrations..')

    router.run()

    # check migrations
    src_models = load_models('pavlov_central.storage.models')
    print(f'src_models={src_models}')
    if router.ignore:
        src_models = [
            m for m in src_models if m.get_table_name() not in router.ignore
        ]

    db_models = router.migrator.orm.values()
    print(f'db_models={db_models}')

    diff_found = diff_many(src_models,
                           db_models,
                           router.migrator,
                           reverse=False)

    if len(diff_found) > 0:
        logging.warning('migrations diff_found={}'.format(diff_found))
        print('migrations diff_found={}'.format(diff_found))
        raise RuntimeError('Check db migrations is failed')
示例#14
0
    def cmd_list(self):
        """
        List migrations.
        """
        LOGGER.setLevel('DEBUG')
        LOGGER.propagate = 0

        router = Router(self.database,
                        migrate_dir=self.app.config['PEEWEE_MIGRATE_DIR'],
                        migrate_table=self.app.config['PEEWEE_MIGRATE_TABLE'])

        LOGGER.info('Migrations are done:')
        LOGGER.info('\n'.join(router.done))
        LOGGER.info('')
        LOGGER.info('Migrations are undone:')
        LOGGER.info('\n'.join(router.diff))