Skip to content

Commit 6ad6c0b

Browse files
authored
Merge pull request #29 from decentraland/fix/promote
fix: promote query
2 parents f68938e + a3690a8 commit 6ad6c0b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/ports/squids/queries.ts

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const getPromoteQuery = (serviceName: string, schemaName: string, project
2222
old_schema_name TEXT;
2323
new_schema_name TEXT;
2424
writer_user TEXT;
25+
old_user TEXT;
2526
BEGIN
2627
-- Fetch the new schema name and database user from the indexers table
2728
SELECT schema, db_user INTO new_schema_name, writer_user
@@ -58,6 +59,14 @@ export const getPromoteQuery = (serviceName: string, schemaName: string, project
5859
.append(
5960
SQL`');
6061
62+
SELECT db_user INTO old_user
63+
FROM public.indexers
64+
WHERE schema = old_schema_name
65+
ORDER BY created_at DESC LIMIT 1;
66+
67+
-- Update the search path for old user to use the old_schema
68+
EXECUTE format('ALTER USER %I SET search_path TO %I', old_user, old_schema_name);
69+
6170
-- Update the schema in the squids table
6271
UPDATE squids
6372
SET schema = new_schema_name WHERE name = `.append(safeProjectName).append(SQL`;

0 commit comments

Comments
 (0)