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 repo(request, db_session): # clean old config settings r.Config.set_current(r.Config({}, {}, None)) disk_store_gen = None disk_store_gen2 = None repo2 = None prevdir = os.getcwd() if request.param == 'memoryrepo': repo = r.MemoryRepo(read=True, write=True, delete=True) elif request.param == 'dbrepo-diskstore': disk_store_gen = disk_store() repo = r.DbRepo(db_session, next(disk_store_gen), read=True, write=True, delete=True) elif request.param == 'chained-memmem': repo = r.ChainedRepo([ r.MemoryRepo(read=True, write=True, delete=True), r.MemoryRepo(read=True, write=True, delete=True), ]) elif request.param == 'chained-repo': disk_store_gen = disk_store() disk_store_gen2 = disk_store() repo1 = r.DbRepo(db_session, next(disk_store_gen), read=True, write=True, delete=True) os.chdir(prevdir) repo2 = r.DbRepo( 'postgresql://localhost/test_provenance', next(disk_store_gen2), read=True, write=True, delete=True, schema='second_repo', ) repo = r.ChainedRepo([repo1, repo2]) else: repo = r.DbRepo(db_session, memory_store(), read=True, write=True, delete=True) p.set_default_repo(repo) yield repo p.set_default_repo(None) if repo2 is not None: repo2._db_engine.execute('drop schema second_repo cascade;') if disk_store_gen: next(disk_store_gen, 'ignore') if disk_store_gen2: next(disk_store_gen2, 'ignore')
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)
def memory_repo(): repo = r.MemoryRepo(read=True, write=True, delete=True) p.set_default_repo(repo) yield repo p.set_default_repo(None)