Beispiel #1
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))
Beispiel #2
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')
Beispiel #3
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,
                        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))
Beispiel #4
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))