thinkwork-cli 0.12.15 → 0.12.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/dist/{api-client-4VT3FWOH.js → api-client-JUBCQQDF.js} +1 -1
  2. package/dist/{chunk-H7AB42ES.js → chunk-STY44FQO.js} +13 -0
  3. package/dist/cli.js +1107 -10225
  4. package/dist/commands/enterprise/templates/deploy-repo/docs/runbook.md +3 -8
  5. package/dist/commands/enterprise/templates/deploy-repo/terraform/main.tf +1 -184
  6. package/dist/drizzle/0050_brain_v0_entity_subtype.sql +2 -2
  7. package/dist/drizzle/0051_brain_v0_tenant_entity_pages.sql +6 -6
  8. package/dist/drizzle/0052_brain_v0_external_refs.sql +2 -2
  9. package/dist/drizzle/0053_brain_v0_unresolved_mentions_subtype.sql +2 -2
  10. package/dist/drizzle/0145_knowledge_graph_thread_ingest.sql +14 -14
  11. package/dist/drizzle/0146_knowledge_graph_source_scope.sql +1 -1
  12. package/dist/drizzle/0157_knowledge_graph_observations_source.sql +2 -2
  13. package/dist/drizzle/0158_wiki_tenant_scope.sql +1 -1
  14. package/dist/drizzle/0165_plugin_premium_entitlements.sql +2 -2
  15. package/dist/drizzle/{0166_company_brain_substrate_contract.sql → 0166_brain_substrate_contract.sql} +9 -9
  16. package/dist/drizzle/{0167_company_brain_artifact_manifest_runtime.sql → 0167_brain_artifact_manifest_runtime.sql} +5 -5
  17. package/dist/drizzle/0168_eval_skill_gate.sql +1 -1
  18. package/dist/drizzle/0183_okf_artifact_manifests.sql +1 -1
  19. package/dist/drizzle/0197_rcm_context_columns.sql +28 -0
  20. package/dist/drizzle/0200_eval_results_execution_tier.sql +40 -0
  21. package/dist/drizzle/0201_brain_dream_runs.sql +72 -0
  22. package/dist/drizzle/0202_backfill_thread_participants_from_senders.sql +110 -0
  23. package/dist/drizzle/0203_threads_mode_override.sql +61 -0
  24. package/dist/drizzle/0204_thread_turns_triggering_message_id.sql +48 -0
  25. package/dist/drizzle/0205_routines_git_python.sql +185 -0
  26. package/dist/drizzle/0206_agent_loop_versions_routine_actions.sql +40 -0
  27. package/dist/drizzle/0207_tenant_credentials_github_repo_kind.sql +52 -0
  28. package/dist/drizzle/0208_knowledge_graph_neutral_identifiers.sql +253 -0
  29. package/dist/drizzle/0209_living_artifacts_schema.sql +109 -0
  30. package/dist/drizzle/0210_think137_automations_additive_schema.sql +113 -0
  31. package/dist/drizzle/0211_backfill_agent_loop_versions_target_spec.sql +120 -0
  32. package/dist/drizzle/0212_fold_webhooks_into_automations.sql +312 -0
  33. package/dist/drizzle/0213_agent_loop_versions_judge_evidence_nullable.sql +63 -0
  34. package/dist/drizzle/0214_think137_drop_judge_evidence_roi.sql +99 -0
  35. package/dist/drizzle/0215_agent_loop_versions_goal_worker_policy_nullable.sql +70 -0
  36. package/dist/drizzle/0216_drop_agent_loop_versions_goal_worker_policy.sql +81 -0
  37. package/dist/drizzle/0217_agents_capability_folder_dispatch.sql +12 -0
  38. package/dist/drizzle/0218_document_plates.sql +30 -0
  39. package/dist/drizzle/0219_document_section_waivers.sql +29 -0
  40. package/dist/drizzle/0220_artifacts_created_by_user.sql +21 -0
  41. package/dist/drizzle/0221_artifact_shares.sql +29 -0
  42. package/dist/drizzle/0221_workflow_interpreter_thin_slice.sql +71 -0
  43. package/dist/drizzle/0222_compliance_drainer_select_audit_events.sql +21 -0
  44. package/dist/drizzle/0223_document_conformance_reports.sql +38 -0
  45. package/dist/drizzle/0224_artifact_refresh_state.sql +11 -0
  46. package/dist/drizzle/0225_think216_agent_loop_convergence.sql +21 -0
  47. package/dist/drizzle/0226_drop_n8n_agent_step_runs.sql +6 -0
  48. package/dist/drizzle/0227_analyst_reader_role.sql +1055 -0
  49. package/dist/drizzle/0228_tenant_credentials_rds_iam_kind.sql +62 -0
  50. package/dist/drizzle/0229_analyst_reader_rds_iam_grant.sql +79 -0
  51. package/dist/drizzle/0230_analyst_rls.sql +1613 -0
  52. package/dist/drizzle/0231_cost_events_cache_write_enforcement_exempt.sql +11 -0
  53. package/dist/plugins/catalog/package.json +0 -1
  54. package/dist/plugins/catalog/src/__tests__/build-catalog.test.ts +0 -1
  55. package/dist/plugins/catalog/src/__tests__/catalog.test.ts +16 -8
  56. package/dist/plugins/catalog/src/__tests__/contracts.test.ts +56 -0
  57. package/dist/plugins/catalog/src/__tests__/plugin-package.test.ts +0 -2
  58. package/dist/plugins/catalog/src/__tests__/plugin-registry.test.ts +0 -5
  59. package/dist/plugins/catalog/src/contracts.ts +112 -0
  60. package/dist/plugins/catalog/src/registry/generated-first-party.ts +0 -6
  61. package/dist/plugins/n8n/README.md +4 -36
  62. package/dist/plugins/n8n/src/deployment/managed-app.ts +0 -17
  63. package/dist/plugins/n8n/src/manifest.ts +0 -5
  64. package/dist/plugins/n8n/terraform/n8n/main.tf +0 -26
  65. package/dist/plugins/n8n/terraform/n8n/outputs.tf +0 -5
  66. package/dist/plugins/n8n/terraform/n8n/variables.tf +0 -6
  67. package/dist/plugins/n8n/test/manifest.test.ts +0 -1
  68. package/dist/plugins/twenty/package.json +5 -0
  69. package/dist/plugins/twenty/scripts/lib/__tests__/load-records.test.ts +232 -0
  70. package/dist/plugins/twenty/scripts/lib/__tests__/mappers.test.ts +489 -0
  71. package/dist/plugins/twenty/scripts/lib/__tests__/members-ensure.test.ts +199 -0
  72. package/dist/plugins/twenty/scripts/lib/__tests__/provision-members-db.test.ts +43 -0
  73. package/dist/plugins/twenty/scripts/lib/__tests__/schema-ensure.test.ts +230 -0
  74. package/dist/plugins/twenty/scripts/lib/__tests__/twenty-client.test.ts +207 -0
  75. package/dist/plugins/twenty/scripts/lib/lastmile-reader.ts +282 -0
  76. package/dist/plugins/twenty/scripts/lib/load-attachments.ts +220 -0
  77. package/dist/plugins/twenty/scripts/lib/load-records.ts +680 -0
  78. package/dist/plugins/twenty/scripts/lib/mappers.ts +559 -0
  79. package/dist/plugins/twenty/scripts/lib/members-ensure.ts +381 -0
  80. package/dist/plugins/twenty/scripts/lib/provision-members-db.ts +191 -0
  81. package/dist/plugins/twenty/scripts/lib/schema-ensure.ts +425 -0
  82. package/dist/plugins/twenty/scripts/lib/twenty-client.ts +246 -0
  83. package/dist/plugins/twenty/scripts/migrate-lastmile.ts +610 -0
  84. package/dist/plugins/twenty/scripts/provision-twenty-members.ts +214 -0
  85. package/dist/plugins/twenty/src/manifest.ts +99 -0
  86. package/dist/plugins/twenty/terraform/twenty/README.md +1 -1
  87. package/dist/plugins/twenty/test/manifest.test.ts +12 -2
  88. package/dist/terraform/examples/greenfield/main.tf +90 -380
  89. package/dist/terraform/examples/greenfield/terraform.tfvars.example +0 -1
  90. package/dist/terraform/modules/app/agentcore-pi/README.md +1 -3
  91. package/dist/terraform/modules/app/agentcore-pi/main.tf +36 -32
  92. package/dist/terraform/modules/app/agentcore-pi/variables.tf +23 -15
  93. package/dist/terraform/modules/app/agentcore-runtime/main.tf +3 -3
  94. package/dist/terraform/modules/app/customer-domain/main.tf +16 -2
  95. package/dist/terraform/modules/app/deployment-control-plane/main.tf +5 -0
  96. package/dist/terraform/modules/app/deployment-control-plane/runner.py +85 -207
  97. package/dist/terraform/modules/app/deployment-control-plane/test_runner_bundle.py +56 -2
  98. package/dist/terraform/modules/app/hindsight-memory/main.tf +52 -4
  99. package/dist/terraform/modules/app/lambda-api/eval-fanout.tf +7 -0
  100. package/dist/terraform/modules/app/lambda-api/handlers.tf +493 -89
  101. package/dist/terraform/modules/app/lambda-api/iam-grouped.tf +215 -96
  102. package/dist/terraform/modules/app/lambda-api/main.tf +24 -5
  103. package/dist/terraform/modules/app/lambda-api/outputs.tf +19 -11
  104. package/dist/terraform/modules/app/lambda-api/variables.tf +94 -67
  105. package/dist/terraform/modules/app/ses-email/main.tf +14 -2
  106. package/dist/terraform/modules/app/workflow-interpreter-stepfunctions/main.tf +493 -0
  107. package/dist/terraform/modules/app/workflow-interpreter-stepfunctions/outputs.tf +34 -0
  108. package/dist/terraform/modules/app/workflow-interpreter-stepfunctions/variables.tf +32 -0
  109. package/dist/terraform/modules/data/aurora-postgres/main.tf +55 -0
  110. package/dist/terraform/modules/data/aurora-postgres/outputs.tf +15 -0
  111. package/dist/terraform/modules/data/s3-buckets/main.tf +26 -0
  112. package/dist/terraform/modules/thinkwork/README.md +0 -1
  113. package/dist/terraform/modules/thinkwork/main.tf +167 -446
  114. package/dist/terraform/modules/thinkwork/outputs.tf +2 -142
  115. package/dist/terraform/modules/thinkwork/variables.tf +55 -309
  116. package/dist/terraform/schema.graphql +4 -0
  117. package/dist/workspace-defaults/files/AGENTS.md +45 -31
  118. package/dist/workspace-defaults/files/CONTEXT.md +48 -4
  119. package/dist/workspace-defaults/files/GUARDRAILS.md +18 -0
  120. package/dist/workspace-defaults/files/MEMORY_GUIDE.md +32 -4
  121. package/dist/workspace-defaults/files/SPACE.md +34 -19
  122. package/dist/workspace-defaults/files/TOOLS.md +30 -0
  123. package/dist/workspace-defaults/files/skills/document-composer/SKILL.md +154 -0
  124. package/dist/workspace-defaults/files/skills/document-composer/references/authoring-rules.md +101 -0
  125. package/package.json +2 -1
  126. package/dist/plugins/company-brain/README.md +0 -37
  127. package/dist/plugins/company-brain/package.json +0 -33
  128. package/dist/plugins/company-brain/runtime/cognee/Dockerfile +0 -11
  129. package/dist/plugins/company-brain/smoke/cognee-managed-app-smoke.mjs +0 -458
  130. package/dist/plugins/company-brain/smoke/cognee-memory-cutover-smoke.mjs +0 -539
  131. package/dist/plugins/company-brain/smoke/company-brain-context-engine-smoke.mjs +0 -312
  132. package/dist/plugins/company-brain/smoke/company-brain-operations-smoke.mjs +0 -449
  133. package/dist/plugins/company-brain/smoke/company-brain-plugin-smoke.mjs +0 -655
  134. package/dist/plugins/company-brain/smoke/hindsight-memory-isolation-smoke.mjs +0 -474
  135. package/dist/plugins/company-brain/src/api/cognee-client.ts +0 -896
  136. package/dist/plugins/company-brain/src/api/cognee-cluster-identity.ts +0 -49
  137. package/dist/plugins/company-brain/src/api/cognee-memory-scope.ts +0 -84
  138. package/dist/plugins/company-brain/src/api/context-engine-provider.ts +0 -888
  139. package/dist/plugins/company-brain/src/api/migration.ts +0 -665
  140. package/dist/plugins/company-brain/src/deployment/cognee-managed-app.ts +0 -396
  141. package/dist/plugins/company-brain/src/index.ts +0 -62
  142. package/dist/plugins/company-brain/src/manifest.ts +0 -112
  143. package/dist/plugins/company-brain/terraform/cognee/README.md +0 -263
  144. package/dist/plugins/company-brain/terraform/cognee/main.tf +0 -766
  145. package/dist/plugins/company-brain/terraform/cognee/outputs.tf +0 -144
  146. package/dist/plugins/company-brain/terraform/cognee/variables.tf +0 -402
  147. package/dist/plugins/company-brain/test/api/cognee-client.test.ts +0 -562
  148. package/dist/plugins/company-brain/test/api/cognee-memory-scope.test.ts +0 -74
  149. package/dist/plugins/company-brain/test/api/context-engine-provider.test.ts +0 -447
  150. package/dist/plugins/company-brain/test/api/migration.test.ts +0 -465
  151. package/dist/plugins/company-brain/test/manifest.test.ts +0 -95
  152. package/dist/plugins/company-brain/tsconfig.json +0 -8
