Skip to content

Commit 9b48da1

Browse files
oavdeevsavingoyal
authored andcommitted
make db schema name configurable
1 parent e4d7b54 commit 9b48da1

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

run_goose.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@
88
import psycopg2.errorcodes
99

1010

11+
DB_SCHEMA_NAME = os.environ.get("DB_SCHEMA_NAME", "public")
12+
13+
1114
def check_if_goose_table_exists(db_connection_string: str):
1215
conn = psycopg2.connect(db_connection_string)
1316
cur = conn.cursor()
1417
try:
1518
cur.execute("SELECT schemaname,tablename FROM pg_tables")
16-
tables = [name for schema, name in cur.fetchall() if schema == "public"]
19+
tables = [name for schema, name in cur.fetchall() if schema == DB_SCHEMA_NAME]
1720
if "goose_db_version" not in tables:
1821
print(
19-
f"Goose migration table not found among tables in schema public. Found: {', '.join(tables)}",
22+
f"Goose migration table not found among tables in schema {DB_SCHEMA_NAME}. Found: {', '.join(tables)}",
2023
file=sys.stderr,
2124
)
2225
return False
2326
else:
24-
print(f"Goose migration table found in schema public", file=sys.stderr)
27+
print(f"Goose migration table found in schema {DB_SCHEMA_NAME}", file=sys.stderr)
2528
return True
2629
finally:
2730
conn.close()

services/data/postgres_async_db.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
TASK_TABLE_NAME = os.environ.get("DB_TABLE_NAME_TASKS", "tasks_v3")
3535
METADATA_TABLE_NAME = os.environ.get("DB_TABLE_NAME_METADATA", "metadata_v3")
3636
ARTIFACT_TABLE_NAME = os.environ.get("DB_TABLE_NAME_ARTIFACT", "artifact_v3")
37+
DB_SCHEMA_NAME = os.environ.get("DB_SCHEMA_NAME", "public")
3738

3839
operator_match = re.compile('([^:]*):([=><]+)$')
3940

@@ -397,7 +398,7 @@ async def create_trigger_if_missing(db: _AsyncPostgresDB, table_name, trigger_na
397398
cur.close()
398399

399400
@staticmethod
400-
async def setup_trigger_notify(db: _AsyncPostgresDB, table_name, keys: List[str] = None, schema="public"):
401+
async def setup_trigger_notify(db: _AsyncPostgresDB, table_name, keys: List[str] = None, schema=DB_SCHEMA_NAME):
401402
if not keys:
402403
pass
403404

0 commit comments

Comments
 (0)