Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: promote query #29

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/ports/squids/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const getPromoteQuery = (serviceName: string, schemaName: string, project
old_schema_name TEXT;
new_schema_name TEXT;
writer_user TEXT;
old_user TEXT;
BEGIN
-- Fetch the new schema name and database user from the indexers table
SELECT schema, db_user INTO new_schema_name, writer_user
Expand Down Expand Up @@ -58,6 +59,14 @@ export const getPromoteQuery = (serviceName: string, schemaName: string, project
.append(
SQL`');

SELECT db_user INTO old_user
FROM public.indexers
WHERE schema = old_schema_name
ORDER BY created_at DESC LIMIT 1;

-- Update the search path for old user to use the old_schema
EXECUTE format('ALTER USER %I SET search_path TO %I', old_user, old_schema_name);

-- Update the schema in the squids table
UPDATE squids
SET schema = new_schema_name WHERE name = `.append(safeProjectName).append(SQL`;
Expand Down
Loading