Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- Deploy: schemas/constructive_store_private/tables/platform_secrets/fixtures/standalone_compat
-- made with <3 @ constructive.io
--
-- Standalone compatibility patch for platform_secrets.
--
-- In the monolith, database_id is set by provisioning triggers and the unique
-- constraint evolves across migrations. The slicer extracts the final table
-- state (UNIQUE on database_id, namespace_id, name) but the functions were
-- generated for the earlier schema (UNIQUE on namespace_id, name only).
--
-- This patch bridges the gap for standalone mode:
-- 1. DEFAULT on database_id → filled from jwt_private.current_database_id()
-- so INSERT without explicit database_id still populates it.
-- 2. Unique index on (namespace_id, name) → matches the ON CONFLICT clause
-- in the generated platform_secrets_set() function.
--
-- Safe for standalone (single database_id). The upstream AST builders will
-- eventually generate entity-aware functions that include database_id directly.

BEGIN;

-- 1. Set DEFAULT on database_id so INSERTs without it use the JWT claim
ALTER TABLE constructive_store_private.platform_secrets
ALTER COLUMN database_id SET DEFAULT jwt_private.current_database_id();

-- 2. Create unique index matching the ON CONFLICT (namespace_id, name) clause
-- in the generated platform_secrets_set/del functions
CREATE UNIQUE INDEX IF NOT EXISTS platform_secrets_namespace_id_name_idx
ON constructive_store_private.platform_secrets (namespace_id, name);

COMMIT;
1 change: 1 addition & 0 deletions pgpm/constructive-infra-seed/pgpm.plan
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
schemas/constructive_infra_public/partitions/create_default_partitions 2017-08-11T08:11:51Z Constructive <developers@constructive.io> # create default partitions for range-partitioned tables
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
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
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 number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Revert: schemas/constructive_store_private/tables/platform_secrets/fixtures/standalone_compat
-- made with <3 @ constructive.io

BEGIN;

DROP INDEX IF EXISTS constructive_store_private.platform_secrets_namespace_id_name_idx;

ALTER TABLE constructive_store_private.platform_secrets
ALTER COLUMN database_id DROP DEFAULT;

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Verify: schemas/constructive_store_private/tables/platform_secrets/fixtures/standalone_compat
-- made with <3 @ constructive.io

BEGIN;

SELECT 1 FROM pg_catalog.pg_indexes
WHERE schemaname = 'constructive_store_private'
AND tablename = 'platform_secrets'
AND indexname = 'platform_secrets_namespace_id_name_idx';

ROLLBACK;
2 changes: 1 addition & 1 deletion scripts/setup-platform-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ echo "→ Deploying constructive-infra..."
cd "$ROOT_DIR/pgpm"
pgpm deploy --yes --database "$DB_NAME" --package constructive-infra

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

Expand Down