Skip to content

Commit c7df5da

Browse files
authored
Merge pull request #61 from constructive-io/feat/standalone-secrets-compat
fix: standalone compat for platform_secrets ON CONFLICT
2 parents 06c93f7 + 0d5f095 commit c7df5da

5 files changed

Lines changed: 55 additions & 1 deletion

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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;

pgpm/constructive-infra-seed/pgpm.plan

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
schemas/constructive_infra_public/partitions/create_default_partitions 2017-08-11T08:11:51Z Constructive <developers@constructive.io> # create default partitions for range-partitioned tables
66
schemas/constructive_infra_public/tables/platform_namespaces/fixtures/seed_default_namespace [schemas/constructive_infra_public/partitions/create_default_partitions] 2017-08-11T08:11:51Z Constructive <developers@constructive.io> # seed default platform namespace
77
schemas/constructive_infra_public/tables/platform_function_definitions/fixtures/seed_built_in_functions [schemas/constructive_infra_public/tables/platform_namespaces/fixtures/seed_default_namespace] 2017-08-11T08:11:51Z Constructive <developers@constructive.io> # seed built-in platform functions with required_secrets and namespace
8+
schemas/constructive_store_private/tables/platform_secrets/fixtures/standalone_compat [schemas/constructive_infra_public/tables/platform_namespaces/fixtures/seed_default_namespace] 2017-08-11T08:11:51Z Constructive <developers@constructive.io> # standalone compat: DEFAULT database_id from JWT + unique index for ON CONFLICT
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Revert: schemas/constructive_store_private/tables/platform_secrets/fixtures/standalone_compat
2+
-- made with <3 @ constructive.io
3+
4+
BEGIN;
5+
6+
DROP INDEX IF EXISTS constructive_store_private.platform_secrets_namespace_id_name_idx;
7+
8+
ALTER TABLE constructive_store_private.platform_secrets
9+
ALTER COLUMN database_id DROP DEFAULT;
10+
11+
COMMIT;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Verify: schemas/constructive_store_private/tables/platform_secrets/fixtures/standalone_compat
2+
-- made with <3 @ constructive.io
3+
4+
BEGIN;
5+
6+
SELECT 1 FROM pg_catalog.pg_indexes
7+
WHERE schemaname = 'constructive_store_private'
8+
AND tablename = 'platform_secrets'
9+
AND indexname = 'platform_secrets_namespace_id_name_idx';
10+
11+
ROLLBACK;

scripts/setup-platform-db.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ echo "→ Deploying constructive-infra..."
3636
cd "$ROOT_DIR/pgpm"
3737
pgpm deploy --yes --database "$DB_NAME" --package constructive-infra
3838

39-
# --- Deploy constructive-infra-seed (built-in function definitions) ---
39+
# --- Deploy constructive-infra-seed (built-in function definitions + compat patches) ---
4040
echo "→ Deploying constructive-infra-seed..."
4141
pgpm deploy --yes --database "$DB_NAME" --package constructive-infra-seed
4242

0 commit comments

Comments
 (0)