def test_failed_and_repair_upgrade_from_v2_0_0(clean_app): """Test upgrade from an unknown B2SHARE version.""" with clean_app.app_context(): ext = clean_app.extensions['invenio-db'] if db.engine.name == 'sqlite': raise pytest.skip('upgrades are not supported on sqlite.') # bring db to v2.0.1 state db_create_v2_0_1() Migration.__table__.create(db.engine) db.session.commit() result = upgrade_run(clean_app) assert result.exception.__class__ == sa.exc.ProgrammingError Migration.__table__.drop(db.engine) result = upgrade_run(clean_app) assert result.exit_code == 0 # Check that the resulting state is in sync with sqlalchemy's MetaData assert not ext.alembic.compare_metadata() # check that the migration information have been saved migrations = Migration.query.all() assert len(migrations) == 1 mig = migrations[0] assert mig.version == current_migration_version assert mig.success repeat_upgrade(clean_app, ext.alembic) validate_metadata(clean_app, ext.alembic)
def test_init_fail_and_retry(clean_app): """Test replay first database init after a failure.""" with clean_app.app_context(): ext = clean_app.extensions['invenio-db'] if db.engine.name == 'sqlite': raise pytest.skip('upgrades are not supported on sqlite.') # create a conflicting table. db.engine.execute('CREATE table b2share_community (wrong int);') result = upgrade_run(clean_app) assert result.exit_code == -1 # remove the problematic table db.engine.execute('DROP table b2share_community;') result = upgrade_run(clean_app) assert result.exit_code == 0 # check that the migration information have been saved migrations = Migration.query.all() assert len(migrations) == 1 mig = migrations[0] assert mig.version == current_migration_version assert mig.success repeat_upgrade(clean_app, ext.alembic) validate_metadata(clean_app, ext.alembic)
def test_upgrade_from_v2_0_0(clean_app): """Test upgrading B2Share from version 2.0.0.""" with clean_app.app_context(): ext = clean_app.extensions['invenio-db'] if db.engine.name == 'sqlite': raise pytest.skip('upgrades are not supported on sqlite.') # bring db to v2.0.1 state db_create_v2_0_1() # Upgrade B2SHARE with `b2share upgrade run` result = upgrade_run(clean_app) assert result.exit_code == 0 repeat_upgrade(clean_app, ext.alembic) # check that the migration information have been saved migrations = Migration.query.all() assert len(migrations) == 1 mig = migrations[0] assert mig.version == current_migration_version for step in mig.data['steps']: assert step['status'] == 'success' assert mig.data['error'] is None validate_metadata(clean_app, ext.alembic)
def test_init_upgrade(clean_app): """Test database upgrade from a clean state.""" with clean_app.app_context(): ext = clean_app.extensions['invenio-db'] if db.engine.name == 'sqlite': raise pytest.skip('upgrades are not supported on sqlite.') result = upgrade_run(clean_app) assert result.exit_code == 0 # check that the migration information have been saved migrations = Migration.query.all() assert len(migrations) == 1 mig = migrations[0] assert mig.version == current_migration_version assert mig.success repeat_upgrade(clean_app, ext.alembic) validate_metadata(clean_app, ext.alembic)