|
| 1 | +-- Deploy: schemas/constructive_store_private/tables/platform_secrets/fixtures/standalone_compat |
| 2 | +-- made with <3 @ constructive.io |
| 3 | +-- |
| 4 | +-- Standalone compatibility patch for platform_secrets. |
| 5 | +-- |
| 6 | +-- In the monolith, database_id is set by provisioning triggers and the unique |
| 7 | +-- constraint evolves across migrations. The slicer extracts the final table |
| 8 | +-- state (UNIQUE on database_id, namespace_id, name) but the functions were |
| 9 | +-- generated for the earlier schema (UNIQUE on namespace_id, name only). |
| 10 | +-- |
| 11 | +-- This patch bridges the gap for standalone mode: |
| 12 | +-- 1. DEFAULT on database_id → filled from jwt_private.current_database_id() |
| 13 | +-- so INSERT without explicit database_id still populates it. |
| 14 | +-- 2. Unique index on (namespace_id, name) → matches the ON CONFLICT clause |
| 15 | +-- in the generated platform_secrets_set() function. |
| 16 | +-- |
| 17 | +-- Safe for standalone (single database_id). The upstream AST builders will |
| 18 | +-- eventually generate entity-aware functions that include database_id directly. |
| 19 | + |
| 20 | +BEGIN; |
| 21 | + |
| 22 | +-- 1. Set DEFAULT on database_id so INSERTs without it use the JWT claim |
| 23 | +ALTER TABLE constructive_store_private.platform_secrets |
| 24 | + ALTER COLUMN database_id SET DEFAULT jwt_private.current_database_id(); |
| 25 | + |
| 26 | +-- 2. Create unique index matching the ON CONFLICT (namespace_id, name) clause |
| 27 | +-- in the generated platform_secrets_set/del functions |
| 28 | +CREATE UNIQUE INDEX IF NOT EXISTS platform_secrets_namespace_id_name_idx |
| 29 | + ON constructive_store_private.platform_secrets (namespace_id, name); |
| 30 | + |
| 31 | +COMMIT; |
0 commit comments