gencow 0.1.184 → 0.1.185
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.
- package/package.json +1 -1
- package/runtime/server.mjs +76 -17
- package/runtime/server.mjs.map +2 -2
package/package.json
CHANGED
package/runtime/server.mjs
CHANGED
|
@@ -72126,6 +72126,34 @@ async function ensurePlatformRlsPolicies(params) {
|
|
|
72126
72126
|
if (!params.isPlatform)
|
|
72127
72127
|
return;
|
|
72128
72128
|
const logger3 = params.logger ?? console;
|
|
72129
|
+
if (params.reconcile === false) {
|
|
72130
|
+
const expectedValues = PLATFORM_RLS_TARGET_TABLES.map((_table, index) => `($${index * 2 + 1}::text, $${index * 2 + 2}::text)`).join(", ");
|
|
72131
|
+
const expectedParams = PLATFORM_RLS_TARGET_TABLES.flatMap((table) => [table.tableName, table.policyName]);
|
|
72132
|
+
const result2 = await params.rawSql(`SELECT expected.table_name,
|
|
72133
|
+
expected.policy_name,
|
|
72134
|
+
COALESCE(c.relrowsecurity, false) AS row_security,
|
|
72135
|
+
COALESCE(c.relforcerowsecurity, false) AS force_row_security,
|
|
72136
|
+
EXISTS (
|
|
72137
|
+
SELECT 1 FROM pg_policy p
|
|
72138
|
+
WHERE p.polrelid = c.oid AND p.polname = expected.policy_name
|
|
72139
|
+
) AS policy_exists
|
|
72140
|
+
FROM (VALUES ${expectedValues}) AS expected(table_name, policy_name)
|
|
72141
|
+
LEFT JOIN pg_namespace n ON n.nspname = 'public'
|
|
72142
|
+
LEFT JOIN pg_class c ON c.relnamespace = n.oid AND c.relname = expected.table_name`, expectedParams);
|
|
72143
|
+
const rows4 = Array.isArray(result2) ? result2 : [];
|
|
72144
|
+
const drifted = rows4.filter((row) => {
|
|
72145
|
+
if (!row || typeof row !== "object")
|
|
72146
|
+
return true;
|
|
72147
|
+
const state = row;
|
|
72148
|
+
return state.row_security !== true || state.force_row_security !== true || state.policy_exists !== true;
|
|
72149
|
+
});
|
|
72150
|
+
if (rows4.length !== PLATFORM_RLS_TARGET_TABLES.length || drifted.length > 0) {
|
|
72151
|
+
const names = drifted.map((row) => row && typeof row === "object" && typeof row.table_name === "string" ? row.table_name : "unknown").join(",");
|
|
72152
|
+
throw new Error(`PLATFORM_RLS_POLICY_DRIFT:${names || "catalog_incomplete"}`);
|
|
72153
|
+
}
|
|
72154
|
+
logger3.log(`[db] platform RLS policies verified for ${rows4.length} table(s)`);
|
|
72155
|
+
return;
|
|
72156
|
+
}
|
|
72129
72157
|
const existing = await listExistingPublicTables(params.rawSql);
|
|
72130
72158
|
const tables = PLATFORM_RLS_TARGET_TABLES.filter((table) => existing.has(table.tableName));
|
|
72131
72159
|
const missing = PLATFORM_RLS_TARGET_TABLES.filter((table) => !existing.has(table.tableName));
|
|
@@ -75492,17 +75520,35 @@ var init_server_platform_node_capacity_schema = __esm({
|
|
|
75492
75520
|
CONSTRAINT platform_node_capacity_audit_reason_check CHECK (char_length(reason) BETWEEN 10 AND 500),
|
|
75493
75521
|
CONSTRAINT platform_node_capacity_audit_outcome_check CHECK (outcome IN ('applied', 'pending', 'rejected', 'failed', 'noop'))
|
|
75494
75522
|
)`,
|
|
75495
|
-
`
|
|
75496
|
-
|
|
75497
|
-
|
|
75498
|
-
|
|
75499
|
-
|
|
75500
|
-
|
|
75523
|
+
`DO $$ BEGIN
|
|
75524
|
+
IF to_regclass('platform_node_capacity_audit_node_created_idx') IS NULL THEN
|
|
75525
|
+
CREATE INDEX platform_node_capacity_audit_node_created_idx
|
|
75526
|
+
ON platform_node_capacity_audit_events (node_id, created_at DESC);
|
|
75527
|
+
END IF;
|
|
75528
|
+
END $$`,
|
|
75529
|
+
`DO $bootstrap$ BEGIN
|
|
75530
|
+
IF to_regprocedure('_gencow_reject_capacity_audit_mutation()') IS NULL THEN
|
|
75531
|
+
EXECUTE $function$
|
|
75532
|
+
CREATE FUNCTION _gencow_reject_capacity_audit_mutation()
|
|
75533
|
+
RETURNS trigger LANGUAGE plpgsql AS $body$
|
|
75534
|
+
BEGIN
|
|
75535
|
+
RAISE EXCEPTION 'platform node capacity audit events are append-only';
|
|
75536
|
+
END $body$
|
|
75537
|
+
$function$;
|
|
75538
|
+
END IF;
|
|
75539
|
+
END $bootstrap$`,
|
|
75540
|
+
`DO $$ BEGIN
|
|
75541
|
+
IF NOT EXISTS (
|
|
75542
|
+
SELECT 1 FROM pg_trigger
|
|
75543
|
+
WHERE tgname = 'platform_node_capacity_audit_append_only'
|
|
75544
|
+
AND tgrelid = 'platform_node_capacity_audit_events'::regclass
|
|
75545
|
+
AND NOT tgisinternal
|
|
75546
|
+
) THEN
|
|
75547
|
+
CREATE TRIGGER platform_node_capacity_audit_append_only
|
|
75548
|
+
BEFORE UPDATE OR DELETE ON platform_node_capacity_audit_events
|
|
75549
|
+
FOR EACH ROW EXECUTE FUNCTION _gencow_reject_capacity_audit_mutation();
|
|
75550
|
+
END IF;
|
|
75501
75551
|
END $$`,
|
|
75502
|
-
`DROP TRIGGER IF EXISTS platform_node_capacity_audit_append_only ON platform_node_capacity_audit_events`,
|
|
75503
|
-
`CREATE TRIGGER platform_node_capacity_audit_append_only
|
|
75504
|
-
BEFORE UPDATE OR DELETE ON platform_node_capacity_audit_events
|
|
75505
|
-
FOR EACH ROW EXECUTE FUNCTION _gencow_reject_capacity_audit_mutation()`,
|
|
75506
75552
|
`CREATE TABLE IF NOT EXISTS platform_node_capacity_runtime_events (
|
|
75507
75553
|
event_id TEXT PRIMARY KEY,
|
|
75508
75554
|
node_id TEXT NOT NULL,
|
|
@@ -75518,13 +75564,24 @@ var init_server_platform_node_capacity_schema = __esm({
|
|
|
75518
75564
|
CONSTRAINT platform_node_capacity_runtime_event_unique
|
|
75519
75565
|
UNIQUE (node_id, running_desired_revision, outcome, reason_code)
|
|
75520
75566
|
)`,
|
|
75521
|
-
`
|
|
75522
|
-
|
|
75523
|
-
|
|
75524
|
-
|
|
75525
|
-
|
|
75526
|
-
|
|
75527
|
-
|
|
75567
|
+
`DO $$ BEGIN
|
|
75568
|
+
IF to_regclass('platform_node_capacity_runtime_node_created_idx') IS NULL THEN
|
|
75569
|
+
CREATE INDEX platform_node_capacity_runtime_node_created_idx
|
|
75570
|
+
ON platform_node_capacity_runtime_events (node_id, created_at DESC);
|
|
75571
|
+
END IF;
|
|
75572
|
+
END $$`,
|
|
75573
|
+
`DO $$ BEGIN
|
|
75574
|
+
IF NOT EXISTS (
|
|
75575
|
+
SELECT 1 FROM pg_trigger
|
|
75576
|
+
WHERE tgname = 'platform_node_capacity_runtime_append_only'
|
|
75577
|
+
AND tgrelid = 'platform_node_capacity_runtime_events'::regclass
|
|
75578
|
+
AND NOT tgisinternal
|
|
75579
|
+
) THEN
|
|
75580
|
+
CREATE TRIGGER platform_node_capacity_runtime_append_only
|
|
75581
|
+
BEFORE UPDATE OR DELETE ON platform_node_capacity_runtime_events
|
|
75582
|
+
FOR EACH ROW EXECUTE FUNCTION _gencow_reject_capacity_audit_mutation();
|
|
75583
|
+
END IF;
|
|
75584
|
+
END $$`
|
|
75528
75585
|
];
|
|
75529
75586
|
}
|
|
75530
75587
|
});
|
|
@@ -76133,6 +76190,7 @@ async function ensurePlatformSchemaUpgrade(params) {
|
|
|
76133
76190
|
await ensurePlatformRlsPolicies({
|
|
76134
76191
|
rawSql: params.rawSql,
|
|
76135
76192
|
isPlatform: params.isPlatform,
|
|
76193
|
+
reconcile: params.reconcileRls !== false,
|
|
76136
76194
|
logger: logger3
|
|
76137
76195
|
});
|
|
76138
76196
|
}
|
|
@@ -117330,6 +117388,7 @@ async function bootstrapRuntimeSystemSchemas(params) {
|
|
|
117330
117388
|
await schemaBootstrap.ensurePlatformSchemaUpgrade({
|
|
117331
117389
|
rawSql: params.rawSql,
|
|
117332
117390
|
isPlatform: params.isPlatform,
|
|
117391
|
+
reconcileRls: false,
|
|
117333
117392
|
logger: logger3
|
|
117334
117393
|
});
|
|
117335
117394
|
if (params.isPlatform) {
|