def xtest_db_is_automatically_migrated(disk_store): db_conn_str = 'postgresql://localhost/test_provenance_automigrate' if sql_utils.database_exists(db_conn_str): sql_utils.drop_database(db_conn_str) sql_utils.create_database(db_conn_str) repo = r.PostgresRepo(db_conn_str, disk_store, read=True, write=True, delete=True, create_db=False, upgrade_db=True) p.set_default_repo(repo) @p.provenance() def calculate(a, b): return a + b # make sure it all works assert calculate(1, 2) == 3 p.set_default_repo(None) sql_utils.drop_database(db_conn_str)
def test_db_is_automatically_created_and_migrated_with_the_right_schema( disk_store): db_conn_str = 'postgresql://localhost/test_provenance_autocreate_schema' if sql_utils.database_exists(db_conn_str): sql_utils.drop_database(db_conn_str) repo = r.PostgresRepo( db_conn_str, disk_store, read=True, write=True, delete=True, create_db=True, schema='foobar', ) p.set_default_repo(repo) @p.provenance() def calculate(a, b): return a + b assert calculate(1, 2) == 3 with repo.session() as s: res = pd.read_sql('select * from foobar.artifacts', s.connection()) repo2 = r.PostgresRepo( db_conn_str, disk_store, read=True, write=True, delete=True, create_db=True, schema='baz', ) p.set_default_repo(repo2) assert calculate(5, 5) == 10 with repo2.session() as s: res = pd.read_sql('select * from baz.artifacts', s.connection()) assert res.iloc[0]['inputs_json'] == {'b': 5, 'a': 5, '__varargs': []} p.set_default_repo(None) sql_utils.drop_database(db_conn_str)