def test_get_temp_schemas_works(test_db_env, conn): with patch("time.time", return_value=1234.1446786): schema = load_dataset.create_temp_schema_name("boop") with load_dataset.create_and_enter_temporary_schema(conn, schema): assert load_dataset.get_temp_schemas(conn, "boop") == ["temp_boop_1234"] assert len(load_dataset.get_temp_schemas(conn, "boop")) == 0
def test_get_temp_schemas_works(test_db_env, conn): with patch('time.time', return_value=1234.1446786): schema = load_dataset.create_temp_schema_name('boop') with load_dataset.create_and_enter_temporary_schema(conn, schema): assert load_dataset.get_temp_schemas(conn, 'boop') == ['temp_boop_1234'] assert len(load_dataset.get_temp_schemas(conn, 'boop')) == 0
def build(db_url: str): slack.sendmsg('Rebuilding Who Owns What tables...') cosmetic_dataset_name = 'wow' tables = [ TableInfo(name=name, dataset=cosmetic_dataset_name) for name in parse_created_tables_in_dir(WOW_SQL_DIR, WOW_SCRIPTS) ] with psycopg2.connect(db_url) as conn: install_db_extensions(conn) temp_schema = create_temp_schema_name(cosmetic_dataset_name) with create_and_enter_temporary_schema(conn, temp_schema): run_wow_sql(conn) ensure_schema_exists(conn, WOW_SCHEMA) with save_and_reapply_permissions(conn, tables, WOW_SCHEMA): drop_tables_if_they_exist(conn, tables, WOW_SCHEMA) change_table_schemas(conn, tables, temp_schema, WOW_SCHEMA) # The WoW tables are now ready, but the functions defined by WoW were # in the temporary schema that just got destroyed. Let's re-run only # the function-creating SQL in the WoW schema now. # # Note this means that any client which uses the functions will need # to set their search_path to "{WOW_SCHEMA}, public" or else the function # may not be found or might even crash! print( f"Re-running CREATE FUNCTION statements in the {WOW_SCHEMA} schema..." ) sql = get_all_create_function_sql(WOW_SQL_DIR, WOW_SCRIPTS) run_sql_if_nonempty( conn, sql, initial_sql=f'SET search_path TO {WOW_SCHEMA}, public') slack.sendmsg('Finished rebuilding Who Owns What tables.')
def test_temp_schema_naming_works(): with patch("time.time", return_value=1545146760.1446786): name = load_dataset.create_temp_schema_name("boop") assert name == "temp_boop_1545146760" ts = load_dataset.get_friendly_temp_schema_creation_time(name) assert ts == "2018-12-18 15:26:00 UTC"