Spaces:
Runtime error
Runtime error
Fix collaboration RLS for dedicated schema
#9
by basyx - opened
app/projects/migrations/0010_collaboration_foundation.sql
CHANGED
|
@@ -94,20 +94,35 @@ create index ix_approval_requests_workflow_id on approval_requests(workflow_id);
|
|
| 94 |
create index ix_review_comments_request_id on review_comments(request_id);
|
| 95 |
create index ix_collaboration_activity_workspace_id on collaboration_activity(workspace_id);
|
| 96 |
|
| 97 |
-
-- RLS
|
| 98 |
do $$
|
| 99 |
declare
|
| 100 |
table_name text;
|
|
|
|
| 101 |
begin
|
| 102 |
-
for table_name in
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
loop
|
| 107 |
-
execute format('alter table %I enable row level security', table_name);
|
| 108 |
-
execute format('alter table %I force row level security', table_name);
|
| 109 |
-
execute format('drop policy if exists collaboration_workspace_isolation on %I', table_name);
|
| 110 |
-
execute format(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
end loop;
|
| 112 |
end $$;
|
| 113 |
|
|
|
|
| 94 |
create index ix_review_comments_request_id on review_comments(request_id);
|
| 95 |
create index ix_collaboration_activity_workspace_id on collaboration_activity(workspace_id);
|
| 96 |
|
| 97 |
+
-- RLS: discover and alter only tables in the active dedicated schema.
|
| 98 |
do $$
|
| 99 |
declare
|
| 100 |
table_name text;
|
| 101 |
+
schema_name text := current_schema();
|
| 102 |
begin
|
| 103 |
+
for table_name in
|
| 104 |
+
select t.table_name
|
| 105 |
+
from information_schema.tables t
|
| 106 |
+
where t.table_schema = schema_name
|
| 107 |
+
and t.table_name in (
|
| 108 |
+
'teams',
|
| 109 |
+
'team_members',
|
| 110 |
+
'invitations',
|
| 111 |
+
'project_collaborators',
|
| 112 |
+
'approval_workflows',
|
| 113 |
+
'approval_requests',
|
| 114 |
+
'review_comments',
|
| 115 |
+
'collaboration_activity'
|
| 116 |
+
)
|
| 117 |
loop
|
| 118 |
+
execute format('alter table %I.%I enable row level security', schema_name, table_name);
|
| 119 |
+
execute format('alter table %I.%I force row level security', schema_name, table_name);
|
| 120 |
+
execute format('drop policy if exists collaboration_workspace_isolation on %I.%I', schema_name, table_name);
|
| 121 |
+
execute format(
|
| 122 |
+
'create policy collaboration_workspace_isolation on %I.%I using (workspace_id = current_setting(''app.workspace_id'', true)) with check (workspace_id = current_setting(''app.workspace_id'', true))',
|
| 123 |
+
schema_name,
|
| 124 |
+
table_name
|
| 125 |
+
);
|
| 126 |
end loop;
|
| 127 |
end $$;
|
| 128 |
|