def test_running_migrations_generates_expected_schema(tmpdir, expected_schema_file, db_url): """Test that migrating an existing database generates the desired schema.""" engine = sqlalchemy.create_engine(db_url) InitialBase.metadata.create_all(engine) invoke_cli_runner(mlflow.db.commands, ['upgrade', db_url]) generated_schema_file = tmpdir.join("generated-schema.sql").strpath dump_db_schema(db_url, generated_schema_file) _assert_schema_files_equal(generated_schema_file, expected_schema_file)
def test_sqlalchemystore_idempotently_generates_up_to_date_schema( tmpdir, db_url, expected_schema_file): generated_schema_file = tmpdir.join("generated-schema.sql").strpath # Repeatedly initialize a SQLAlchemyStore against the same DB URL. Initialization should # succeed and the schema should be the same. for _ in range(3): SqlAlchemyStore(db_url, tmpdir.join("ARTIFACTS").strpath) dump_db_schema(db_url, dst_file=generated_schema_file) _assert_schema_files_equal(generated_schema_file, expected_schema_file)