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(schemas): explicitly set search path #6101

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions packages/schemas/alterations/next-1719221205-fix-functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* In Logto Cloud, we have multiple schemas and the default search behavior will be problematic.
* This alteration script will fix it by setting the search path to public for the functions.
*/

import { sql } from '@silverhand/slonik';

import type { AlterationScript } from '../lib/types/alteration.js';

const alteration: AlterationScript = {
up: async (pool) => {
await pool.query(sql`
alter function check_application_type set search_path = public;
alter function check_organization_role_type set search_path = public;
`);
},
down: async (pool) => {
await pool.query(sql`
alter function check_application_type reset search_path;
alter function check_organization_role_type reset search_path;
`);
},
};

export default alteration;
2 changes: 1 addition & 1 deletion packages/schemas/tables/applications.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ create unique index applications__protected_app_metadata_custom_domain
create function check_application_type(application_id varchar(21), target_type application_type) returns boolean as
$$ begin
return (select type from applications where id = application_id) = target_type;
end; $$ language plpgsql;
end; $$ language plpgsql set search_path = public;
2 changes: 1 addition & 1 deletion packages/schemas/tables/organization_roles.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ create index organization_roles__id
create function check_organization_role_type(role_id varchar(21), target_type role_type) returns boolean as
$$ begin
return (select type from organization_roles where id = role_id) = target_type;
end; $$ language plpgsql;
end; $$ language plpgsql set search_path = public;
Loading