コード例 #1
0
def test_sqlalchemy_store_detects_schema_mismatch(tmpdir, db_url):  # pylint: disable=unused-argument
    def _assert_invalid_schema(engine):
        with pytest.raises(MlflowException) as ex:
            SqlAlchemyStore._verify_schema(engine)
            assert ex.message.contains("Detected out-of-date database schema.")

    # Initialize an empty database & verify that we detect a schema mismatch
    engine = sqlalchemy.create_engine(db_url)
    _assert_invalid_schema(engine)
    # Create legacy tables, verify schema is still out of date
    InitialBase.metadata.create_all(engine)
    _assert_invalid_schema(engine)
    # Run each migration. Until the last one, schema should be out of date
    config = _get_alembic_config(db_url)
    script = ScriptDirectory.from_config(config)
    revisions = list(script.walk_revisions())
    revisions.reverse()
    for rev in revisions[:-1]:
        command.upgrade(config, rev.revision)
        _assert_invalid_schema(engine)
    # Run migrations, schema verification should now pass
    invoke_cli_runner(mlflow.db.commands, ['upgrade', db_url])
    SqlAlchemyStore._verify_schema(engine)
コード例 #2
0
 def _assert_invalid_schema(engine):
     with pytest.raises(MlflowException) as ex:
         SqlAlchemyStore._verify_schema(engine)
         assert ex.message.contains("Detected out-of-date database schema.")