@@ -0,0 +1,1613 @@
1
+ -- 0230_analyst_rls.sql
2
+ --
3
+ -- THINK-234: row-level tenant scoping for the ThinkWork Analyst.
4
+ --
5
+ -- 0227 gave `analyst_reader` a per-table SELECT surface but no row filter —
6
+ -- a granted table exposed EVERY tenant's rows. This migration adds the row
7
+ -- filter: it enables row-level security and installs one
8
+ -- `analyst_tenant_isolation` policy per granted table, scoped
9
+ -- `TO analyst_reader` and `FOR SELECT`, that filters rows to the single
10
+ -- verified tenant the query broker pins on the connection.
11
+ --
12
+ -- How the tenant is pinned: after every `DISCARD ALL`, the broker runs
13
+ -- SELECT set_config('thinkwork.analyst_tenant', '<verified-tenant-uuid>', false);
14
+ -- and each policy reads it back via
15
+ -- current_setting('thinkwork.analyst_tenant', true)::uuid
16
+ -- (`missing_ok = true`, so an un-primed connection yields NULL → every
17
+ -- comparison is false → zero rows, fail-closed). GUC + current_setting::uuid
18
+ -- precedent: drizzle/0076_scheduled_jobs_marco_backfill.sql.
19
+ --
20
+ -- Per-table scope (from packages/database-pg/src/analyst/annotations.ts):
21
+ -- - column (default): USING (tenant_id = <verified tenant>)
22
+ -- - self (tenants): USING (id = <verified tenant>)
23
+ -- - join (no tenant_id of their own — inherit via a parent FK):
24
+ -- USING (EXISTS (SELECT 1 FROM <parent> p
25
+ -- WHERE p.<pk> = <table>.<fk>
26
+ -- AND p.tenant_id = <verified tenant>))
27
+ -- - global (capability_catalog, model_catalog): granted, RLS NOT enabled.
28
+ --
29
+ -- Why ENABLE is safe for every other role: enabling RLS default-denies any
30
+ -- non-owner role without a matching policy, but NO other non-owner role holds
31
+ -- SELECT on any public.* table — the compliance_* roles are scoped entirely
32
+ -- to the compliance.* schema (drizzle/0070, 0073, 0222). The application
33
+ -- writer connects as the table OWNER (master/migration user), which bypasses
34
+ -- RLS (no FORCE is applied), so ordinary reads/writes are unaffected.
35
+ --
36
+ -- Generated: the section between the GENERATED ANALYST RLS markers is spliced
37
+ -- from packages/database-pg/src/analyst/semantic-model.ts (`analystRlsSql`) by
38
+ -- scripts/generate-analyst-schema.ts. A vitest staleness test asserts the
39
+ -- committed section matches the current schema, so a table added/removed
40
+ -- without a regen fails CI. Do NOT hand-edit inside the markers.
41
+ --
42
+ -- Plan reference:
43
+ -- THINK-234 (analyst row-level tenant scoping) — the RLS-generation leg.
44
+ --
45
+ -- Apply manually (hand-rolled — NOT in meta/_journal.json). Apply AFTER the
46
+ -- broker PR (which pins thinkwork.analyst_tenant) has deployed:
47
+ -- psql "$DATABASE_URL" -f packages/database-pg/drizzle/0230_analyst_rls.sql
48
+ --
49
+ -- Re-running is idempotent: ENABLE ROW LEVEL SECURITY is a no-op once set,
50
+ -- each policy is DROP POLICY IF EXISTS'd before CREATE, and the REVOKEs below
51
+ -- are inherently idempotent.
52
+ --
53
+ -- Markers (consumed by scripts/db-migrate-manual.sh as the drift gate). This
54
+ -- migration installs one analyst_tenant_isolation policy per granted table
55
+ -- (160+); declaring them all would bloat the header, so we declare a
56
+ -- representative sentinel set spanning every scope kind (self / column /
57
+ -- join). The full policy set is generated and asserted by the vitest
58
+ -- staleness test, not by these markers.
59
+ --
60
+ -- creates-policy: public.tenants.analyst_tenant_isolation
61
+ -- creates-policy: public.threads.analyst_tenant_isolation
62
+ -- creates-policy: public.agent_operation_leases.analyst_tenant_isolation
63
+ -- creates-policy: public.eval_results.analyst_tenant_isolation
64
+ -- creates-policy: public.plugin_components.analyst_tenant_isolation
65
+
66
+ \set ON_ERROR_STOP on
67
+
68
+ BEGIN;
69
+
70
+ SET LOCAL lock_timeout = '5s';
71
+ SET LOCAL statement_timeout = '120s';
72
+
73
+ -- Refuse to apply against an unexpected DB (stale DATABASE_URL guard).
74
+ DO $$
75
+ BEGIN
76
+ IF current_database() != 'thinkwork' THEN
77
+ RAISE EXCEPTION 'wrong database: %, expected thinkwork', current_database();
78
+ END IF;
79
+ END $$;
80
+
81
+ -- ---------------------------------------------------------------------------
82
+ -- (a) Revoke the surface THINK-234 removed from the analyst.
83
+ --
84
+ -- billing_export_imports, stripe_events, webhook_idempotency, and
85
+ -- customer_deployment_session_events were granted by 0227 but are now
86
+ -- denylisted (platform billing/infra ledgers with no tenant dimension — they
87
+ -- carry no tenant_id and so cannot be row-scoped). Re-applying 0227 no longer
88
+ -- grants them, but it also does not revoke an existing grant, so revoke here.
89
+ -- Existence-guarded so a DB missing any of them still applies cleanly.
90
+ -- ---------------------------------------------------------------------------
91
+
92
+ DO $$
93
+ DECLARE
94
+ t text;
95
+ BEGIN
96
+ FOREACH t IN ARRAY ARRAY[
97
+ 'billing_export_imports',
98
+ 'customer_deployment_session_events',
99
+ 'stripe_events',
100
+ 'webhook_idempotency'
101
+ ] LOOP
102
+ IF to_regclass('public.' || t) IS NOT NULL THEN
103
+ EXECUTE format('REVOKE ALL PRIVILEGES ON public.%I FROM analyst_reader', t);
104
+ END IF;
105
+ END LOOP;
106
+ END $$;
107
+
108
+ -- ---------------------------------------------------------------------------
109
+ -- (b) Enable RLS + install per-table tenant-isolation policies (generated).
110
+ --
111
+ -- Regenerate: npx tsx scripts/generate-analyst-schema.ts
112
+ -- Source of truth: packages/database-pg/src/analyst/semantic-model.ts
113
+ -- ---------------------------------------------------------------------------
114
+
115
+ -- BEGIN GENERATED ANALYST RLS
116
+ -- Global reference tables — granted but RLS intentionally NOT enabled
117
+ -- (no tenant dimension): capability_catalog, model_catalog.
118
+ DO $$
119
+ DECLARE
120
+ missing text[] := '{}';
121
+ BEGIN
122
+ IF to_regclass('public.activity_log') IS NOT NULL THEN
123
+ ALTER TABLE public.activity_log ENABLE ROW LEVEL SECURITY;
124
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.activity_log;
125
+ CREATE POLICY analyst_tenant_isolation ON public.activity_log
126
+ FOR SELECT TO analyst_reader
127
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
128
+ ELSE
129
+ missing := missing || 'activity_log'::text;
130
+ END IF;
131
+ IF to_regclass('public.agent_capabilities') IS NOT NULL THEN
132
+ ALTER TABLE public.agent_capabilities ENABLE ROW LEVEL SECURITY;
133
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_capabilities;
134
+ CREATE POLICY analyst_tenant_isolation ON public.agent_capabilities
135
+ FOR SELECT TO analyst_reader
136
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
137
+ ELSE
138
+ missing := missing || 'agent_capabilities'::text;
139
+ END IF;
140
+ IF to_regclass('public.agent_knowledge_bases') IS NOT NULL THEN
141
+ ALTER TABLE public.agent_knowledge_bases ENABLE ROW LEVEL SECURITY;
142
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_knowledge_bases;
143
+ CREATE POLICY analyst_tenant_isolation ON public.agent_knowledge_bases
144
+ FOR SELECT TO analyst_reader
145
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
146
+ ELSE
147
+ missing := missing || 'agent_knowledge_bases'::text;
148
+ END IF;
149
+ IF to_regclass('public.agent_loop_iterations') IS NOT NULL THEN
150
+ ALTER TABLE public.agent_loop_iterations ENABLE ROW LEVEL SECURITY;
151
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_loop_iterations;
152
+ CREATE POLICY analyst_tenant_isolation ON public.agent_loop_iterations
153
+ FOR SELECT TO analyst_reader
154
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
155
+ ELSE
156
+ missing := missing || 'agent_loop_iterations'::text;
157
+ END IF;
158
+ IF to_regclass('public.agent_loop_runs') IS NOT NULL THEN
159
+ ALTER TABLE public.agent_loop_runs ENABLE ROW LEVEL SECURITY;
160
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_loop_runs;
161
+ CREATE POLICY analyst_tenant_isolation ON public.agent_loop_runs
162
+ FOR SELECT TO analyst_reader
163
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
164
+ ELSE
165
+ missing := missing || 'agent_loop_runs'::text;
166
+ END IF;
167
+ IF to_regclass('public.agent_loop_versions') IS NOT NULL THEN
168
+ ALTER TABLE public.agent_loop_versions ENABLE ROW LEVEL SECURITY;
169
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_loop_versions;
170
+ CREATE POLICY analyst_tenant_isolation ON public.agent_loop_versions
171
+ FOR SELECT TO analyst_reader
172
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
173
+ ELSE
174
+ missing := missing || 'agent_loop_versions'::text;
175
+ END IF;
176
+ IF to_regclass('public.agent_loops') IS NOT NULL THEN
177
+ ALTER TABLE public.agent_loops ENABLE ROW LEVEL SECURITY;
178
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_loops;
179
+ CREATE POLICY analyst_tenant_isolation ON public.agent_loops
180
+ FOR SELECT TO analyst_reader
181
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
182
+ ELSE
183
+ missing := missing || 'agent_loops'::text;
184
+ END IF;
185
+ IF to_regclass('public.agent_mcp_servers') IS NOT NULL THEN
186
+ ALTER TABLE public.agent_mcp_servers ENABLE ROW LEVEL SECURITY;
187
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_mcp_servers;
188
+ CREATE POLICY analyst_tenant_isolation ON public.agent_mcp_servers
189
+ FOR SELECT TO analyst_reader
190
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
191
+ ELSE
192
+ missing := missing || 'agent_mcp_servers'::text;
193
+ END IF;
194
+ IF to_regclass('public.agent_operation_leases') IS NOT NULL THEN
195
+ ALTER TABLE public.agent_operation_leases ENABLE ROW LEVEL SECURITY;
196
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_operation_leases;
197
+ CREATE POLICY analyst_tenant_isolation ON public.agent_operation_leases
198
+ FOR SELECT TO analyst_reader
199
+ USING (EXISTS (SELECT 1 FROM public.agents p WHERE p.id = public.agent_operation_leases.agent_id AND p.tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid));
200
+ ELSE
201
+ missing := missing || 'agent_operation_leases'::text;
202
+ END IF;
203
+ IF to_regclass('public.agent_profile_space_assignments') IS NOT NULL THEN
204
+ ALTER TABLE public.agent_profile_space_assignments ENABLE ROW LEVEL SECURITY;
205
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_profile_space_assignments;
206
+ CREATE POLICY analyst_tenant_isolation ON public.agent_profile_space_assignments
207
+ FOR SELECT TO analyst_reader
208
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
209
+ ELSE
210
+ missing := missing || 'agent_profile_space_assignments'::text;
211
+ END IF;
212
+ IF to_regclass('public.agent_profiles') IS NOT NULL THEN
213
+ ALTER TABLE public.agent_profiles ENABLE ROW LEVEL SECURITY;
214
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_profiles;
215
+ CREATE POLICY analyst_tenant_isolation ON public.agent_profiles
216
+ FOR SELECT TO analyst_reader
217
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
218
+ ELSE
219
+ missing := missing || 'agent_profiles'::text;
220
+ END IF;
221
+ IF to_regclass('public.agent_skills') IS NOT NULL THEN
222
+ ALTER TABLE public.agent_skills ENABLE ROW LEVEL SECURITY;
223
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_skills;
224
+ CREATE POLICY analyst_tenant_isolation ON public.agent_skills
225
+ FOR SELECT TO analyst_reader
226
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
227
+ ELSE
228
+ missing := missing || 'agent_skills'::text;
229
+ END IF;
230
+ IF to_regclass('public.agent_template_mcp_servers') IS NOT NULL THEN
231
+ ALTER TABLE public.agent_template_mcp_servers ENABLE ROW LEVEL SECURITY;
232
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_template_mcp_servers;
233
+ CREATE POLICY analyst_tenant_isolation ON public.agent_template_mcp_servers
234
+ FOR SELECT TO analyst_reader
235
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
236
+ ELSE
237
+ missing := missing || 'agent_template_mcp_servers'::text;
238
+ END IF;
239
+ IF to_regclass('public.agent_templates') IS NOT NULL THEN
240
+ ALTER TABLE public.agent_templates ENABLE ROW LEVEL SECURITY;
241
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_templates;
242
+ CREATE POLICY analyst_tenant_isolation ON public.agent_templates
243
+ FOR SELECT TO analyst_reader
244
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
245
+ ELSE
246
+ missing := missing || 'agent_templates'::text;
247
+ END IF;
248
+ IF to_regclass('public.agent_versions') IS NOT NULL THEN
249
+ ALTER TABLE public.agent_versions ENABLE ROW LEVEL SECURITY;
250
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_versions;
251
+ CREATE POLICY analyst_tenant_isolation ON public.agent_versions
252
+ FOR SELECT TO analyst_reader
253
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
254
+ ELSE
255
+ missing := missing || 'agent_versions'::text;
256
+ END IF;
257
+ IF to_regclass('public.agent_wakeup_requests') IS NOT NULL THEN
258
+ ALTER TABLE public.agent_wakeup_requests ENABLE ROW LEVEL SECURITY;
259
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_wakeup_requests;
260
+ CREATE POLICY analyst_tenant_isolation ON public.agent_wakeup_requests
261
+ FOR SELECT TO analyst_reader
262
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
263
+ ELSE
264
+ missing := missing || 'agent_wakeup_requests'::text;
265
+ END IF;
266
+ IF to_regclass('public.agent_workspace_events') IS NOT NULL THEN
267
+ ALTER TABLE public.agent_workspace_events ENABLE ROW LEVEL SECURITY;
268
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_workspace_events;
269
+ CREATE POLICY analyst_tenant_isolation ON public.agent_workspace_events
270
+ FOR SELECT TO analyst_reader
271
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
272
+ ELSE
273
+ missing := missing || 'agent_workspace_events'::text;
274
+ END IF;
275
+ IF to_regclass('public.agent_workspace_runs') IS NOT NULL THEN
276
+ ALTER TABLE public.agent_workspace_runs ENABLE ROW LEVEL SECURITY;
277
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agent_workspace_runs;
278
+ CREATE POLICY analyst_tenant_isolation ON public.agent_workspace_runs
279
+ FOR SELECT TO analyst_reader
280
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
281
+ ELSE
282
+ missing := missing || 'agent_workspace_runs'::text;
283
+ END IF;
284
+ IF to_regclass('public.agents') IS NOT NULL THEN
285
+ ALTER TABLE public.agents ENABLE ROW LEVEL SECURITY;
286
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.agents;
287
+ CREATE POLICY analyst_tenant_isolation ON public.agents
288
+ FOR SELECT TO analyst_reader
289
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
290
+ ELSE
291
+ missing := missing || 'agents'::text;
292
+ END IF;
293
+ IF to_regclass('public.artifact_data_bindings') IS NOT NULL THEN
294
+ ALTER TABLE public.artifact_data_bindings ENABLE ROW LEVEL SECURITY;
295
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.artifact_data_bindings;
296
+ CREATE POLICY analyst_tenant_isolation ON public.artifact_data_bindings
297
+ FOR SELECT TO analyst_reader
298
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
299
+ ELSE
300
+ missing := missing || 'artifact_data_bindings'::text;
301
+ END IF;
302
+ IF to_regclass('public.artifact_shares') IS NOT NULL THEN
303
+ ALTER TABLE public.artifact_shares ENABLE ROW LEVEL SECURITY;
304
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.artifact_shares;
305
+ CREATE POLICY analyst_tenant_isolation ON public.artifact_shares
306
+ FOR SELECT TO analyst_reader
307
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
308
+ ELSE
309
+ missing := missing || 'artifact_shares'::text;
310
+ END IF;
311
+ IF to_regclass('public.artifact_versions') IS NOT NULL THEN
312
+ ALTER TABLE public.artifact_versions ENABLE ROW LEVEL SECURITY;
313
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.artifact_versions;
314
+ CREATE POLICY analyst_tenant_isolation ON public.artifact_versions
315
+ FOR SELECT TO analyst_reader
316
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
317
+ ELSE
318
+ missing := missing || 'artifact_versions'::text;
319
+ END IF;
320
+ IF to_regclass('public.artifacts') IS NOT NULL THEN
321
+ ALTER TABLE public.artifacts ENABLE ROW LEVEL SECURITY;
322
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.artifacts;
323
+ CREATE POLICY analyst_tenant_isolation ON public.artifacts
324
+ FOR SELECT TO analyst_reader
325
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
326
+ ELSE
327
+ missing := missing || 'artifacts'::text;
328
+ END IF;
329
+ IF to_regclass('public.billing_export_line_items') IS NOT NULL THEN
330
+ ALTER TABLE public.billing_export_line_items ENABLE ROW LEVEL SECURITY;
331
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.billing_export_line_items;
332
+ CREATE POLICY analyst_tenant_isolation ON public.billing_export_line_items
333
+ FOR SELECT TO analyst_reader
334
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
335
+ ELSE
336
+ missing := missing || 'billing_export_line_items'::text;
337
+ END IF;
338
+ IF to_regclass('public.brain_dream_actions') IS NOT NULL THEN
339
+ ALTER TABLE public.brain_dream_actions ENABLE ROW LEVEL SECURITY;
340
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.brain_dream_actions;
341
+ CREATE POLICY analyst_tenant_isolation ON public.brain_dream_actions
342
+ FOR SELECT TO analyst_reader
343
+ USING (EXISTS (SELECT 1 FROM public.brain_dream_runs p WHERE p.id = public.brain_dream_actions.run_id AND p.tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid));
344
+ ELSE
345
+ missing := missing || 'brain_dream_actions'::text;
346
+ END IF;
347
+ IF to_regclass('public.brain_dream_runs') IS NOT NULL THEN
348
+ ALTER TABLE public.brain_dream_runs ENABLE ROW LEVEL SECURITY;
349
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.brain_dream_runs;
350
+ CREATE POLICY analyst_tenant_isolation ON public.brain_dream_runs
351
+ FOR SELECT TO analyst_reader
352
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
353
+ ELSE
354
+ missing := missing || 'brain_dream_runs'::text;
355
+ END IF;
356
+ IF to_regclass('public.budget_policies') IS NOT NULL THEN
357
+ ALTER TABLE public.budget_policies ENABLE ROW LEVEL SECURITY;
358
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.budget_policies;
359
+ CREATE POLICY analyst_tenant_isolation ON public.budget_policies
360
+ FOR SELECT TO analyst_reader
361
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
362
+ ELSE
363
+ missing := missing || 'budget_policies'::text;
364
+ END IF;
365
+ IF to_regclass('public.connections') IS NOT NULL THEN
366
+ ALTER TABLE public.connections ENABLE ROW LEVEL SECURITY;
367
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.connections;
368
+ CREATE POLICY analyst_tenant_isolation ON public.connections
369
+ FOR SELECT TO analyst_reader
370
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
371
+ ELSE
372
+ missing := missing || 'connections'::text;
373
+ END IF;
374
+ IF to_regclass('public.cost_events') IS NOT NULL THEN
375
+ ALTER TABLE public.cost_events ENABLE ROW LEVEL SECURITY;
376
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.cost_events;
377
+ CREATE POLICY analyst_tenant_isolation ON public.cost_events
378
+ FOR SELECT TO analyst_reader
379
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
380
+ ELSE
381
+ missing := missing || 'cost_events'::text;
382
+ END IF;
383
+ IF to_regclass('public.crm_work_links') IS NOT NULL THEN
384
+ ALTER TABLE public.crm_work_links ENABLE ROW LEVEL SECURITY;
385
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.crm_work_links;
386
+ CREATE POLICY analyst_tenant_isolation ON public.crm_work_links
387
+ FOR SELECT TO analyst_reader
388
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
389
+ ELSE
390
+ missing := missing || 'crm_work_links'::text;
391
+ END IF;
392
+ IF to_regclass('public.document_conformance_reports') IS NOT NULL THEN
393
+ ALTER TABLE public.document_conformance_reports ENABLE ROW LEVEL SECURITY;
394
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.document_conformance_reports;
395
+ CREATE POLICY analyst_tenant_isolation ON public.document_conformance_reports
396
+ FOR SELECT TO analyst_reader
397
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
398
+ ELSE
399
+ missing := missing || 'document_conformance_reports'::text;
400
+ END IF;
401
+ IF to_regclass('public.document_plates') IS NOT NULL THEN
402
+ ALTER TABLE public.document_plates ENABLE ROW LEVEL SECURITY;
403
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.document_plates;
404
+ CREATE POLICY analyst_tenant_isolation ON public.document_plates
405
+ FOR SELECT TO analyst_reader
406
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
407
+ ELSE
408
+ missing := missing || 'document_plates'::text;
409
+ END IF;
410
+ IF to_regclass('public.document_section_waivers') IS NOT NULL THEN
411
+ ALTER TABLE public.document_section_waivers ENABLE ROW LEVEL SECURITY;
412
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.document_section_waivers;
413
+ CREATE POLICY analyst_tenant_isolation ON public.document_section_waivers
414
+ FOR SELECT TO analyst_reader
415
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
416
+ ELSE
417
+ missing := missing || 'document_section_waivers'::text;
418
+ END IF;
419
+ IF to_regclass('public.documents') IS NOT NULL THEN
420
+ ALTER TABLE public.documents ENABLE ROW LEVEL SECURITY;
421
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.documents;
422
+ CREATE POLICY analyst_tenant_isolation ON public.documents
423
+ FOR SELECT TO analyst_reader
424
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
425
+ ELSE
426
+ missing := missing || 'documents'::text;
427
+ END IF;
428
+ IF to_regclass('public.email_body_objects') IS NOT NULL THEN
429
+ ALTER TABLE public.email_body_objects ENABLE ROW LEVEL SECURITY;
430
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.email_body_objects;
431
+ CREATE POLICY analyst_tenant_isolation ON public.email_body_objects
432
+ FOR SELECT TO analyst_reader
433
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
434
+ ELSE
435
+ missing := missing || 'email_body_objects'::text;
436
+ END IF;
437
+ IF to_regclass('public.email_conversations') IS NOT NULL THEN
438
+ ALTER TABLE public.email_conversations ENABLE ROW LEVEL SECURITY;
439
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.email_conversations;
440
+ CREATE POLICY analyst_tenant_isolation ON public.email_conversations
441
+ FOR SELECT TO analyst_reader
442
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
443
+ ELSE
444
+ missing := missing || 'email_conversations'::text;
445
+ END IF;
446
+ IF to_regclass('public.email_domains') IS NOT NULL THEN
447
+ ALTER TABLE public.email_domains ENABLE ROW LEVEL SECURITY;
448
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.email_domains;
449
+ CREATE POLICY analyst_tenant_isolation ON public.email_domains
450
+ FOR SELECT TO analyst_reader
451
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
452
+ ELSE
453
+ missing := missing || 'email_domains'::text;
454
+ END IF;
455
+ IF to_regclass('public.email_ledger_events') IS NOT NULL THEN
456
+ ALTER TABLE public.email_ledger_events ENABLE ROW LEVEL SECURITY;
457
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.email_ledger_events;
458
+ CREATE POLICY analyst_tenant_isolation ON public.email_ledger_events
459
+ FOR SELECT TO analyst_reader
460
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
461
+ ELSE
462
+ missing := missing || 'email_ledger_events'::text;
463
+ END IF;
464
+ IF to_regclass('public.email_provider_events') IS NOT NULL THEN
465
+ ALTER TABLE public.email_provider_events ENABLE ROW LEVEL SECURITY;
466
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.email_provider_events;
467
+ CREATE POLICY analyst_tenant_isolation ON public.email_provider_events
468
+ FOR SELECT TO analyst_reader
469
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
470
+ ELSE
471
+ missing := missing || 'email_provider_events'::text;
472
+ END IF;
473
+ IF to_regclass('public.email_readiness_checks') IS NOT NULL THEN
474
+ ALTER TABLE public.email_readiness_checks ENABLE ROW LEVEL SECURITY;
475
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.email_readiness_checks;
476
+ CREATE POLICY analyst_tenant_isolation ON public.email_readiness_checks
477
+ FOR SELECT TO analyst_reader
478
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
479
+ ELSE
480
+ missing := missing || 'email_readiness_checks'::text;
481
+ END IF;
482
+ IF to_regclass('public.email_ses_compatibility_mappings') IS NOT NULL THEN
483
+ ALTER TABLE public.email_ses_compatibility_mappings ENABLE ROW LEVEL SECURITY;
484
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.email_ses_compatibility_mappings;
485
+ CREATE POLICY analyst_tenant_isolation ON public.email_ses_compatibility_mappings
486
+ FOR SELECT TO analyst_reader
487
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
488
+ ELSE
489
+ missing := missing || 'email_ses_compatibility_mappings'::text;
490
+ END IF;
491
+ IF to_regclass('public.email_space_policies') IS NOT NULL THEN
492
+ ALTER TABLE public.email_space_policies ENABLE ROW LEVEL SECURITY;
493
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.email_space_policies;
494
+ CREATE POLICY analyst_tenant_isolation ON public.email_space_policies
495
+ FOR SELECT TO analyst_reader
496
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
497
+ ELSE
498
+ missing := missing || 'email_space_policies'::text;
499
+ END IF;
500
+ IF to_regclass('public.email_space_sender_allowlists') IS NOT NULL THEN
501
+ ALTER TABLE public.email_space_sender_allowlists ENABLE ROW LEVEL SECURITY;
502
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.email_space_sender_allowlists;
503
+ CREATE POLICY analyst_tenant_isolation ON public.email_space_sender_allowlists
504
+ FOR SELECT TO analyst_reader
505
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
506
+ ELSE
507
+ missing := missing || 'email_space_sender_allowlists'::text;
508
+ END IF;
509
+ IF to_regclass('public.eval_case_overrides') IS NOT NULL THEN
510
+ ALTER TABLE public.eval_case_overrides ENABLE ROW LEVEL SECURITY;
511
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.eval_case_overrides;
512
+ CREATE POLICY analyst_tenant_isolation ON public.eval_case_overrides
513
+ FOR SELECT TO analyst_reader
514
+ USING (EXISTS (SELECT 1 FROM public.eval_runs p WHERE p.id = public.eval_case_overrides.run_id AND p.tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid));
515
+ ELSE
516
+ missing := missing || 'eval_case_overrides'::text;
517
+ END IF;
518
+ IF to_regclass('public.eval_datasets') IS NOT NULL THEN
519
+ ALTER TABLE public.eval_datasets ENABLE ROW LEVEL SECURITY;
520
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.eval_datasets;
521
+ CREATE POLICY analyst_tenant_isolation ON public.eval_datasets
522
+ FOR SELECT TO analyst_reader
523
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
524
+ ELSE
525
+ missing := missing || 'eval_datasets'::text;
526
+ END IF;
527
+ IF to_regclass('public.eval_profiles') IS NOT NULL THEN
528
+ ALTER TABLE public.eval_profiles ENABLE ROW LEVEL SECURITY;
529
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.eval_profiles;
530
+ CREATE POLICY analyst_tenant_isolation ON public.eval_profiles
531
+ FOR SELECT TO analyst_reader
532
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
533
+ ELSE
534
+ missing := missing || 'eval_profiles'::text;
535
+ END IF;
536
+ IF to_regclass('public.eval_replay_tool_allowlist') IS NOT NULL THEN
537
+ ALTER TABLE public.eval_replay_tool_allowlist ENABLE ROW LEVEL SECURITY;
538
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.eval_replay_tool_allowlist;
539
+ CREATE POLICY analyst_tenant_isolation ON public.eval_replay_tool_allowlist
540
+ FOR SELECT TO analyst_reader
541
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
542
+ ELSE
543
+ missing := missing || 'eval_replay_tool_allowlist'::text;
544
+ END IF;
545
+ IF to_regclass('public.eval_results') IS NOT NULL THEN
546
+ ALTER TABLE public.eval_results ENABLE ROW LEVEL SECURITY;
547
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.eval_results;
548
+ CREATE POLICY analyst_tenant_isolation ON public.eval_results
549
+ FOR SELECT TO analyst_reader
550
+ USING (EXISTS (SELECT 1 FROM public.eval_runs p WHERE p.id = public.eval_results.run_id AND p.tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid));
551
+ ELSE
552
+ missing := missing || 'eval_results'::text;
553
+ END IF;
554
+ IF to_regclass('public.eval_runs') IS NOT NULL THEN
555
+ ALTER TABLE public.eval_runs ENABLE ROW LEVEL SECURITY;
556
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.eval_runs;
557
+ CREATE POLICY analyst_tenant_isolation ON public.eval_runs
558
+ FOR SELECT TO analyst_reader
559
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
560
+ ELSE
561
+ missing := missing || 'eval_runs'::text;
562
+ END IF;
563
+ IF to_regclass('public.eval_skill_gate') IS NOT NULL THEN
564
+ ALTER TABLE public.eval_skill_gate ENABLE ROW LEVEL SECURITY;
565
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.eval_skill_gate;
566
+ CREATE POLICY analyst_tenant_isolation ON public.eval_skill_gate
567
+ FOR SELECT TO analyst_reader
568
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
569
+ ELSE
570
+ missing := missing || 'eval_skill_gate'::text;
571
+ END IF;
572
+ IF to_regclass('public.eval_test_cases') IS NOT NULL THEN
573
+ ALTER TABLE public.eval_test_cases ENABLE ROW LEVEL SECURITY;
574
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.eval_test_cases;
575
+ CREATE POLICY analyst_tenant_isolation ON public.eval_test_cases
576
+ FOR SELECT TO analyst_reader
577
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
578
+ ELSE
579
+ missing := missing || 'eval_test_cases'::text;
580
+ END IF;
581
+ IF to_regclass('public.folder_bundle_import_rate_limits') IS NOT NULL THEN
582
+ ALTER TABLE public.folder_bundle_import_rate_limits ENABLE ROW LEVEL SECURITY;
583
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.folder_bundle_import_rate_limits;
584
+ CREATE POLICY analyst_tenant_isolation ON public.folder_bundle_import_rate_limits
585
+ FOR SELECT TO analyst_reader
586
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
587
+ ELSE
588
+ missing := missing || 'folder_bundle_import_rate_limits'::text;
589
+ END IF;
590
+ IF to_regclass('public.github_app_installations') IS NOT NULL THEN
591
+ ALTER TABLE public.github_app_installations ENABLE ROW LEVEL SECURITY;
592
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.github_app_installations;
593
+ CREATE POLICY analyst_tenant_isolation ON public.github_app_installations
594
+ FOR SELECT TO analyst_reader
595
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
596
+ ELSE
597
+ missing := missing || 'github_app_installations'::text;
598
+ END IF;
599
+ IF to_regclass('public.github_webhook_deliveries') IS NOT NULL THEN
600
+ ALTER TABLE public.github_webhook_deliveries ENABLE ROW LEVEL SECURITY;
601
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.github_webhook_deliveries;
602
+ CREATE POLICY analyst_tenant_isolation ON public.github_webhook_deliveries
603
+ FOR SELECT TO analyst_reader
604
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
605
+ ELSE
606
+ missing := missing || 'github_webhook_deliveries'::text;
607
+ END IF;
608
+ IF to_regclass('public.goals') IS NOT NULL THEN
609
+ ALTER TABLE public.goals ENABLE ROW LEVEL SECURITY;
610
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.goals;
611
+ CREATE POLICY analyst_tenant_isolation ON public.goals
612
+ FOR SELECT TO analyst_reader
613
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
614
+ ELSE
615
+ missing := missing || 'goals'::text;
616
+ END IF;
617
+ IF to_regclass('public.guardrail_blocks') IS NOT NULL THEN
618
+ ALTER TABLE public.guardrail_blocks ENABLE ROW LEVEL SECURITY;
619
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.guardrail_blocks;
620
+ CREATE POLICY analyst_tenant_isolation ON public.guardrail_blocks
621
+ FOR SELECT TO analyst_reader
622
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
623
+ ELSE
624
+ missing := missing || 'guardrail_blocks'::text;
625
+ END IF;
626
+ IF to_regclass('public.guardrails') IS NOT NULL THEN
627
+ ALTER TABLE public.guardrails ENABLE ROW LEVEL SECURITY;
628
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.guardrails;
629
+ CREATE POLICY analyst_tenant_isolation ON public.guardrails
630
+ FOR SELECT TO analyst_reader
631
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
632
+ ELSE
633
+ missing := missing || 'guardrails'::text;
634
+ END IF;
635
+ IF to_regclass('public.inbox_item_comments') IS NOT NULL THEN
636
+ ALTER TABLE public.inbox_item_comments ENABLE ROW LEVEL SECURITY;
637
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.inbox_item_comments;
638
+ CREATE POLICY analyst_tenant_isolation ON public.inbox_item_comments
639
+ FOR SELECT TO analyst_reader
640
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
641
+ ELSE
642
+ missing := missing || 'inbox_item_comments'::text;
643
+ END IF;
644
+ IF to_regclass('public.inbox_item_links') IS NOT NULL THEN
645
+ ALTER TABLE public.inbox_item_links ENABLE ROW LEVEL SECURITY;
646
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.inbox_item_links;
647
+ CREATE POLICY analyst_tenant_isolation ON public.inbox_item_links
648
+ FOR SELECT TO analyst_reader
649
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
650
+ ELSE
651
+ missing := missing || 'inbox_item_links'::text;
652
+ END IF;
653
+ IF to_regclass('public.inbox_items') IS NOT NULL THEN
654
+ ALTER TABLE public.inbox_items ENABLE ROW LEVEL SECURITY;
655
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.inbox_items;
656
+ CREATE POLICY analyst_tenant_isolation ON public.inbox_items
657
+ FOR SELECT TO analyst_reader
658
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
659
+ ELSE
660
+ missing := missing || 'inbox_items'::text;
661
+ END IF;
662
+ IF to_regclass('public.knowledge_bases') IS NOT NULL THEN
663
+ ALTER TABLE public.knowledge_bases ENABLE ROW LEVEL SECURITY;
664
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.knowledge_bases;
665
+ CREATE POLICY analyst_tenant_isolation ON public.knowledge_bases
666
+ FOR SELECT TO analyst_reader
667
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
668
+ ELSE
669
+ missing := missing || 'knowledge_bases'::text;
670
+ END IF;
671
+ IF to_regclass('public.knowledge_graph_entities') IS NOT NULL THEN
672
+ ALTER TABLE public.knowledge_graph_entities ENABLE ROW LEVEL SECURITY;
673
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.knowledge_graph_entities;
674
+ CREATE POLICY analyst_tenant_isolation ON public.knowledge_graph_entities
675
+ FOR SELECT TO analyst_reader
676
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
677
+ ELSE
678
+ missing := missing || 'knowledge_graph_entities'::text;
679
+ END IF;
680
+ IF to_regclass('public.knowledge_graph_evidence') IS NOT NULL THEN
681
+ ALTER TABLE public.knowledge_graph_evidence ENABLE ROW LEVEL SECURITY;
682
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.knowledge_graph_evidence;
683
+ CREATE POLICY analyst_tenant_isolation ON public.knowledge_graph_evidence
684
+ FOR SELECT TO analyst_reader
685
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
686
+ ELSE
687
+ missing := missing || 'knowledge_graph_evidence'::text;
688
+ END IF;
689
+ IF to_regclass('public.knowledge_graph_ingest_runs') IS NOT NULL THEN
690
+ ALTER TABLE public.knowledge_graph_ingest_runs ENABLE ROW LEVEL SECURITY;
691
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.knowledge_graph_ingest_runs;
692
+ CREATE POLICY analyst_tenant_isolation ON public.knowledge_graph_ingest_runs
693
+ FOR SELECT TO analyst_reader
694
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
695
+ ELSE
696
+ missing := missing || 'knowledge_graph_ingest_runs'::text;
697
+ END IF;
698
+ IF to_regclass('public.knowledge_graph_observation_cursors') IS NOT NULL THEN
699
+ ALTER TABLE public.knowledge_graph_observation_cursors ENABLE ROW LEVEL SECURITY;
700
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.knowledge_graph_observation_cursors;
701
+ CREATE POLICY analyst_tenant_isolation ON public.knowledge_graph_observation_cursors
702
+ FOR SELECT TO analyst_reader
703
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
704
+ ELSE
705
+ missing := missing || 'knowledge_graph_observation_cursors'::text;
706
+ END IF;
707
+ IF to_regclass('public.knowledge_graph_relationships') IS NOT NULL THEN
708
+ ALTER TABLE public.knowledge_graph_relationships ENABLE ROW LEVEL SECURITY;
709
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.knowledge_graph_relationships;
710
+ CREATE POLICY analyst_tenant_isolation ON public.knowledge_graph_relationships
711
+ FOR SELECT TO analyst_reader
712
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
713
+ ELSE
714
+ missing := missing || 'knowledge_graph_relationships'::text;
715
+ END IF;
716
+ IF to_regclass('public.linked_task_events') IS NOT NULL THEN
717
+ ALTER TABLE public.linked_task_events ENABLE ROW LEVEL SECURITY;
718
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.linked_task_events;
719
+ CREATE POLICY analyst_tenant_isolation ON public.linked_task_events
720
+ FOR SELECT TO analyst_reader
721
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
722
+ ELSE
723
+ missing := missing || 'linked_task_events'::text;
724
+ END IF;
725
+ IF to_regclass('public.linked_tasks') IS NOT NULL THEN
726
+ ALTER TABLE public.linked_tasks ENABLE ROW LEVEL SECURITY;
727
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.linked_tasks;
728
+ CREATE POLICY analyst_tenant_isolation ON public.linked_tasks
729
+ FOR SELECT TO analyst_reader
730
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
731
+ ELSE
732
+ missing := missing || 'linked_tasks'::text;
733
+ END IF;
734
+ IF to_regclass('public.managed_application_deployment_events') IS NOT NULL THEN
735
+ ALTER TABLE public.managed_application_deployment_events ENABLE ROW LEVEL SECURITY;
736
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.managed_application_deployment_events;
737
+ CREATE POLICY analyst_tenant_isolation ON public.managed_application_deployment_events
738
+ FOR SELECT TO analyst_reader
739
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
740
+ ELSE
741
+ missing := missing || 'managed_application_deployment_events'::text;
742
+ END IF;
743
+ IF to_regclass('public.managed_application_deployment_jobs') IS NOT NULL THEN
744
+ ALTER TABLE public.managed_application_deployment_jobs ENABLE ROW LEVEL SECURITY;
745
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.managed_application_deployment_jobs;
746
+ CREATE POLICY analyst_tenant_isolation ON public.managed_application_deployment_jobs
747
+ FOR SELECT TO analyst_reader
748
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
749
+ ELSE
750
+ missing := missing || 'managed_application_deployment_jobs'::text;
751
+ END IF;
752
+ IF to_regclass('public.managed_applications') IS NOT NULL THEN
753
+ ALTER TABLE public.managed_applications ENABLE ROW LEVEL SECURITY;
754
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.managed_applications;
755
+ CREATE POLICY analyst_tenant_isolation ON public.managed_applications
756
+ FOR SELECT TO analyst_reader
757
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
758
+ ELSE
759
+ missing := missing || 'managed_applications'::text;
760
+ END IF;
761
+ IF to_regclass('public.memory_retain_attempts') IS NOT NULL THEN
762
+ ALTER TABLE public.memory_retain_attempts ENABLE ROW LEVEL SECURITY;
763
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.memory_retain_attempts;
764
+ CREATE POLICY analyst_tenant_isolation ON public.memory_retain_attempts
765
+ FOR SELECT TO analyst_reader
766
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
767
+ ELSE
768
+ missing := missing || 'memory_retain_attempts'::text;
769
+ END IF;
770
+ IF to_regclass('public.message_artifacts') IS NOT NULL THEN
771
+ ALTER TABLE public.message_artifacts ENABLE ROW LEVEL SECURITY;
772
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.message_artifacts;
773
+ CREATE POLICY analyst_tenant_isolation ON public.message_artifacts
774
+ FOR SELECT TO analyst_reader
775
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
776
+ ELSE
777
+ missing := missing || 'message_artifacts'::text;
778
+ END IF;
779
+ IF to_regclass('public.message_mentions') IS NOT NULL THEN
780
+ ALTER TABLE public.message_mentions ENABLE ROW LEVEL SECURITY;
781
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.message_mentions;
782
+ CREATE POLICY analyst_tenant_isolation ON public.message_mentions
783
+ FOR SELECT TO analyst_reader
784
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
785
+ ELSE
786
+ missing := missing || 'message_mentions'::text;
787
+ END IF;
788
+ IF to_regclass('public.messages') IS NOT NULL THEN
789
+ ALTER TABLE public.messages ENABLE ROW LEVEL SECURITY;
790
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.messages;
791
+ CREATE POLICY analyst_tenant_isolation ON public.messages
792
+ FOR SELECT TO analyst_reader
793
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
794
+ ELSE
795
+ missing := missing || 'messages'::text;
796
+ END IF;
797
+ IF to_regclass('public.mutation_idempotency') IS NOT NULL THEN
798
+ ALTER TABLE public.mutation_idempotency ENABLE ROW LEVEL SECURITY;
799
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.mutation_idempotency;
800
+ CREATE POLICY analyst_tenant_isolation ON public.mutation_idempotency
801
+ FOR SELECT TO analyst_reader
802
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
803
+ ELSE
804
+ missing := missing || 'mutation_idempotency'::text;
805
+ END IF;
806
+ IF to_regclass('public.pending_user_questions') IS NOT NULL THEN
807
+ ALTER TABLE public.pending_user_questions ENABLE ROW LEVEL SECURITY;
808
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.pending_user_questions;
809
+ CREATE POLICY analyst_tenant_isolation ON public.pending_user_questions
810
+ FOR SELECT TO analyst_reader
811
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
812
+ ELSE
813
+ missing := missing || 'pending_user_questions'::text;
814
+ END IF;
815
+ IF to_regclass('public.pi_extension_assignments') IS NOT NULL THEN
816
+ ALTER TABLE public.pi_extension_assignments ENABLE ROW LEVEL SECURITY;
817
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.pi_extension_assignments;
818
+ CREATE POLICY analyst_tenant_isolation ON public.pi_extension_assignments
819
+ FOR SELECT TO analyst_reader
820
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
821
+ ELSE
822
+ missing := missing || 'pi_extension_assignments'::text;
823
+ END IF;
824
+ IF to_regclass('public.pi_extension_sources') IS NOT NULL THEN
825
+ ALTER TABLE public.pi_extension_sources ENABLE ROW LEVEL SECURITY;
826
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.pi_extension_sources;
827
+ CREATE POLICY analyst_tenant_isolation ON public.pi_extension_sources
828
+ FOR SELECT TO analyst_reader
829
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
830
+ ELSE
831
+ missing := missing || 'pi_extension_sources'::text;
832
+ END IF;
833
+ IF to_regclass('public.pi_extension_versions') IS NOT NULL THEN
834
+ ALTER TABLE public.pi_extension_versions ENABLE ROW LEVEL SECURITY;
835
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.pi_extension_versions;
836
+ CREATE POLICY analyst_tenant_isolation ON public.pi_extension_versions
837
+ FOR SELECT TO analyst_reader
838
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
839
+ ELSE
840
+ missing := missing || 'pi_extension_versions'::text;
841
+ END IF;
842
+ IF to_regclass('public.plugin_app_overlays') IS NOT NULL THEN
843
+ ALTER TABLE public.plugin_app_overlays ENABLE ROW LEVEL SECURITY;
844
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.plugin_app_overlays;
845
+ CREATE POLICY analyst_tenant_isolation ON public.plugin_app_overlays
846
+ FOR SELECT TO analyst_reader
847
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
848
+ ELSE
849
+ missing := missing || 'plugin_app_overlays'::text;
850
+ END IF;
851
+ IF to_regclass('public.plugin_components') IS NOT NULL THEN
852
+ ALTER TABLE public.plugin_components ENABLE ROW LEVEL SECURITY;
853
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.plugin_components;
854
+ CREATE POLICY analyst_tenant_isolation ON public.plugin_components
855
+ FOR SELECT TO analyst_reader
856
+ USING (EXISTS (SELECT 1 FROM public.plugin_installs p WHERE p.id = public.plugin_components.plugin_install_id AND p.tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid));
857
+ ELSE
858
+ missing := missing || 'plugin_components'::text;
859
+ END IF;
860
+ IF to_regclass('public.plugin_entitlements') IS NOT NULL THEN
861
+ ALTER TABLE public.plugin_entitlements ENABLE ROW LEVEL SECURITY;
862
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.plugin_entitlements;
863
+ CREATE POLICY analyst_tenant_isolation ON public.plugin_entitlements
864
+ FOR SELECT TO analyst_reader
865
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
866
+ ELSE
867
+ missing := missing || 'plugin_entitlements'::text;
868
+ END IF;
869
+ IF to_regclass('public.plugin_installs') IS NOT NULL THEN
870
+ ALTER TABLE public.plugin_installs ENABLE ROW LEVEL SECURITY;
871
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.plugin_installs;
872
+ CREATE POLICY analyst_tenant_isolation ON public.plugin_installs
873
+ FOR SELECT TO analyst_reader
874
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
875
+ ELSE
876
+ missing := missing || 'plugin_installs'::text;
877
+ END IF;
878
+ IF to_regclass('public.plugin_uploads') IS NOT NULL THEN
879
+ ALTER TABLE public.plugin_uploads ENABLE ROW LEVEL SECURITY;
880
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.plugin_uploads;
881
+ CREATE POLICY analyst_tenant_isolation ON public.plugin_uploads
882
+ FOR SELECT TO analyst_reader
883
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
884
+ ELSE
885
+ missing := missing || 'plugin_uploads'::text;
886
+ END IF;
887
+ IF to_regclass('public.principal_permission_grants') IS NOT NULL THEN
888
+ ALTER TABLE public.principal_permission_grants ENABLE ROW LEVEL SECURITY;
889
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.principal_permission_grants;
890
+ CREATE POLICY analyst_tenant_isolation ON public.principal_permission_grants
891
+ FOR SELECT TO analyst_reader
892
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
893
+ ELSE
894
+ missing := missing || 'principal_permission_grants'::text;
895
+ END IF;
896
+ IF to_regclass('public.recipes') IS NOT NULL THEN
897
+ ALTER TABLE public.recipes ENABLE ROW LEVEL SECURITY;
898
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.recipes;
899
+ CREATE POLICY analyst_tenant_isolation ON public.recipes
900
+ FOR SELECT TO analyst_reader
901
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
902
+ ELSE
903
+ missing := missing || 'recipes'::text;
904
+ END IF;
905
+ IF to_regclass('public.release_update_events') IS NOT NULL THEN
906
+ ALTER TABLE public.release_update_events ENABLE ROW LEVEL SECURITY;
907
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.release_update_events;
908
+ CREATE POLICY analyst_tenant_isolation ON public.release_update_events
909
+ FOR SELECT TO analyst_reader
910
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
911
+ ELSE
912
+ missing := missing || 'release_update_events'::text;
913
+ END IF;
914
+ IF to_regclass('public.release_update_jobs') IS NOT NULL THEN
915
+ ALTER TABLE public.release_update_jobs ENABLE ROW LEVEL SECURITY;
916
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.release_update_jobs;
917
+ CREATE POLICY analyst_tenant_isolation ON public.release_update_jobs
918
+ FOR SELECT TO analyst_reader
919
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
920
+ ELSE
921
+ missing := missing || 'release_update_jobs'::text;
922
+ END IF;
923
+ IF to_regclass('public.resolved_capability_manifests') IS NOT NULL THEN
924
+ ALTER TABLE public.resolved_capability_manifests ENABLE ROW LEVEL SECURITY;
925
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.resolved_capability_manifests;
926
+ CREATE POLICY analyst_tenant_isolation ON public.resolved_capability_manifests
927
+ FOR SELECT TO analyst_reader
928
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
929
+ ELSE
930
+ missing := missing || 'resolved_capability_manifests'::text;
931
+ END IF;
932
+ IF to_regclass('public.retry_queue') IS NOT NULL THEN
933
+ ALTER TABLE public.retry_queue ENABLE ROW LEVEL SECURITY;
934
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.retry_queue;
935
+ CREATE POLICY analyst_tenant_isolation ON public.retry_queue
936
+ FOR SELECT TO analyst_reader
937
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
938
+ ELSE
939
+ missing := missing || 'retry_queue'::text;
940
+ END IF;
941
+ IF to_regclass('public.routine_asl_versions') IS NOT NULL THEN
942
+ ALTER TABLE public.routine_asl_versions ENABLE ROW LEVEL SECURITY;
943
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.routine_asl_versions;
944
+ CREATE POLICY analyst_tenant_isolation ON public.routine_asl_versions
945
+ FOR SELECT TO analyst_reader
946
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
947
+ ELSE
948
+ missing := missing || 'routine_asl_versions'::text;
949
+ END IF;
950
+ IF to_regclass('public.routine_code_cache') IS NOT NULL THEN
951
+ ALTER TABLE public.routine_code_cache ENABLE ROW LEVEL SECURITY;
952
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.routine_code_cache;
953
+ CREATE POLICY analyst_tenant_isolation ON public.routine_code_cache
954
+ FOR SELECT TO analyst_reader
955
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
956
+ ELSE
957
+ missing := missing || 'routine_code_cache'::text;
958
+ END IF;
959
+ IF to_regclass('public.routine_executions') IS NOT NULL THEN
960
+ ALTER TABLE public.routine_executions ENABLE ROW LEVEL SECURITY;
961
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.routine_executions;
962
+ CREATE POLICY analyst_tenant_isolation ON public.routine_executions
963
+ FOR SELECT TO analyst_reader
964
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
965
+ ELSE
966
+ missing := missing || 'routine_executions'::text;
967
+ END IF;
968
+ IF to_regclass('public.routine_repair_events') IS NOT NULL THEN
969
+ ALTER TABLE public.routine_repair_events ENABLE ROW LEVEL SECURITY;
970
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.routine_repair_events;
971
+ CREATE POLICY analyst_tenant_isolation ON public.routine_repair_events
972
+ FOR SELECT TO analyst_reader
973
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
974
+ ELSE
975
+ missing := missing || 'routine_repair_events'::text;
976
+ END IF;
977
+ IF to_regclass('public.routine_step_events') IS NOT NULL THEN
978
+ ALTER TABLE public.routine_step_events ENABLE ROW LEVEL SECURITY;
979
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.routine_step_events;
980
+ CREATE POLICY analyst_tenant_isolation ON public.routine_step_events
981
+ FOR SELECT TO analyst_reader
982
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
983
+ ELSE
984
+ missing := missing || 'routine_step_events'::text;
985
+ END IF;
986
+ IF to_regclass('public.routines') IS NOT NULL THEN
987
+ ALTER TABLE public.routines ENABLE ROW LEVEL SECURITY;
988
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.routines;
989
+ CREATE POLICY analyst_tenant_isolation ON public.routines
990
+ FOR SELECT TO analyst_reader
991
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
992
+ ELSE
993
+ missing := missing || 'routines'::text;
994
+ END IF;
995
+ IF to_regclass('public.sandbox_agent_hourly_counters') IS NOT NULL THEN
996
+ ALTER TABLE public.sandbox_agent_hourly_counters ENABLE ROW LEVEL SECURITY;
997
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.sandbox_agent_hourly_counters;
998
+ CREATE POLICY analyst_tenant_isolation ON public.sandbox_agent_hourly_counters
999
+ FOR SELECT TO analyst_reader
1000
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1001
+ ELSE
1002
+ missing := missing || 'sandbox_agent_hourly_counters'::text;
1003
+ END IF;
1004
+ IF to_regclass('public.sandbox_invocations') IS NOT NULL THEN
1005
+ ALTER TABLE public.sandbox_invocations ENABLE ROW LEVEL SECURITY;
1006
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.sandbox_invocations;
1007
+ CREATE POLICY analyst_tenant_isolation ON public.sandbox_invocations
1008
+ FOR SELECT TO analyst_reader
1009
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1010
+ ELSE
1011
+ missing := missing || 'sandbox_invocations'::text;
1012
+ END IF;
1013
+ IF to_regclass('public.sandbox_tenant_daily_counters') IS NOT NULL THEN
1014
+ ALTER TABLE public.sandbox_tenant_daily_counters ENABLE ROW LEVEL SECURITY;
1015
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.sandbox_tenant_daily_counters;
1016
+ CREATE POLICY analyst_tenant_isolation ON public.sandbox_tenant_daily_counters
1017
+ FOR SELECT TO analyst_reader
1018
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1019
+ ELSE
1020
+ missing := missing || 'sandbox_tenant_daily_counters'::text;
1021
+ END IF;
1022
+ IF to_regclass('public.scheduled_jobs') IS NOT NULL THEN
1023
+ ALTER TABLE public.scheduled_jobs ENABLE ROW LEVEL SECURITY;
1024
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.scheduled_jobs;
1025
+ CREATE POLICY analyst_tenant_isolation ON public.scheduled_jobs
1026
+ FOR SELECT TO analyst_reader
1027
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1028
+ ELSE
1029
+ missing := missing || 'scheduled_jobs'::text;
1030
+ END IF;
1031
+ IF to_regclass('public.skill_catalog') IS NOT NULL THEN
1032
+ ALTER TABLE public.skill_catalog ENABLE ROW LEVEL SECURITY;
1033
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.skill_catalog;
1034
+ CREATE POLICY analyst_tenant_isolation ON public.skill_catalog
1035
+ FOR SELECT TO analyst_reader
1036
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1037
+ ELSE
1038
+ missing := missing || 'skill_catalog'::text;
1039
+ END IF;
1040
+ IF to_regclass('public.skill_draft_events') IS NOT NULL THEN
1041
+ ALTER TABLE public.skill_draft_events ENABLE ROW LEVEL SECURITY;
1042
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.skill_draft_events;
1043
+ CREATE POLICY analyst_tenant_isolation ON public.skill_draft_events
1044
+ FOR SELECT TO analyst_reader
1045
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1046
+ ELSE
1047
+ missing := missing || 'skill_draft_events'::text;
1048
+ END IF;
1049
+ IF to_regclass('public.skill_drafts') IS NOT NULL THEN
1050
+ ALTER TABLE public.skill_drafts ENABLE ROW LEVEL SECURITY;
1051
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.skill_drafts;
1052
+ CREATE POLICY analyst_tenant_isolation ON public.skill_drafts
1053
+ FOR SELECT TO analyst_reader
1054
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1055
+ ELSE
1056
+ missing := missing || 'skill_drafts'::text;
1057
+ END IF;
1058
+ IF to_regclass('public.skill_runs') IS NOT NULL THEN
1059
+ ALTER TABLE public.skill_runs ENABLE ROW LEVEL SECURITY;
1060
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.skill_runs;
1061
+ CREATE POLICY analyst_tenant_isolation ON public.skill_runs
1062
+ FOR SELECT TO analyst_reader
1063
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1064
+ ELSE
1065
+ missing := missing || 'skill_runs'::text;
1066
+ END IF;
1067
+ IF to_regclass('public.slack_threads') IS NOT NULL THEN
1068
+ ALTER TABLE public.slack_threads ENABLE ROW LEVEL SECURITY;
1069
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.slack_threads;
1070
+ CREATE POLICY analyst_tenant_isolation ON public.slack_threads
1071
+ FOR SELECT TO analyst_reader
1072
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1073
+ ELSE
1074
+ missing := missing || 'slack_threads'::text;
1075
+ END IF;
1076
+ IF to_regclass('public.slack_user_links') IS NOT NULL THEN
1077
+ ALTER TABLE public.slack_user_links ENABLE ROW LEVEL SECURITY;
1078
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.slack_user_links;
1079
+ CREATE POLICY analyst_tenant_isolation ON public.slack_user_links
1080
+ FOR SELECT TO analyst_reader
1081
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1082
+ ELSE
1083
+ missing := missing || 'slack_user_links'::text;
1084
+ END IF;
1085
+ IF to_regclass('public.space_checklist_items') IS NOT NULL THEN
1086
+ ALTER TABLE public.space_checklist_items ENABLE ROW LEVEL SECURITY;
1087
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.space_checklist_items;
1088
+ CREATE POLICY analyst_tenant_isolation ON public.space_checklist_items
1089
+ FOR SELECT TO analyst_reader
1090
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1091
+ ELSE
1092
+ missing := missing || 'space_checklist_items'::text;
1093
+ END IF;
1094
+ IF to_regclass('public.space_checklist_templates') IS NOT NULL THEN
1095
+ ALTER TABLE public.space_checklist_templates ENABLE ROW LEVEL SECURITY;
1096
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.space_checklist_templates;
1097
+ CREATE POLICY analyst_tenant_isolation ON public.space_checklist_templates
1098
+ FOR SELECT TO analyst_reader
1099
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1100
+ ELSE
1101
+ missing := missing || 'space_checklist_templates'::text;
1102
+ END IF;
1103
+ IF to_regclass('public.space_integrations') IS NOT NULL THEN
1104
+ ALTER TABLE public.space_integrations ENABLE ROW LEVEL SECURITY;
1105
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.space_integrations;
1106
+ CREATE POLICY analyst_tenant_isolation ON public.space_integrations
1107
+ FOR SELECT TO analyst_reader
1108
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1109
+ ELSE
1110
+ missing := missing || 'space_integrations'::text;
1111
+ END IF;
1112
+ IF to_regclass('public.space_knowledge_bases') IS NOT NULL THEN
1113
+ ALTER TABLE public.space_knowledge_bases ENABLE ROW LEVEL SECURITY;
1114
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.space_knowledge_bases;
1115
+ CREATE POLICY analyst_tenant_isolation ON public.space_knowledge_bases
1116
+ FOR SELECT TO analyst_reader
1117
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1118
+ ELSE
1119
+ missing := missing || 'space_knowledge_bases'::text;
1120
+ END IF;
1121
+ IF to_regclass('public.space_mcp_servers') IS NOT NULL THEN
1122
+ ALTER TABLE public.space_mcp_servers ENABLE ROW LEVEL SECURITY;
1123
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.space_mcp_servers;
1124
+ CREATE POLICY analyst_tenant_isolation ON public.space_mcp_servers
1125
+ FOR SELECT TO analyst_reader
1126
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1127
+ ELSE
1128
+ missing := missing || 'space_mcp_servers'::text;
1129
+ END IF;
1130
+ IF to_regclass('public.space_members') IS NOT NULL THEN
1131
+ ALTER TABLE public.space_members ENABLE ROW LEVEL SECURITY;
1132
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.space_members;
1133
+ CREATE POLICY analyst_tenant_isolation ON public.space_members
1134
+ FOR SELECT TO analyst_reader
1135
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1136
+ ELSE
1137
+ missing := missing || 'space_members'::text;
1138
+ END IF;
1139
+ IF to_regclass('public.spaces') IS NOT NULL THEN
1140
+ ALTER TABLE public.spaces ENABLE ROW LEVEL SECURITY;
1141
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.spaces;
1142
+ CREATE POLICY analyst_tenant_isolation ON public.spaces
1143
+ FOR SELECT TO analyst_reader
1144
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1145
+ ELSE
1146
+ missing := missing || 'spaces'::text;
1147
+ END IF;
1148
+ IF to_regclass('public.stripe_customers') IS NOT NULL THEN
1149
+ ALTER TABLE public.stripe_customers ENABLE ROW LEVEL SECURITY;
1150
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.stripe_customers;
1151
+ CREATE POLICY analyst_tenant_isolation ON public.stripe_customers
1152
+ FOR SELECT TO analyst_reader
1153
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1154
+ ELSE
1155
+ missing := missing || 'stripe_customers'::text;
1156
+ END IF;
1157
+ IF to_regclass('public.stripe_subscriptions') IS NOT NULL THEN
1158
+ ALTER TABLE public.stripe_subscriptions ENABLE ROW LEVEL SECURITY;
1159
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.stripe_subscriptions;
1160
+ CREATE POLICY analyst_tenant_isolation ON public.stripe_subscriptions
1161
+ FOR SELECT TO analyst_reader
1162
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1163
+ ELSE
1164
+ missing := missing || 'stripe_subscriptions'::text;
1165
+ END IF;
1166
+ IF to_regclass('public.tenant_builtin_tools') IS NOT NULL THEN
1167
+ ALTER TABLE public.tenant_builtin_tools ENABLE ROW LEVEL SECURITY;
1168
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.tenant_builtin_tools;
1169
+ CREATE POLICY analyst_tenant_isolation ON public.tenant_builtin_tools
1170
+ FOR SELECT TO analyst_reader
1171
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1172
+ ELSE
1173
+ missing := missing || 'tenant_builtin_tools'::text;
1174
+ END IF;
1175
+ IF to_regclass('public.tenant_context_provider_settings') IS NOT NULL THEN
1176
+ ALTER TABLE public.tenant_context_provider_settings ENABLE ROW LEVEL SECURITY;
1177
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.tenant_context_provider_settings;
1178
+ CREATE POLICY analyst_tenant_isolation ON public.tenant_context_provider_settings
1179
+ FOR SELECT TO analyst_reader
1180
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1181
+ ELSE
1182
+ missing := missing || 'tenant_context_provider_settings'::text;
1183
+ END IF;
1184
+ IF to_regclass('public.tenant_mcp_context_tools') IS NOT NULL THEN
1185
+ ALTER TABLE public.tenant_mcp_context_tools ENABLE ROW LEVEL SECURITY;
1186
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.tenant_mcp_context_tools;
1187
+ CREATE POLICY analyst_tenant_isolation ON public.tenant_mcp_context_tools
1188
+ FOR SELECT TO analyst_reader
1189
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1190
+ ELSE
1191
+ missing := missing || 'tenant_mcp_context_tools'::text;
1192
+ END IF;
1193
+ IF to_regclass('public.tenant_mcp_servers') IS NOT NULL THEN
1194
+ ALTER TABLE public.tenant_mcp_servers ENABLE ROW LEVEL SECURITY;
1195
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.tenant_mcp_servers;
1196
+ CREATE POLICY analyst_tenant_isolation ON public.tenant_mcp_servers
1197
+ FOR SELECT TO analyst_reader
1198
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1199
+ ELSE
1200
+ missing := missing || 'tenant_mcp_servers'::text;
1201
+ END IF;
1202
+ IF to_regclass('public.tenant_members') IS NOT NULL THEN
1203
+ ALTER TABLE public.tenant_members ENABLE ROW LEVEL SECURITY;
1204
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.tenant_members;
1205
+ CREATE POLICY analyst_tenant_isolation ON public.tenant_members
1206
+ FOR SELECT TO analyst_reader
1207
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1208
+ ELSE
1209
+ missing := missing || 'tenant_members'::text;
1210
+ END IF;
1211
+ IF to_regclass('public.tenant_model_catalog') IS NOT NULL THEN
1212
+ ALTER TABLE public.tenant_model_catalog ENABLE ROW LEVEL SECURITY;
1213
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.tenant_model_catalog;
1214
+ CREATE POLICY analyst_tenant_isolation ON public.tenant_model_catalog
1215
+ FOR SELECT TO analyst_reader
1216
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1217
+ ELSE
1218
+ missing := missing || 'tenant_model_catalog'::text;
1219
+ END IF;
1220
+ IF to_regclass('public.tenant_policy_events') IS NOT NULL THEN
1221
+ ALTER TABLE public.tenant_policy_events ENABLE ROW LEVEL SECURITY;
1222
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.tenant_policy_events;
1223
+ CREATE POLICY analyst_tenant_isolation ON public.tenant_policy_events
1224
+ FOR SELECT TO analyst_reader
1225
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1226
+ ELSE
1227
+ missing := missing || 'tenant_policy_events'::text;
1228
+ END IF;
1229
+ IF to_regclass('public.tenant_settings') IS NOT NULL THEN
1230
+ ALTER TABLE public.tenant_settings ENABLE ROW LEVEL SECURITY;
1231
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.tenant_settings;
1232
+ CREATE POLICY analyst_tenant_isolation ON public.tenant_settings
1233
+ FOR SELECT TO analyst_reader
1234
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1235
+ ELSE
1236
+ missing := missing || 'tenant_settings'::text;
1237
+ END IF;
1238
+ IF to_regclass('public.tenant_system_users') IS NOT NULL THEN
1239
+ ALTER TABLE public.tenant_system_users ENABLE ROW LEVEL SECURITY;
1240
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.tenant_system_users;
1241
+ CREATE POLICY analyst_tenant_isolation ON public.tenant_system_users
1242
+ FOR SELECT TO analyst_reader
1243
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1244
+ ELSE
1245
+ missing := missing || 'tenant_system_users'::text;
1246
+ END IF;
1247
+ IF to_regclass('public.tenant_workflow_catalog') IS NOT NULL THEN
1248
+ ALTER TABLE public.tenant_workflow_catalog ENABLE ROW LEVEL SECURITY;
1249
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.tenant_workflow_catalog;
1250
+ CREATE POLICY analyst_tenant_isolation ON public.tenant_workflow_catalog
1251
+ FOR SELECT TO analyst_reader
1252
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1253
+ ELSE
1254
+ missing := missing || 'tenant_workflow_catalog'::text;
1255
+ END IF;
1256
+ IF to_regclass('public.tenants') IS NOT NULL THEN
1257
+ ALTER TABLE public.tenants ENABLE ROW LEVEL SECURITY;
1258
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.tenants;
1259
+ CREATE POLICY analyst_tenant_isolation ON public.tenants
1260
+ FOR SELECT TO analyst_reader
1261
+ USING (id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1262
+ ELSE
1263
+ missing := missing || 'tenants'::text;
1264
+ END IF;
1265
+ IF to_regclass('public.thread_attachments') IS NOT NULL THEN
1266
+ ALTER TABLE public.thread_attachments ENABLE ROW LEVEL SECURITY;
1267
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.thread_attachments;
1268
+ CREATE POLICY analyst_tenant_isolation ON public.thread_attachments
1269
+ FOR SELECT TO analyst_reader
1270
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1271
+ ELSE
1272
+ missing := missing || 'thread_attachments'::text;
1273
+ END IF;
1274
+ IF to_regclass('public.thread_dependencies') IS NOT NULL THEN
1275
+ ALTER TABLE public.thread_dependencies ENABLE ROW LEVEL SECURITY;
1276
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.thread_dependencies;
1277
+ CREATE POLICY analyst_tenant_isolation ON public.thread_dependencies
1278
+ FOR SELECT TO analyst_reader
1279
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1280
+ ELSE
1281
+ missing := missing || 'thread_dependencies'::text;
1282
+ END IF;
1283
+ IF to_regclass('public.thread_idle_learning_runs') IS NOT NULL THEN
1284
+ ALTER TABLE public.thread_idle_learning_runs ENABLE ROW LEVEL SECURITY;
1285
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.thread_idle_learning_runs;
1286
+ CREATE POLICY analyst_tenant_isolation ON public.thread_idle_learning_runs
1287
+ FOR SELECT TO analyst_reader
1288
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1289
+ ELSE
1290
+ missing := missing || 'thread_idle_learning_runs'::text;
1291
+ END IF;
1292
+ IF to_regclass('public.thread_idle_learning_state') IS NOT NULL THEN
1293
+ ALTER TABLE public.thread_idle_learning_state ENABLE ROW LEVEL SECURITY;
1294
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.thread_idle_learning_state;
1295
+ CREATE POLICY analyst_tenant_isolation ON public.thread_idle_learning_state
1296
+ FOR SELECT TO analyst_reader
1297
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1298
+ ELSE
1299
+ missing := missing || 'thread_idle_learning_state'::text;
1300
+ END IF;
1301
+ IF to_regclass('public.thread_label_assignments') IS NOT NULL THEN
1302
+ ALTER TABLE public.thread_label_assignments ENABLE ROW LEVEL SECURITY;
1303
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.thread_label_assignments;
1304
+ CREATE POLICY analyst_tenant_isolation ON public.thread_label_assignments
1305
+ FOR SELECT TO analyst_reader
1306
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1307
+ ELSE
1308
+ missing := missing || 'thread_label_assignments'::text;
1309
+ END IF;
1310
+ IF to_regclass('public.thread_labels') IS NOT NULL THEN
1311
+ ALTER TABLE public.thread_labels ENABLE ROW LEVEL SECURITY;
1312
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.thread_labels;
1313
+ CREATE POLICY analyst_tenant_isolation ON public.thread_labels
1314
+ FOR SELECT TO analyst_reader
1315
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1316
+ ELSE
1317
+ missing := missing || 'thread_labels'::text;
1318
+ END IF;
1319
+ IF to_regclass('public.thread_participants') IS NOT NULL THEN
1320
+ ALTER TABLE public.thread_participants ENABLE ROW LEVEL SECURITY;
1321
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.thread_participants;
1322
+ CREATE POLICY analyst_tenant_isolation ON public.thread_participants
1323
+ FOR SELECT TO analyst_reader
1324
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1325
+ ELSE
1326
+ missing := missing || 'thread_participants'::text;
1327
+ END IF;
1328
+ IF to_regclass('public.thread_turn_events') IS NOT NULL THEN
1329
+ ALTER TABLE public.thread_turn_events ENABLE ROW LEVEL SECURITY;
1330
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.thread_turn_events;
1331
+ CREATE POLICY analyst_tenant_isolation ON public.thread_turn_events
1332
+ FOR SELECT TO analyst_reader
1333
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1334
+ ELSE
1335
+ missing := missing || 'thread_turn_events'::text;
1336
+ END IF;
1337
+ IF to_regclass('public.thread_turns') IS NOT NULL THEN
1338
+ ALTER TABLE public.thread_turns ENABLE ROW LEVEL SECURITY;
1339
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.thread_turns;
1340
+ CREATE POLICY analyst_tenant_isolation ON public.thread_turns
1341
+ FOR SELECT TO analyst_reader
1342
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1343
+ ELSE
1344
+ missing := missing || 'thread_turns'::text;
1345
+ END IF;
1346
+ IF to_regclass('public.threads') IS NOT NULL THEN
1347
+ ALTER TABLE public.threads ENABLE ROW LEVEL SECURITY;
1348
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.threads;
1349
+ CREATE POLICY analyst_tenant_isolation ON public.threads
1350
+ FOR SELECT TO analyst_reader
1351
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1352
+ ELSE
1353
+ missing := missing || 'threads'::text;
1354
+ END IF;
1355
+ IF to_regclass('public.trace_cost_reconciliation_facts') IS NOT NULL THEN
1356
+ ALTER TABLE public.trace_cost_reconciliation_facts ENABLE ROW LEVEL SECURITY;
1357
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.trace_cost_reconciliation_facts;
1358
+ CREATE POLICY analyst_tenant_isolation ON public.trace_cost_reconciliation_facts
1359
+ FOR SELECT TO analyst_reader
1360
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1361
+ ELSE
1362
+ missing := missing || 'trace_cost_reconciliation_facts'::text;
1363
+ END IF;
1364
+ IF to_regclass('public.trace_events') IS NOT NULL THEN
1365
+ ALTER TABLE public.trace_events ENABLE ROW LEVEL SECURITY;
1366
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.trace_events;
1367
+ CREATE POLICY analyst_tenant_isolation ON public.trace_events
1368
+ FOR SELECT TO analyst_reader
1369
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1370
+ ELSE
1371
+ missing := missing || 'trace_events'::text;
1372
+ END IF;
1373
+ IF to_regclass('public.trace_runs') IS NOT NULL THEN
1374
+ ALTER TABLE public.trace_runs ENABLE ROW LEVEL SECURITY;
1375
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.trace_runs;
1376
+ CREATE POLICY analyst_tenant_isolation ON public.trace_runs
1377
+ FOR SELECT TO analyst_reader
1378
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1379
+ ELSE
1380
+ missing := missing || 'trace_runs'::text;
1381
+ END IF;
1382
+ IF to_regclass('public.trace_source_evidence') IS NOT NULL THEN
1383
+ ALTER TABLE public.trace_source_evidence ENABLE ROW LEVEL SECURITY;
1384
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.trace_source_evidence;
1385
+ CREATE POLICY analyst_tenant_isolation ON public.trace_source_evidence
1386
+ FOR SELECT TO analyst_reader
1387
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1388
+ ELSE
1389
+ missing := missing || 'trace_source_evidence'::text;
1390
+ END IF;
1391
+ IF to_regclass('public.user_model_approvals') IS NOT NULL THEN
1392
+ ALTER TABLE public.user_model_approvals ENABLE ROW LEVEL SECURITY;
1393
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.user_model_approvals;
1394
+ CREATE POLICY analyst_tenant_isolation ON public.user_model_approvals
1395
+ FOR SELECT TO analyst_reader
1396
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1397
+ ELSE
1398
+ missing := missing || 'user_model_approvals'::text;
1399
+ END IF;
1400
+ IF to_regclass('public.user_plugin_activations') IS NOT NULL THEN
1401
+ ALTER TABLE public.user_plugin_activations ENABLE ROW LEVEL SECURITY;
1402
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.user_plugin_activations;
1403
+ CREATE POLICY analyst_tenant_isolation ON public.user_plugin_activations
1404
+ FOR SELECT TO analyst_reader
1405
+ USING (EXISTS (SELECT 1 FROM public.plugin_installs p WHERE p.id = public.user_plugin_activations.plugin_install_id AND p.tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid));
1406
+ ELSE
1407
+ missing := missing || 'user_plugin_activations'::text;
1408
+ END IF;
1409
+ IF to_regclass('public.user_profiles') IS NOT NULL THEN
1410
+ ALTER TABLE public.user_profiles ENABLE ROW LEVEL SECURITY;
1411
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.user_profiles;
1412
+ CREATE POLICY analyst_tenant_isolation ON public.user_profiles
1413
+ FOR SELECT TO analyst_reader
1414
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1415
+ ELSE
1416
+ missing := missing || 'user_profiles'::text;
1417
+ END IF;
1418
+ IF to_regclass('public.user_quick_actions') IS NOT NULL THEN
1419
+ ALTER TABLE public.user_quick_actions ENABLE ROW LEVEL SECURITY;
1420
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.user_quick_actions;
1421
+ CREATE POLICY analyst_tenant_isolation ON public.user_quick_actions
1422
+ FOR SELECT TO analyst_reader
1423
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1424
+ ELSE
1425
+ missing := missing || 'user_quick_actions'::text;
1426
+ END IF;
1427
+ IF to_regclass('public.users') IS NOT NULL THEN
1428
+ ALTER TABLE public.users ENABLE ROW LEVEL SECURITY;
1429
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.users;
1430
+ CREATE POLICY analyst_tenant_isolation ON public.users
1431
+ FOR SELECT TO analyst_reader
1432
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1433
+ ELSE
1434
+ missing := missing || 'users'::text;
1435
+ END IF;
1436
+ IF to_regclass('public.wakeup_requests') IS NOT NULL THEN
1437
+ ALTER TABLE public.wakeup_requests ENABLE ROW LEVEL SECURITY;
1438
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.wakeup_requests;
1439
+ CREATE POLICY analyst_tenant_isolation ON public.wakeup_requests
1440
+ FOR SELECT TO analyst_reader
1441
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1442
+ ELSE
1443
+ missing := missing || 'wakeup_requests'::text;
1444
+ END IF;
1445
+ IF to_regclass('public.work_item_comments') IS NOT NULL THEN
1446
+ ALTER TABLE public.work_item_comments ENABLE ROW LEVEL SECURITY;
1447
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.work_item_comments;
1448
+ CREATE POLICY analyst_tenant_isolation ON public.work_item_comments
1449
+ FOR SELECT TO analyst_reader
1450
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1451
+ ELSE
1452
+ missing := missing || 'work_item_comments'::text;
1453
+ END IF;
1454
+ IF to_regclass('public.work_item_documents') IS NOT NULL THEN
1455
+ ALTER TABLE public.work_item_documents ENABLE ROW LEVEL SECURITY;
1456
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.work_item_documents;
1457
+ CREATE POLICY analyst_tenant_isolation ON public.work_item_documents
1458
+ FOR SELECT TO analyst_reader
1459
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1460
+ ELSE
1461
+ missing := missing || 'work_item_documents'::text;
1462
+ END IF;
1463
+ IF to_regclass('public.work_item_events') IS NOT NULL THEN
1464
+ ALTER TABLE public.work_item_events ENABLE ROW LEVEL SECURITY;
1465
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.work_item_events;
1466
+ CREATE POLICY analyst_tenant_isolation ON public.work_item_events
1467
+ FOR SELECT TO analyst_reader
1468
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1469
+ ELSE
1470
+ missing := missing || 'work_item_events'::text;
1471
+ END IF;
1472
+ IF to_regclass('public.work_item_external_refs') IS NOT NULL THEN
1473
+ ALTER TABLE public.work_item_external_refs ENABLE ROW LEVEL SECURITY;
1474
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.work_item_external_refs;
1475
+ CREATE POLICY analyst_tenant_isolation ON public.work_item_external_refs
1476
+ FOR SELECT TO analyst_reader
1477
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1478
+ ELSE
1479
+ missing := missing || 'work_item_external_refs'::text;
1480
+ END IF;
1481
+ IF to_regclass('public.work_item_label_assignments') IS NOT NULL THEN
1482
+ ALTER TABLE public.work_item_label_assignments ENABLE ROW LEVEL SECURITY;
1483
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.work_item_label_assignments;
1484
+ CREATE POLICY analyst_tenant_isolation ON public.work_item_label_assignments
1485
+ FOR SELECT TO analyst_reader
1486
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1487
+ ELSE
1488
+ missing := missing || 'work_item_label_assignments'::text;
1489
+ END IF;
1490
+ IF to_regclass('public.work_item_labels') IS NOT NULL THEN
1491
+ ALTER TABLE public.work_item_labels ENABLE ROW LEVEL SECURITY;
1492
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.work_item_labels;
1493
+ CREATE POLICY analyst_tenant_isolation ON public.work_item_labels
1494
+ FOR SELECT TO analyst_reader
1495
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1496
+ ELSE
1497
+ missing := missing || 'work_item_labels'::text;
1498
+ END IF;
1499
+ IF to_regclass('public.work_item_saved_views') IS NOT NULL THEN
1500
+ ALTER TABLE public.work_item_saved_views ENABLE ROW LEVEL SECURITY;
1501
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.work_item_saved_views;
1502
+ CREATE POLICY analyst_tenant_isolation ON public.work_item_saved_views
1503
+ FOR SELECT TO analyst_reader
1504
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1505
+ ELSE
1506
+ missing := missing || 'work_item_saved_views'::text;
1507
+ END IF;
1508
+ IF to_regclass('public.work_item_statuses') IS NOT NULL THEN
1509
+ ALTER TABLE public.work_item_statuses ENABLE ROW LEVEL SECURITY;
1510
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.work_item_statuses;
1511
+ CREATE POLICY analyst_tenant_isolation ON public.work_item_statuses
1512
+ FOR SELECT TO analyst_reader
1513
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1514
+ ELSE
1515
+ missing := missing || 'work_item_statuses'::text;
1516
+ END IF;
1517
+ IF to_regclass('public.work_item_thread_links') IS NOT NULL THEN
1518
+ ALTER TABLE public.work_item_thread_links ENABLE ROW LEVEL SECURITY;
1519
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.work_item_thread_links;
1520
+ CREATE POLICY analyst_tenant_isolation ON public.work_item_thread_links
1521
+ FOR SELECT TO analyst_reader
1522
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1523
+ ELSE
1524
+ missing := missing || 'work_item_thread_links'::text;
1525
+ END IF;
1526
+ IF to_regclass('public.work_items') IS NOT NULL THEN
1527
+ ALTER TABLE public.work_items ENABLE ROW LEVEL SECURITY;
1528
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.work_items;
1529
+ CREATE POLICY analyst_tenant_isolation ON public.work_items
1530
+ FOR SELECT TO analyst_reader
1531
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1532
+ ELSE
1533
+ missing := missing || 'work_items'::text;
1534
+ END IF;
1535
+ IF to_regclass('public.workflow_configs') IS NOT NULL THEN
1536
+ ALTER TABLE public.workflow_configs ENABLE ROW LEVEL SECURITY;
1537
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.workflow_configs;
1538
+ CREATE POLICY analyst_tenant_isolation ON public.workflow_configs
1539
+ FOR SELECT TO analyst_reader
1540
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1541
+ ELSE
1542
+ missing := missing || 'workflow_configs'::text;
1543
+ END IF;
1544
+ IF to_regclass('public.workflow_engine_bindings') IS NOT NULL THEN
1545
+ ALTER TABLE public.workflow_engine_bindings ENABLE ROW LEVEL SECURITY;
1546
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.workflow_engine_bindings;
1547
+ CREATE POLICY analyst_tenant_isolation ON public.workflow_engine_bindings
1548
+ FOR SELECT TO analyst_reader
1549
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1550
+ ELSE
1551
+ missing := missing || 'workflow_engine_bindings'::text;
1552
+ END IF;
1553
+ IF to_regclass('public.workflow_evidence') IS NOT NULL THEN
1554
+ ALTER TABLE public.workflow_evidence ENABLE ROW LEVEL SECURITY;
1555
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.workflow_evidence;
1556
+ CREATE POLICY analyst_tenant_isolation ON public.workflow_evidence
1557
+ FOR SELECT TO analyst_reader
1558
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1559
+ ELSE
1560
+ missing := missing || 'workflow_evidence'::text;
1561
+ END IF;
1562
+ IF to_regclass('public.workflow_run_events') IS NOT NULL THEN
1563
+ ALTER TABLE public.workflow_run_events ENABLE ROW LEVEL SECURITY;
1564
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.workflow_run_events;
1565
+ CREATE POLICY analyst_tenant_isolation ON public.workflow_run_events
1566
+ FOR SELECT TO analyst_reader
1567
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1568
+ ELSE
1569
+ missing := missing || 'workflow_run_events'::text;
1570
+ END IF;
1571
+ IF to_regclass('public.workflow_runs') IS NOT NULL THEN
1572
+ ALTER TABLE public.workflow_runs ENABLE ROW LEVEL SECURITY;
1573
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.workflow_runs;
1574
+ CREATE POLICY analyst_tenant_isolation ON public.workflow_runs
1575
+ FOR SELECT TO analyst_reader
1576
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1577
+ ELSE
1578
+ missing := missing || 'workflow_runs'::text;
1579
+ END IF;
1580
+ IF to_regclass('public.workflow_triggers') IS NOT NULL THEN
1581
+ ALTER TABLE public.workflow_triggers ENABLE ROW LEVEL SECURITY;
1582
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.workflow_triggers;
1583
+ CREATE POLICY analyst_tenant_isolation ON public.workflow_triggers
1584
+ FOR SELECT TO analyst_reader
1585
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1586
+ ELSE
1587
+ missing := missing || 'workflow_triggers'::text;
1588
+ END IF;
1589
+ IF to_regclass('public.workflow_versions') IS NOT NULL THEN
1590
+ ALTER TABLE public.workflow_versions ENABLE ROW LEVEL SECURITY;
1591
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.workflow_versions;
1592
+ CREATE POLICY analyst_tenant_isolation ON public.workflow_versions
1593
+ FOR SELECT TO analyst_reader
1594
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1595
+ ELSE
1596
+ missing := missing || 'workflow_versions'::text;
1597
+ END IF;
1598
+ IF to_regclass('public.workflows') IS NOT NULL THEN
1599
+ ALTER TABLE public.workflows ENABLE ROW LEVEL SECURITY;
1600
+ DROP POLICY IF EXISTS analyst_tenant_isolation ON public.workflows;
1601
+ CREATE POLICY analyst_tenant_isolation ON public.workflows
1602
+ FOR SELECT TO analyst_reader
1603
+ USING (tenant_id = current_setting('thinkwork.analyst_tenant', true)::uuid);
1604
+ ELSE
1605
+ missing := missing || 'workflows'::text;
1606
+ END IF;
1607
+ IF array_length(missing, 1) > 0 THEN
1608
+ RAISE WARNING 'analyst RLS skipped for tables missing on this database: %', missing;
1609
+ END IF;
1610
+ END $$;
1611
+ -- END GENERATED ANALYST RLS
1612
+
1613
+ COMMIT;