def thd(engine): # if the migrate_version table exists, we can just let migrate # take care of this process. if table_exists(engine, 'migrate_version'): r = engine.execute("select version from migrate_version limit 1") old_version = r.scalar() if old_version < 40: raise EightUpgradeError() upgrade(engine) # if the version table exists, then we can version_control things # at that version, drop the version table, and let migrate take # care of the rest. elif table_exists(engine, 'version'): raise EightUpgradeError() # otherwise, this db is new, so we dont bother using the migration engine # and just create the tables, and put the version directly to # latest else: # do some tests before getting started test_unicode(engine) log.msg("Initializing empty database") Model.metadata.create_all(engine) repo = migrate.versioning.repository.Repository(self.repo_path) version_control(engine, repo.latest)
def thd(engine): # if the migrate_version table exists, we can just let migrate # take care of this process. if table_exists(engine, 'migrate_version'): r = engine.execute( "select version from migrate_version limit 1") old_version = r.scalar() if old_version < 40: raise EightUpgradeError() upgrade(engine) # if the version table exists, then we can version_control things # at that version, drop the version table, and let migrate take # care of the rest. elif table_exists(engine, 'version'): raise EightUpgradeError() # otherwise, this db is new, so we don't bother using the migration engine # and just create the tables, and put the version directly to # latest else: # do some tests before getting started test_unicode(engine) log.msg("Initializing empty database") Model.metadata.create_all(engine) repo = migrate.versioning.repository.Repository(self.repo_path) version_control(engine, repo.latest)
def upgrade(migrate_engine): metadata.bind = migrate_engine # do some tests before getting started test_unicode(migrate_engine) # create the initial schema metadata.create_all() # and import some changes import_changes(migrate_engine)
def thd(conn): alembic_scripts = self.alembic_get_scripts() current_script_rev_head = alembic_scripts.get_current_head() if self.table_exists(conn, 'version'): raise UpgradeFromBefore0p9Error() if self.table_exists(conn, 'migrate_version'): version = self.migrate_get_version(conn) if version < 40: raise UpgradeFromBefore0p9Error() last_sqlalchemy_migrate_version = 58 if version != last_sqlalchemy_migrate_version: raise UpgradeFromBefore3p0Error() self.alembic_stamp(conn, alembic_scripts, alembic_scripts.get_base()) conn.execute('drop table migrate_version') if not self.table_exists(conn, 'alembic_version'): log.msg("Initializing empty database") # Do some tests first test_unicode(conn) Model.metadata.create_all(conn) self.alembic_stamp(conn, alembic_scripts, current_script_rev_head) return context = alembic.runtime.migration.MigrationContext.configure( conn) current_rev = context.get_current_revision() if current_rev == current_script_rev_head: log.msg( 'Upgrading database: the current database schema is already the newest' ) return log.msg('Upgrading database') with sautils.withoutSqliteForeignKeys(conn): with context.begin_transaction(): context.run_migrations() log.msg('Upgrading database: done')
def thd(engine): # if the migrate_version table exists, we can just let migrate # take care of this process. if table_exists(engine, 'migrate_version'): upgrade(engine) # if the version table exists, then we can version_control things # at that version, drop the version table, and let migrate take # care of the rest. elif table_exists(engine, 'version'): # get the existing version r = engine.execute("select version from version limit 1") old_version = r.scalar() # set up migrate at the same version version_control(engine, old_version) # drop the no-longer-required version table, using a dummy # metadata entry table = sautils.Table('version', self.metadata, sa.Column('x', sa.Integer)) table.drop(bind=engine) # clear the dummy metadata entry self.metadata.remove(table) # and, finally, upgrade using migrate upgrade(engine) # if we detect a pre-db installation, we run the migration engine # to convert pickles elif should_import_changes(engine): version_control(engine) upgrade(engine) # otherwise, this db is new, so we dont bother using the migration engine # and just create the tables, and put the version directly to # latest else: # do some tests before getting started test_unicode(engine) log.msg("Initializing empty database") Model.metadata.create_all(engine) repo = migrate.versioning.repository.Repository(self.repo_path) version_control(engine, repo.latest)
def thd(engine): # if the migrate_version table exists, we can just let migrate # take care of this process. if table_exists(engine, 'migrate_version'): r = engine.execute( "select version from migrate_version limit 1") old_version = r.scalar() if old_version < 40: raise EightUpgradeError() try: upgrade(engine) except sa.exc.NoSuchTableError as e: # pragma: no cover if 'migration_tmp' in str(e): log.err( 'A serious error has been encountered during the upgrade. The ' 'previous upgrade has been likely interrupted. The database has ' 'been damaged and automatic recovery is impossible.' ) log.err( 'If you believe this is an error, please submit a bug to the ' 'Buildbot project.') raise # if the version table exists, then we can version_control things # at that version, drop the version table, and let migrate take # care of the rest. elif table_exists(engine, 'version'): raise EightUpgradeError() # otherwise, this db is new, so we don't bother using the migration engine # and just create the tables, and put the version directly to # latest else: # do some tests before getting started test_unicode(engine) log.msg("Initializing empty database") Model.metadata.create_all(engine) repo = migrate.versioning.repository.Repository(self.repo_path) version_control(engine, repo.latest)