@prisma/orm-target-postgres 8.0.0-rc.9-dev.5 → 8.0.0-rc.9-dev.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"diff-database-schema-B27W13mM-DmRNUFyg.mjs","names":[],"sources":["../../../../3-targets/3-targets/postgres/dist/diff-database-schema-B27W13mM.mjs"],"sourcesContent":["import { s as postgresError } from \"./errors-DYyzTYzE.mjs\";\nimport { n as postgresResolveDefault } from \"./default-normalizer-Ba5ZebHM.mjs\";\nimport { r as isPostgresSchema } from \"./postgres-schema-B3t7Zr52.mjs\";\nimport { a as postgresDiffSubjectGranularity, n as PostgresNativeEnumSchemaNode, r as PostgresSchemaNodeKind, t as PostgresTableSchemaNode } from \"./postgres-table-schema-node-BBkitBQh.mjs\";\nimport { i as PostgresDatabaseSchemaNode, n as PostgresPolicySchemaNode, r as PostgresNamespaceSchemaNode, t as PostgresRoleSchemaNode } from \"./postgres-role-schema-node-B8Z5i5D-.mjs\";\nimport { t as resolveDdlSchemaForNamespaceStorage } from \"./resolve-ddl-schema-Cab6g5MC.mjs\";\nimport { i as resolvePostgresNodeIssueControlPolicySubject } from \"./control-policy-HgW6zNnz.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { UNBOUND_NAMESPACE_ID } from \"@internal/framework-components/ir\";\nimport { buildNativeTypeExpander, contractNamespaceToSchemaIR } from \"@internal/family-sql/control\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { namingOf } from \"@internal/sql-schema-ir/naming\";\nimport { PrimaryKey, RelationalSchemaNodeKind, SqlForeignKeyIR, SqlIndexIR, SqlUniqueIR } from \"@internal/sql-schema-ir/types\";\nimport { classifyDiffSubjectGranularity } from \"@internal/family-sql/diff\";\nimport { diffSchemas, issueOutcome } from \"@internal/framework-components/control\";\n//#region src/core/migrations/contract-to-postgres-database-schema-node.ts\n/** The database root's fixed sentinel id (`PostgresDatabaseSchemaNode#id`). */\nfunction databaseStep() {\n\treturn {\n\t\tnodeKind: PostgresSchemaNodeKind.database,\n\t\tid: \"database\"\n\t};\n}\nfunction tableDependsOn(namespaceId, tableName) {\n\treturn [\n\t\tdatabaseStep(),\n\t\t{\n\t\t\tnodeKind: PostgresSchemaNodeKind.namespace,\n\t\t\tid: namespaceId\n\t\t},\n\t\t{\n\t\t\tnodeKind: PostgresSchemaNodeKind.table,\n\t\t\tid: tableName\n\t\t}\n\t];\n}\nfunction roleDependsOn(role) {\n\treturn [databaseStep(), {\n\t\tnodeKind: PostgresSchemaNodeKind.role,\n\t\tid: role\n\t}];\n}\n/**\n* The chains from a table-child object (foreign key, index, unique, primary\n* key) to each of the own columns it is built on, in the Postgres tree.\n* Dropping a covered column auto-drops the object, so the object's drop must\n* precede the column's; the graph derives that direction from these edges.\n*/\nfunction columnDependsOn(namespaceId, tableName, columns) {\n\treturn columns.map((column) => [...tableDependsOn(namespaceId, tableName), {\n\t\tnodeKind: RelationalSchemaNodeKind.column,\n\t\tid: `column:${column}`\n\t}]);\n}\nfunction toPolicyNode(policy, namespaceId) {\n\treturn new PostgresPolicySchemaNode({\n\t\tnaming: namingOf(policy.name, policy.prefix),\n\t\ttableName: policy.tableName,\n\t\tnamespaceId,\n\t\toperation: policy.operation,\n\t\troles: [...policy.roles],\n\t\tusing: policy.using,\n\t\twithCheck: policy.withCheck,\n\t\tpermissive: policy.permissive,\n\t\tdependsOn: [tableDependsOn(namespaceId, policy.tableName), ...policy.roles.map(roleDependsOn)]\n\t});\n}\n/**\n* Projects a Postgres contract into the expected schema-diff tree: a\n* `PostgresDatabaseSchemaNode` root holding one `PostgresNamespaceSchemaNode`\n* per Postgres namespace, each holding its `PostgresTableSchemaNode`s with\n* their `PostgresPolicySchemaNode`s, plus the database roles on the root.\n*\n* Not a duplicate of the family's `contractToSchemaIR`: that builds a flat,\n* single `{ tables }` map (and throws on cross-namespace name collisions, with\n* no RLS/role concept) for SQLite's single-schema world. This is the\n* Postgres-specific *tree* shape — multi-schema, RLS-policy-aware, role-aware.\n* It reuses the family's per-namespace table conversion (`contractNamespaceToSchemaIR`)\n* for column/FK/index building and only adds the Postgres tree/policy/role shape.\n*\n* Tables are grouped by their owning namespace (resolved DDL schema name) so\n* the tree mirrors Postgres's object hierarchy. The DDL schema name is\n* resolved once per namespace.\n*\n* A policy that references a table absent from its namespace is a malformed\n* contract — the loop throws rather than fabricating a stub table.\n*/\nfunction contractToPostgresDatabaseSchemaNode(contract, options) {\n\tif (contract === null) return new PostgresDatabaseSchemaNode({\n\t\tnamespaces: {},\n\t\troles: [],\n\t\texistingSchemas: [],\n\t\tpgVersion: \"\"\n\t});\n\tconst namespaces = {};\n\tconst roles = [];\n\tconst ownedSchemas = [];\n\tfor (const ns of Object.values(contract.storage.namespaces)) {\n\t\tif (!isPostgresSchema(ns)) continue;\n\t\tfor (const role of Object.values(ns.role)) roles.push(new PostgresRoleSchemaNode({\n\t\t\tname: role.name,\n\t\t\tnamespaceId: role.namespaceId\n\t\t}));\n\t\tif (ns.id === UNBOUND_NAMESPACE_ID) {\n\t\t\tif (!Object.entries(ns.entries).some(([entriesKey, slot]) => entriesKey !== \"role\" && Object.keys(slot).length > 0)) continue;\n\t\t}\n\t\tconst ddlSchema = resolveDdlSchemaForNamespaceStorage(contract.storage, ns.id);\n\t\townedSchemas.push(ddlSchema);\n\t\tconst sqlTables = contractNamespaceToSchemaIR(contract.storage, ns.id, options).tables;\n\t\tconst policiesByTable = /* @__PURE__ */ new Map();\n\t\tfor (const policy of Object.values(ns.policy)) {\n\t\t\tconst list = policiesByTable.get(policy.tableName) ?? [];\n\t\t\tlist.push(toPolicyNode(policy, ddlSchema));\n\t\t\tpoliciesByTable.set(policy.tableName, list);\n\t\t}\n\t\tconst tables = {};\n\t\tfor (const tableName of Object.keys(ns.table)) {\n\t\t\tconst sqlTable = sqlTables[tableName];\n\t\t\tif (sqlTable === void 0) continue;\n\t\t\tconst foreignKeys = sqlTable.foreignKeys.map((fk) => {\n\t\t\t\tconst resolvedReferencedNamespace = resolveDdlSchemaForNamespaceStorage(contract.storage, fk.referencedSchema ?? UNBOUND_NAMESPACE_ID);\n\t\t\t\treturn new SqlForeignKeyIR({\n\t\t\t\t\tcolumns: fk.columns,\n\t\t\t\t\treferencedTable: fk.referencedTable,\n\t\t\t\t\treferencedColumns: fk.referencedColumns,\n\t\t\t\t\treferencedSchema: fk.referencedSchema ?? UNBOUND_NAMESPACE_ID,\n\t\t\t\t\t...ifDefined(\"name\", fk.name),\n\t\t\t\t\t...ifDefined(\"onDelete\", fk.onDelete),\n\t\t\t\t\t...ifDefined(\"onUpdate\", fk.onUpdate),\n\t\t\t\t\t...ifDefined(\"annotations\", fk.annotations),\n\t\t\t\t\tresolvedReferencedNamespace,\n\t\t\t\t\tdependsOn: [tableDependsOn(resolvedReferencedNamespace, fk.referencedTable), ...columnDependsOn(ddlSchema, tableName, fk.columns)]\n\t\t\t\t});\n\t\t\t});\n\t\t\tconst uniques = sqlTable.uniques.map((u) => new SqlUniqueIR({\n\t\t\t\tcolumns: u.columns,\n\t\t\t\t...ifDefined(\"name\", u.name),\n\t\t\t\t...ifDefined(\"annotations\", u.annotations),\n\t\t\t\tdependsOn: columnDependsOn(ddlSchema, tableName, u.columns)\n\t\t\t}));\n\t\t\tconst indexes = sqlTable.indexes.map((i) => {\n\t\t\t\tconst base = {\n\t\t\t\t\tnaming: namingOf(i.name, i.prefix),\n\t\t\t\t\twhere: i.where,\n\t\t\t\t\tunique: i.unique,\n\t\t\t\t\tpartial: i.partial,\n\t\t\t\t\ttype: i.type,\n\t\t\t\t\toptions: i.options,\n\t\t\t\t\tannotations: i.annotations,\n\t\t\t\t\tdependsOn: columnDependsOn(ddlSchema, tableName, i.columns ?? Object.keys(sqlTable.columns))\n\t\t\t\t};\n\t\t\t\treturn new SqlIndexIR(i.expression !== void 0 ? {\n\t\t\t\t\t...base,\n\t\t\t\t\texpression: i.expression\n\t\t\t\t} : {\n\t\t\t\t\t...base,\n\t\t\t\t\tcolumns: i.columns ?? []\n\t\t\t\t});\n\t\t\t});\n\t\t\tconst primaryKey = sqlTable.primaryKey !== void 0 ? new PrimaryKey({\n\t\t\t\tcolumns: sqlTable.primaryKey.columns,\n\t\t\t\t...ifDefined(\"name\", sqlTable.primaryKey.name),\n\t\t\t\tdependsOn: columnDependsOn(ddlSchema, tableName, sqlTable.primaryKey.columns)\n\t\t\t}) : void 0;\n\t\t\ttables[tableName] = new PostgresTableSchemaNode({\n\t\t\t\tname: sqlTable.name,\n\t\t\t\tcolumns: sqlTable.columns,\n\t\t\t\tforeignKeys,\n\t\t\t\tuniques,\n\t\t\t\tindexes,\n\t\t\t\t...ifDefined(\"primaryKey\", primaryKey),\n\t\t\t\t...ifDefined(\"annotations\", sqlTable.annotations),\n\t\t\t\t...ifDefined(\"checks\", sqlTable.checks),\n\t\t\t\tpolicies: policiesByTable.get(tableName) ?? [],\n\t\t\t\trlsEnabled: Object.hasOwn(ns.rls, tableName)\n\t\t\t});\n\t\t}\n\t\tfor (const [tableName, tablePolicies] of policiesByTable) {\n\t\t\tif (!(tableName in tables)) {\n\t\t\t\tconst policyName = tablePolicies[0]?.name ?? \"(unknown)\";\n\t\t\t\tthrow postgresError(\"CONTRACT.POLICY_INVALID\", `contract-to-postgres-database-schema-node: policy \"${policyName}\" references table \"${tableName}\" not present in namespace \"${ddlSchema}\"`, { meta: {\n\t\t\t\t\tpolicyName,\n\t\t\t\t\ttableName,\n\t\t\t\t\tnamespaceId: ddlSchema,\n\t\t\t\t\treason: \"table-missing\"\n\t\t\t\t} });\n\t\t\t}\n\t\t\tif (!Object.hasOwn(ns.rls, tableName)) {\n\t\t\t\tconst policyLabel = tablePolicies[0]?.prefix ?? tablePolicies[0]?.name ?? \"(unknown)\";\n\t\t\t\tthrow postgresError(\"CONTRACT.POLICY_INVALID\", `contract-to-postgres-database-schema-node: policy \"${policyLabel}\" targets table \"${tableName}\" in namespace \"${ddlSchema}\", which is not RLS-controlled. Mark the model with @@rls (entries.rls[\"${tableName}\"]) or remove the policy.`, { meta: {\n\t\t\t\t\tpolicyName: policyLabel,\n\t\t\t\t\ttableName,\n\t\t\t\t\tnamespaceId: ddlSchema,\n\t\t\t\t\treason: \"table-not-rls-controlled\"\n\t\t\t\t} });\n\t\t\t}\n\t\t}\n\t\tnamespaces[ddlSchema] = new PostgresNamespaceSchemaNode({\n\t\t\tschemaName: ddlSchema,\n\t\t\ttables,\n\t\t\tnativeEnums: Object.values(ns.entries.native_enum ?? {}).map((entity) => new PostgresNativeEnumSchemaNode({\n\t\t\t\ttypeName: entity.typeName,\n\t\t\t\tnamespaceId: ddlSchema,\n\t\t\t\tmembers: entity.members,\n\t\t\t\t...ifDefined(\"control\", entity.control)\n\t\t\t}))\n\t\t});\n\t}\n\treturn new PostgresDatabaseSchemaNode({\n\t\tnamespaces,\n\t\troles,\n\t\texistingSchemas: ownedSchemas,\n\t\tpgVersion: \"\"\n\t});\n}\n//#endregion\n//#region src/core/migrations/diff-database-schema.ts\n/**\n* Whether a diff issue's subject node is cluster-scoped — it carries its own\n* `namespaceId` field (only role and policy diff nodes do) and that\n* coordinate is the unbound sentinel, meaning the node is not owned by any\n* schema/namespace. A role node is always cluster-scoped (roles are\n* cluster-level objects); a policy node's `namespaceId` is always its\n* table's resolved DDL schema, never the sentinel. Namespace-ownership\n* scoping (which compares `issue.path[1]` against the set of DDL schemas\n* the contract owns) makes no sense for a cluster-scoped subject — its path\n* segment at that index is the object's own name, not a schema name — so\n* such an issue bypasses that scoping entirely.\n*/\nfunction isClusterScopedIssue(issue) {\n\tconst node = issue.expected ?? issue.actual;\n\treturn node !== void 0 && nodeNamespaceId(node) === UNBOUND_NAMESPACE_ID;\n}\nfunction nodeNamespaceId(node) {\n\tif (!Object.hasOwn(node, \"namespaceId\")) return void 0;\n\treturn blindCast(node).namespaceId;\n}\nfunction ownedSchemaNames(expected) {\n\tconst policyNamespaces = Object.values(expected.namespaces).flatMap((ns) => Object.values(ns.tables).flatMap((t) => t.policies.map((p) => p.namespaceId)));\n\treturn /* @__PURE__ */ new Set([...policyNamespaces, ...expected.existingSchemas]);\n}\n/**\n* Drops contract namespaces that declare no tables from the verdict-diff\n* expected tree and the relational owned-schema set. The legacy relational\n* walk skipped a table-less namespace (e.g. an enums-only schema) before\n* pairing, so neither its DDL schema's absence nor that schema's live\n* relational contents ever reached the verdict — the pruned tree\n* reproduces that. The prune loses no expected policies: policies attach\n* to tables, so a table-less namespace carries none (the projection\n* throws on a policy referencing an absent table). Live policies in a\n* pruned schema remain governed via the full owned set (see\n* {@link diffPostgresSchema}).\n*/\nfunction pruneTableLessNamespaces(expected) {\n\tconst namespaces = Object.fromEntries(Object.entries(expected.namespaces).filter(([, ns]) => Object.keys(ns.tables).length > 0));\n\treturn new PostgresDatabaseSchemaNode({\n\t\tnamespaces,\n\t\troles: [...expected.roles],\n\t\texistingSchemas: expected.existingSchemas.filter((s) => namespaces[s] !== void 0),\n\t\tpgVersion: expected.pgVersion\n\t});\n}\n/**\n* Resolves a verdict-diff issue's subject's declared control policy directly\n* from the contract, by delegating to the same node-typed resolver\n* ({@link resolvePostgresNodeIssueControlPolicySubject}) the planner uses to\n* gate DDL calls. `undefined` when the issue resolves to no contract subject.\n*\n* A role issue resolves through that same resolver to `external`\n* unconditionally (see its role branch), regardless of the contract's own\n* default policy: a role is referenced by the contract but not owned, and\n* `external`'s existing semantics — a missing declared subject still fails,\n* every extra is suppressed — are exactly the wanted asymmetric grading for\n* a cluster object the framework does not own.\n*/\nfunction resolveControlPolicy(issue, contract) {\n\treturn resolvePostgresNodeIssueControlPolicySubject(blindCast(issue), contract)?.explicitNodeControlPolicy;\n}\n/**\n* The Postgres full-tree node diff for the family verify verdict: derive\n* the expected tree (resolved leaf values, expander threaded, FK schemas\n* resolved, table-less namespaces pruned), run the generic\n* differ over the trees as derived, and scope out `not-expected` findings under namespaces the\n* contract does not own. Ownership scoping bypasses cluster-scoped subjects\n* (roles today), mirroring the legacy decomposition: relational extras check\n* the PRUNED owned set (the legacy\n* per-namespace walk never visited a table-less namespace, so its live\n* relational contents are invisible), while `structural` extras (RLS\n* policies) check the FULL owned set (the legacy policy diff governed\n* every contract schema regardless of tables — RLS governance does not\n* shrink because a namespace declares no tables). The codec `verifyType`\n* hooks run once per contract namespace with tables against that\n* namespace's paired actual node (the hooks read namespace-scoped state\n* such as `nativeEnums`).\n*/\nfunction diffPostgresSchema(input) {\n\tconst postgresContract = blindCast(input.contract);\n\tPostgresDatabaseSchemaNode.assert(input.schema);\n\tconst actual = input.schema;\n\tconst fullExpected = contractToPostgresDatabaseSchemaNode(postgresContract, {\n\t\tannotationNamespace: \"pg\",\n\t\t...ifDefined(\"expandNativeType\", buildNativeTypeExpander(input.frameworkComponents)),\n\t\tresolveDefault: postgresResolveDefault\n\t});\n\tconst expected = pruneTableLessNamespaces(fullExpected);\n\tconst relationalOwned = ownedSchemaNames(expected);\n\tconst structuralOwned = ownedSchemaNames(fullExpected);\n\treturn {\n\t\tissues: diffSchemas(expected, actual).filter((issue) => {\n\t\t\tif (issueOutcome(issue) !== \"not-expected\") return true;\n\t\t\tif (isClusterScopedIssue(issue)) return true;\n\t\t\tconst granularity = classifyDiffSubjectGranularity(issue, postgresDiffSubjectGranularity);\n\t\t\tconst namespaceSegment = issue.path[1];\n\t\t\tif (namespaceSegment === void 0) return true;\n\t\t\treturn (granularity === \"structural\" ? structuralOwned : relationalOwned).has(namespaceSegment);\n\t\t}),\n\t\tresolveControlPolicy: (issue) => resolveControlPolicy(issue, postgresContract),\n\t\tnamespacePairs: Object.values(expected.namespaces).map((ns) => ({ actual: actual.namespaces[ns.schemaName] }))\n\t};\n}\n/**\n* Adds an empty namespace node to the actual tree for every expected namespace\n* absent from it. The relational plan diff pairs on namespace: a contract\n* namespace whose live schema does not exist yet must surface each of its\n* tables as `not-found` (→ `CREATE TABLE`), NOT as a single namespace\n* `not-found` that subtree-coalescing would collapse (leaving `CREATE SCHEMA`\n* with no tables). Padding makes the namespaces pair, so only table/column/\n* policy drift surfaces; `CREATE SCHEMA` comes separately from the synthesized\n* namespace-presence stitch (`verifyPostgresNamespacePresence`), never from the\n* tree diff — matching the retired per-namespace-paired relational walk, which\n* paired a missing schema against an empty namespace node.\n*/\nfunction padActualNamespaces(expected, actual) {\n\tconst namespaces = { ...actual.namespaces };\n\tlet padded = false;\n\tfor (const schemaName of Object.keys(expected.namespaces)) if (namespaces[schemaName] === void 0) {\n\t\tnamespaces[schemaName] = new PostgresNamespaceSchemaNode({\n\t\t\tschemaName,\n\t\t\ttables: {}\n\t\t});\n\t\tpadded = true;\n\t}\n\tif (!padded) return actual;\n\treturn new PostgresDatabaseSchemaNode({\n\t\tnamespaces,\n\t\troles: [...actual.roles],\n\t\texistingSchemas: [...actual.existingSchemas],\n\t\tpgVersion: actual.pgVersion\n\t});\n}\n/**\n* The Postgres planner's diff input: the SAME tree-building\n* `diffPostgresSchema` uses (expander threaded, FK schemas resolved,\n* table-less namespaces pruned, cluster-scope-aware ownership filter) plus\n* actual namespace padding (so a missing\n* schema's tables surface as `not-found` instead of a swallowed namespace\n* `not-found`). One differ drives both verify and plan; this is the\n* plan-side derivation. The single issue list covers tables / columns /\n* constraints / indexes / defaults AND policies — the caller splits it\n* (relational → `mapNodeIssueToCall`; policy → RLS ops) and stitches in\n* `CREATE SCHEMA` separately.\n*/\nfunction buildPostgresPlanDiff(input) {\n\tconst postgresContract = blindCast(input.contract);\n\tPostgresDatabaseSchemaNode.assert(input.actualSchema);\n\tconst actual = input.actualSchema;\n\tconst fullExpected = contractToPostgresDatabaseSchemaNode(postgresContract, {\n\t\tannotationNamespace: \"pg\",\n\t\t...ifDefined(\"expandNativeType\", buildNativeTypeExpander(input.frameworkComponents)),\n\t\tresolveDefault: postgresResolveDefault\n\t});\n\tconst expected = pruneTableLessNamespaces(fullExpected);\n\tconst paddedActual = padActualNamespaces(expected, actual);\n\tconst relationalOwned = ownedSchemaNames(expected);\n\tconst structuralOwned = ownedSchemaNames(fullExpected);\n\treturn {\n\t\texpected,\n\t\tactual: paddedActual,\n\t\tissues: blindCast(diffSchemas(expected, paddedActual)).filter((issue) => {\n\t\t\tif (issueOutcome(issue) !== \"not-expected\") return true;\n\t\t\tif (isClusterScopedIssue(issue)) return true;\n\t\t\tconst granularity = classifyDiffSubjectGranularity(issue, postgresDiffSubjectGranularity);\n\t\t\tconst namespaceSegment = issue.path[1];\n\t\t\tif (namespaceSegment === void 0) return true;\n\t\t\treturn (granularity === \"structural\" ? structuralOwned : relationalOwned).has(namespaceSegment);\n\t\t})\n\t};\n}\n//#endregion\nexport { diffPostgresSchema as n, contractToPostgresDatabaseSchemaNode as r, buildPostgresPlanDiff as t };\n\n//# sourceMappingURL=diff-database-schema-B27W13mM.mjs.map"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAS,eAAe;CACvB,OAAO;EACN,UAAU,uBAAuB;EACjC,IAAI;CACL;AACD;AACA,SAAS,eAAe,aAAa,WAAW;CAC/C,OAAO;EACN,aAAa;EACb;GACC,UAAU,uBAAuB;GACjC,IAAI;EACL;EACA;GACC,UAAU,uBAAuB;GACjC,IAAI;EACL;CACD;AACD;AACA,SAAS,cAAc,MAAM;CAC5B,OAAO,CAAC,aAAa,GAAG;EACvB,UAAU,uBAAuB;EACjC,IAAI;CACL,CAAC;AACF;;;;;;;AAOA,SAAS,gBAAgB,aAAa,WAAW,SAAS;CACzD,OAAO,QAAQ,KAAK,WAAW,CAAC,GAAG,eAAe,aAAa,SAAS,GAAG;EAC1E,UAAU,yBAAyB;EACnC,IAAI,UAAU;CACf,CAAC,CAAC;AACH;AACA,SAAS,aAAa,QAAQ,aAAa;CAC1C,OAAO,IAAI,yBAAyB;EACnC,QAAQ,SAAS,OAAO,MAAM,OAAO,MAAM;EAC3C,WAAW,OAAO;EAClB;EACA,WAAW,OAAO;EAClB,OAAO,CAAC,GAAG,OAAO,KAAK;EACvB,OAAO,OAAO;EACd,WAAW,OAAO;EAClB,YAAY,OAAO;EACnB,WAAW,CAAC,eAAe,aAAa,OA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AmB,UAAU,MAAM,QAAQ;CACjD,2BAA2B,OAAO,MAAM,YAAY;CACpD,MAAM,SAAS,MAAM;CACrB,MAAM,eAAe,qCAAqC,kBAAkB;EAC3E,qBAAqB;EACrB,GAAG,UAAU,oBAAoB,wBAAwB,MAAM,mBAAmB,CAAC;EACnF,gBAAgB;CACjB,CAAC;CACD,MAAM,WAAW,yBAAyB,YAAY;CACtD,MAAM,eAAe,oBAAoB,UAAU,MAAM;CACzD,MAAM,kBAAkB,iBAAiB,QAAQ;CACjD,MAAM,kBAAkB,iBAAiB,YAAY;CACrD,OAAO;EACN;EACA,QAAQ;EACR,QAAQ,UAAU,YAAY,UAAU,YAAY,CAAC,CAAC,CAAC,QAAQ,UAAU;GACxE,IAAI,aAAa,KAAK,MAAM,gBAAgB,OAAO;GACnD,IAAI,qBAAqB,KAAK,GAAG,OAAO;GACxC,MAAM,cAAc,+BAA+B,OAAO,8BAA8B;GACxF,MAAM,mBAAmB,MAAM,KAAK;GACpC,IAAI,qBAAqB,KAAK,GAAG,OAAO;GACxC,QAAQ,gBAAgB,eAAe,kBAAkB,gBAAA,CAAiB,IAAI,gBAAgB;EAC/F,CAAC;CACF;AACD"}
1
+ {"version":3,"file":"diff-database-schema-C9UxdmYu-BzQjQb1e.mjs","names":[],"sources":["../../../../3-targets/3-targets/postgres/dist/diff-database-schema-C9UxdmYu.mjs"],"sourcesContent":["import { s as postgresError } from \"./errors-DYyzTYzE.mjs\";\nimport { n as postgresResolveDefault } from \"./default-normalizer-Ba5ZebHM.mjs\";\nimport { r as isPostgresSchema } from \"./postgres-schema-B3t7Zr52.mjs\";\nimport { a as postgresDiffSubjectGranularity, n as PostgresNativeEnumSchemaNode, r as PostgresSchemaNodeKind, t as PostgresTableSchemaNode } from \"./postgres-table-schema-node-BBkitBQh.mjs\";\nimport { i as PostgresDatabaseSchemaNode, n as PostgresPolicySchemaNode, r as PostgresNamespaceSchemaNode, t as PostgresRoleSchemaNode } from \"./postgres-role-schema-node-B8Z5i5D-.mjs\";\nimport { t as resolveDdlSchemaForNamespaceStorage } from \"./resolve-ddl-schema-Cab6g5MC.mjs\";\nimport { i as resolvePostgresNodeIssueControlPolicySubject } from \"./control-policy-BN8Ouun3.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { UNBOUND_NAMESPACE_ID } from \"@internal/framework-components/ir\";\nimport { buildNativeTypeExpander, contractNamespaceToSchemaIR } from \"@internal/family-sql/control\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { namingOf } from \"@internal/sql-schema-ir/naming\";\nimport { PrimaryKey, RelationalSchemaNodeKind, SqlForeignKeyIR, SqlIndexIR, SqlUniqueIR } from \"@internal/sql-schema-ir/types\";\nimport { classifyDiffSubjectGranularity } from \"@internal/family-sql/diff\";\nimport { diffSchemas, issueOutcome } from \"@internal/framework-components/control\";\n//#region src/core/migrations/contract-to-postgres-database-schema-node.ts\n/** The database root's fixed sentinel id (`PostgresDatabaseSchemaNode#id`). */\nfunction databaseStep() {\n\treturn {\n\t\tnodeKind: PostgresSchemaNodeKind.database,\n\t\tid: \"database\"\n\t};\n}\nfunction tableDependsOn(namespaceId, tableName) {\n\treturn [\n\t\tdatabaseStep(),\n\t\t{\n\t\t\tnodeKind: PostgresSchemaNodeKind.namespace,\n\t\t\tid: namespaceId\n\t\t},\n\t\t{\n\t\t\tnodeKind: PostgresSchemaNodeKind.table,\n\t\t\tid: tableName\n\t\t}\n\t];\n}\nfunction roleDependsOn(role) {\n\treturn [databaseStep(), {\n\t\tnodeKind: PostgresSchemaNodeKind.role,\n\t\tid: role\n\t}];\n}\n/**\n* The chains from a table-child object (foreign key, index, unique, primary\n* key) to each of the own columns it is built on, in the Postgres tree.\n* Dropping a covered column auto-drops the object, so the object's drop must\n* precede the column's; the graph derives that direction from these edges.\n*/\nfunction columnDependsOn(namespaceId, tableName, columns) {\n\treturn columns.map((column) => [...tableDependsOn(namespaceId, tableName), {\n\t\tnodeKind: RelationalSchemaNodeKind.column,\n\t\tid: `column:${column}`\n\t}]);\n}\nfunction toPolicyNode(policy, namespaceId) {\n\treturn new PostgresPolicySchemaNode({\n\t\tnaming: namingOf(policy.name, policy.prefix),\n\t\ttableName: policy.tableName,\n\t\tnamespaceId,\n\t\toperation: policy.operation,\n\t\troles: [...policy.roles],\n\t\tusing: policy.using,\n\t\twithCheck: policy.withCheck,\n\t\tpermissive: policy.permissive,\n\t\tdependsOn: [tableDependsOn(namespaceId, policy.tableName), ...policy.roles.map(roleDependsOn)]\n\t});\n}\n/**\n* Projects a Postgres contract into the expected schema-diff tree: a\n* `PostgresDatabaseSchemaNode` root holding one `PostgresNamespaceSchemaNode`\n* per Postgres namespace, each holding its `PostgresTableSchemaNode`s with\n* their `PostgresPolicySchemaNode`s, plus the database roles on the root.\n*\n* Not a duplicate of the family's `contractToSchemaIR`: that builds a flat,\n* single `{ tables }` map (and throws on cross-namespace name collisions, with\n* no RLS/role concept) for SQLite's single-schema world. This is the\n* Postgres-specific *tree* shape — multi-schema, RLS-policy-aware, role-aware.\n* It reuses the family's per-namespace table conversion (`contractNamespaceToSchemaIR`)\n* for column/FK/index building and only adds the Postgres tree/policy/role shape.\n*\n* Tables are grouped by their owning namespace (resolved DDL schema name) so\n* the tree mirrors Postgres's object hierarchy. The DDL schema name is\n* resolved once per namespace.\n*\n* A policy that references a table absent from its namespace is a malformed\n* contract — the loop throws rather than fabricating a stub table.\n*/\nfunction contractToPostgresDatabaseSchemaNode(contract, options) {\n\tif (contract === null) return new PostgresDatabaseSchemaNode({\n\t\tnamespaces: {},\n\t\troles: [],\n\t\texistingSchemas: [],\n\t\tpgVersion: \"\"\n\t});\n\tconst namespaces = {};\n\tconst roles = [];\n\tconst ownedSchemas = [];\n\tfor (const ns of Object.values(contract.storage.namespaces)) {\n\t\tif (!isPostgresSchema(ns)) continue;\n\t\tfor (const role of Object.values(ns.role)) roles.push(new PostgresRoleSchemaNode({\n\t\t\tname: role.name,\n\t\t\tnamespaceId: role.namespaceId\n\t\t}));\n\t\tif (ns.id === UNBOUND_NAMESPACE_ID) {\n\t\t\tif (!Object.entries(ns.entries).some(([entriesKey, slot]) => entriesKey !== \"role\" && Object.keys(slot).length > 0)) continue;\n\t\t}\n\t\tconst ddlSchema = resolveDdlSchemaForNamespaceStorage(contract.storage, ns.id);\n\t\townedSchemas.push(ddlSchema);\n\t\tconst sqlTables = contractNamespaceToSchemaIR(contract.storage, ns.id, options).tables;\n\t\tconst policiesByTable = /* @__PURE__ */ new Map();\n\t\tfor (const policy of Object.values(ns.policy)) {\n\t\t\tconst list = policiesByTable.get(policy.tableName) ?? [];\n\t\t\tlist.push(toPolicyNode(policy, ddlSchema));\n\t\t\tpoliciesByTable.set(policy.tableName, list);\n\t\t}\n\t\tconst tables = {};\n\t\tfor (const tableName of Object.keys(ns.table)) {\n\t\t\tconst sqlTable = sqlTables[tableName];\n\t\t\tif (sqlTable === void 0) continue;\n\t\t\tconst foreignKeys = sqlTable.foreignKeys.map((fk) => {\n\t\t\t\tconst resolvedReferencedNamespace = resolveDdlSchemaForNamespaceStorage(contract.storage, fk.referencedSchema ?? UNBOUND_NAMESPACE_ID);\n\t\t\t\treturn new SqlForeignKeyIR({\n\t\t\t\t\tcolumns: fk.columns,\n\t\t\t\t\treferencedTable: fk.referencedTable,\n\t\t\t\t\treferencedColumns: fk.referencedColumns,\n\t\t\t\t\treferencedSchema: fk.referencedSchema ?? UNBOUND_NAMESPACE_ID,\n\t\t\t\t\t...ifDefined(\"name\", fk.name),\n\t\t\t\t\t...ifDefined(\"onDelete\", fk.onDelete),\n\t\t\t\t\t...ifDefined(\"onUpdate\", fk.onUpdate),\n\t\t\t\t\t...ifDefined(\"annotations\", fk.annotations),\n\t\t\t\t\tresolvedReferencedNamespace,\n\t\t\t\t\tdependsOn: [tableDependsOn(resolvedReferencedNamespace, fk.referencedTable), ...columnDependsOn(ddlSchema, tableName, fk.columns)]\n\t\t\t\t});\n\t\t\t});\n\t\t\tconst uniques = sqlTable.uniques.map((u) => new SqlUniqueIR({\n\t\t\t\tcolumns: u.columns,\n\t\t\t\t...ifDefined(\"name\", u.name),\n\t\t\t\t...ifDefined(\"annotations\", u.annotations),\n\t\t\t\tdependsOn: columnDependsOn(ddlSchema, tableName, u.columns)\n\t\t\t}));\n\t\t\tconst indexes = sqlTable.indexes.map((i) => {\n\t\t\t\tconst base = {\n\t\t\t\t\tnaming: namingOf(i.name, i.prefix),\n\t\t\t\t\twhere: i.where,\n\t\t\t\t\tunique: i.unique,\n\t\t\t\t\tpartial: i.partial,\n\t\t\t\t\ttype: i.type,\n\t\t\t\t\toptions: i.options,\n\t\t\t\t\tannotations: i.annotations,\n\t\t\t\t\tdependsOn: columnDependsOn(ddlSchema, tableName, i.columns ?? Object.keys(sqlTable.columns))\n\t\t\t\t};\n\t\t\t\treturn new SqlIndexIR(i.expression !== void 0 ? {\n\t\t\t\t\t...base,\n\t\t\t\t\texpression: i.expression\n\t\t\t\t} : {\n\t\t\t\t\t...base,\n\t\t\t\t\tcolumns: i.columns ?? []\n\t\t\t\t});\n\t\t\t});\n\t\t\tconst primaryKey = sqlTable.primaryKey !== void 0 ? new PrimaryKey({\n\t\t\t\tcolumns: sqlTable.primaryKey.columns,\n\t\t\t\t...ifDefined(\"name\", sqlTable.primaryKey.name),\n\t\t\t\tdependsOn: columnDependsOn(ddlSchema, tableName, sqlTable.primaryKey.columns)\n\t\t\t}) : void 0;\n\t\t\ttables[tableName] = new PostgresTableSchemaNode({\n\t\t\t\tname: sqlTable.name,\n\t\t\t\tcolumns: sqlTable.columns,\n\t\t\t\tforeignKeys,\n\t\t\t\tuniques,\n\t\t\t\tindexes,\n\t\t\t\t...ifDefined(\"primaryKey\", primaryKey),\n\t\t\t\t...ifDefined(\"annotations\", sqlTable.annotations),\n\t\t\t\t...ifDefined(\"checks\", sqlTable.checks),\n\t\t\t\tpolicies: policiesByTable.get(tableName) ?? [],\n\t\t\t\trlsEnabled: Object.hasOwn(ns.rls, tableName)\n\t\t\t});\n\t\t}\n\t\tfor (const [tableName, tablePolicies] of policiesByTable) {\n\t\t\tif (!(tableName in tables)) {\n\t\t\t\tconst policyName = tablePolicies[0]?.name ?? \"(unknown)\";\n\t\t\t\tthrow postgresError(\"CONTRACT.POLICY_INVALID\", `contract-to-postgres-database-schema-node: policy \"${policyName}\" references table \"${tableName}\" not present in namespace \"${ddlSchema}\"`, { meta: {\n\t\t\t\t\tpolicyName,\n\t\t\t\t\ttableName,\n\t\t\t\t\tnamespaceId: ddlSchema,\n\t\t\t\t\treason: \"table-missing\"\n\t\t\t\t} });\n\t\t\t}\n\t\t\tif (!Object.hasOwn(ns.rls, tableName)) {\n\t\t\t\tconst policyLabel = tablePolicies[0]?.prefix ?? tablePolicies[0]?.name ?? \"(unknown)\";\n\t\t\t\tthrow postgresError(\"CONTRACT.POLICY_INVALID\", `contract-to-postgres-database-schema-node: policy \"${policyLabel}\" targets table \"${tableName}\" in namespace \"${ddlSchema}\", which is not RLS-controlled. Mark the model with @@rls (entries.rls[\"${tableName}\"]) or remove the policy.`, { meta: {\n\t\t\t\t\tpolicyName: policyLabel,\n\t\t\t\t\ttableName,\n\t\t\t\t\tnamespaceId: ddlSchema,\n\t\t\t\t\treason: \"table-not-rls-controlled\"\n\t\t\t\t} });\n\t\t\t}\n\t\t}\n\t\tnamespaces[ddlSchema] = new PostgresNamespaceSchemaNode({\n\t\t\tschemaName: ddlSchema,\n\t\t\ttables,\n\t\t\tnativeEnums: Object.values(ns.entries.native_enum ?? {}).map((entity) => new PostgresNativeEnumSchemaNode({\n\t\t\t\ttypeName: entity.typeName,\n\t\t\t\tnamespaceId: ddlSchema,\n\t\t\t\tmembers: entity.members,\n\t\t\t\t...ifDefined(\"control\", entity.control)\n\t\t\t}))\n\t\t});\n\t}\n\treturn new PostgresDatabaseSchemaNode({\n\t\tnamespaces,\n\t\troles,\n\t\texistingSchemas: ownedSchemas,\n\t\tpgVersion: \"\"\n\t});\n}\n//#endregion\n//#region src/core/migrations/diff-database-schema.ts\n/**\n* Whether a diff issue's subject node is cluster-scoped — it carries its own\n* `namespaceId` field (only role and policy diff nodes do) and that\n* coordinate is the unbound sentinel, meaning the node is not owned by any\n* schema/namespace. A role node is always cluster-scoped (roles are\n* cluster-level objects); a policy node's `namespaceId` is always its\n* table's resolved DDL schema, never the sentinel. Namespace-ownership\n* scoping (which compares `issue.path[1]` against the set of DDL schemas\n* the contract owns) makes no sense for a cluster-scoped subject — its path\n* segment at that index is the object's own name, not a schema name — so\n* such an issue bypasses that scoping entirely.\n*/\nfunction isClusterScopedIssue(issue) {\n\tconst node = issue.expected ?? issue.actual;\n\treturn node !== void 0 && nodeNamespaceId(node) === UNBOUND_NAMESPACE_ID;\n}\nfunction nodeNamespaceId(node) {\n\tif (!Object.hasOwn(node, \"namespaceId\")) return void 0;\n\treturn blindCast(node).namespaceId;\n}\nfunction ownedSchemaNames(expected) {\n\tconst policyNamespaces = Object.values(expected.namespaces).flatMap((ns) => Object.values(ns.tables).flatMap((t) => t.policies.map((p) => p.namespaceId)));\n\treturn /* @__PURE__ */ new Set([...policyNamespaces, ...expected.existingSchemas]);\n}\n/**\n* Drops contract namespaces that declare no tables from the verdict-diff\n* expected tree and the relational owned-schema set. The legacy relational\n* walk skipped a table-less namespace (e.g. an enums-only schema) before\n* pairing, so neither its DDL schema's absence nor that schema's live\n* relational contents ever reached the verdict — the pruned tree\n* reproduces that. The prune loses no expected policies: policies attach\n* to tables, so a table-less namespace carries none (the projection\n* throws on a policy referencing an absent table). Live policies in a\n* pruned schema remain governed via the full owned set (see\n* {@link diffPostgresSchema}).\n*/\nfunction pruneTableLessNamespaces(expected) {\n\tconst namespaces = Object.fromEntries(Object.entries(expected.namespaces).filter(([, ns]) => Object.keys(ns.tables).length > 0));\n\treturn new PostgresDatabaseSchemaNode({\n\t\tnamespaces,\n\t\troles: [...expected.roles],\n\t\texistingSchemas: expected.existingSchemas.filter((s) => namespaces[s] !== void 0),\n\t\tpgVersion: expected.pgVersion\n\t});\n}\n/**\n* Resolves a verdict-diff issue's subject's declared control policy directly\n* from the contract, by delegating to the same node-typed resolver\n* ({@link resolvePostgresNodeIssueControlPolicySubject}) the planner uses to\n* gate DDL calls. `undefined` when the issue resolves to no contract subject.\n*\n* A role issue resolves through that same resolver to `external`\n* unconditionally (see its role branch), regardless of the contract's own\n* default policy: a role is referenced by the contract but not owned, and\n* `external`'s existing semantics — a missing declared subject still fails,\n* every extra is suppressed — are exactly the wanted asymmetric grading for\n* a cluster object the framework does not own.\n*/\nfunction resolveControlPolicy(issue, contract) {\n\treturn resolvePostgresNodeIssueControlPolicySubject(blindCast(issue), contract)?.explicitNodeControlPolicy;\n}\n/**\n* The Postgres full-tree node diff for the family verify verdict: derive\n* the expected tree (resolved leaf values, expander threaded, FK schemas\n* resolved, table-less namespaces pruned), run the generic\n* differ over the trees as derived, and scope out `not-expected` findings under namespaces the\n* contract does not own. Ownership scoping bypasses cluster-scoped subjects\n* (roles today), mirroring the legacy decomposition: relational extras check\n* the PRUNED owned set (the legacy\n* per-namespace walk never visited a table-less namespace, so its live\n* relational contents are invisible), while `structural` extras (RLS\n* policies) check the FULL owned set (the legacy policy diff governed\n* every contract schema regardless of tables — RLS governance does not\n* shrink because a namespace declares no tables). The codec `verifyType`\n* hooks run once per contract namespace with tables against that\n* namespace's paired actual node (the hooks read namespace-scoped state\n* such as `nativeEnums`).\n*/\nfunction diffPostgresSchema(input) {\n\tconst postgresContract = blindCast(input.contract);\n\tPostgresDatabaseSchemaNode.assert(input.schema);\n\tconst actual = input.schema;\n\tconst fullExpected = contractToPostgresDatabaseSchemaNode(postgresContract, {\n\t\tannotationNamespace: \"pg\",\n\t\t...ifDefined(\"expandNativeType\", buildNativeTypeExpander(input.frameworkComponents)),\n\t\tresolveDefault: postgresResolveDefault\n\t});\n\tconst expected = pruneTableLessNamespaces(fullExpected);\n\tconst relationalOwned = ownedSchemaNames(expected);\n\tconst structuralOwned = ownedSchemaNames(fullExpected);\n\treturn {\n\t\tissues: diffSchemas(expected, actual).filter((issue) => {\n\t\t\tif (issueOutcome(issue) !== \"not-expected\") return true;\n\t\t\tif (isClusterScopedIssue(issue)) return true;\n\t\t\tconst granularity = classifyDiffSubjectGranularity(issue, postgresDiffSubjectGranularity);\n\t\t\tconst namespaceSegment = issue.path[1];\n\t\t\tif (namespaceSegment === void 0) return true;\n\t\t\treturn (granularity === \"structural\" ? structuralOwned : relationalOwned).has(namespaceSegment);\n\t\t}),\n\t\tresolveControlPolicy: (issue) => resolveControlPolicy(issue, postgresContract),\n\t\tnamespacePairs: Object.values(expected.namespaces).map((ns) => ({ actual: actual.namespaces[ns.schemaName] }))\n\t};\n}\n/**\n* Adds an empty namespace node to the actual tree for every expected namespace\n* absent from it. The relational plan diff pairs on namespace: a contract\n* namespace whose live schema does not exist yet must surface each of its\n* tables as `not-found` (→ `CREATE TABLE`), NOT as a single namespace\n* `not-found` that subtree-coalescing would collapse (leaving `CREATE SCHEMA`\n* with no tables). Padding makes the namespaces pair, so only table/column/\n* policy drift surfaces; `CREATE SCHEMA` comes separately from the synthesized\n* namespace-presence stitch (`verifyPostgresNamespacePresence`), never from the\n* tree diff — matching the retired per-namespace-paired relational walk, which\n* paired a missing schema against an empty namespace node.\n*/\nfunction padActualNamespaces(expected, actual) {\n\tconst namespaces = { ...actual.namespaces };\n\tlet padded = false;\n\tfor (const schemaName of Object.keys(expected.namespaces)) if (namespaces[schemaName] === void 0) {\n\t\tnamespaces[schemaName] = new PostgresNamespaceSchemaNode({\n\t\t\tschemaName,\n\t\t\ttables: {}\n\t\t});\n\t\tpadded = true;\n\t}\n\tif (!padded) return actual;\n\treturn new PostgresDatabaseSchemaNode({\n\t\tnamespaces,\n\t\troles: [...actual.roles],\n\t\texistingSchemas: [...actual.existingSchemas],\n\t\tpgVersion: actual.pgVersion\n\t});\n}\n/**\n* The Postgres planner's diff input: the SAME tree-building\n* `diffPostgresSchema` uses (expander threaded, FK schemas resolved,\n* table-less namespaces pruned, cluster-scope-aware ownership filter) plus\n* actual namespace padding (so a missing\n* schema's tables surface as `not-found` instead of a swallowed namespace\n* `not-found`). One differ drives both verify and plan; this is the\n* plan-side derivation. The single issue list covers tables / columns /\n* constraints / indexes / defaults AND policies — the caller splits it\n* (relational → `mapNodeIssueToCall`; policy → RLS ops) and stitches in\n* `CREATE SCHEMA` separately.\n*/\nfunction buildPostgresPlanDiff(input) {\n\tconst postgresContract = blindCast(input.contract);\n\tPostgresDatabaseSchemaNode.assert(input.actualSchema);\n\tconst actual = input.actualSchema;\n\tconst fullExpected = contractToPostgresDatabaseSchemaNode(postgresContract, {\n\t\tannotationNamespace: \"pg\",\n\t\t...ifDefined(\"expandNativeType\", buildNativeTypeExpander(input.frameworkComponents)),\n\t\tresolveDefault: postgresResolveDefault\n\t});\n\tconst expected = pruneTableLessNamespaces(fullExpected);\n\tconst paddedActual = padActualNamespaces(expected, actual);\n\tconst relationalOwned = ownedSchemaNames(expected);\n\tconst structuralOwned = ownedSchemaNames(fullExpected);\n\treturn {\n\t\texpected,\n\t\tactual: paddedActual,\n\t\tissues: blindCast(diffSchemas(expected, paddedActual)).filter((issue) => {\n\t\t\tif (issueOutcome(issue) !== \"not-expected\") return true;\n\t\t\tif (isClusterScopedIssue(issue)) return true;\n\t\t\tconst granularity = classifyDiffSubjectGranularity(issue, postgresDiffSubjectGranularity);\n\t\t\tconst namespaceSegment = issue.path[1];\n\t\t\tif (namespaceSegment === void 0) return true;\n\t\t\treturn (granularity === \"structural\" ? structuralOwned : relationalOwned).has(namespaceSegment);\n\t\t})\n\t};\n}\n//#endregion\nexport { diffPostgresSchema as n, contractToPostgresDatabaseSchemaNode as r, buildPostgresPlanDiff as t };\n\n//# sourceMappingURL=diff-database-schema-C9UxdmYu.mjs.map"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAS,eAAe;CACvB,OAAO;EACN,UAAU,uBAAuB;EACjC,IAAI;CACL;AACD;AACA,SAAS,eAAe,aAAa,WAAW;CAC/C,OAAO;EACN,aAAa;EACb;GACC,UAAU,uBAAuB;GACjC,IAAI;EACL;EACA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;GACxC,QAAQ,gBAAgB,eAAe,kBAAkB,gBAAA,CAAiB,IAAI,gBAAgB;EAC/F,CAAC;CACF;AACD"}
package/dist/driver.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  import { t as PostgresControlDriver } from "./control-DzK5mSLo.mjs";
2
- import { n as suppressIdleConnectionErrors } from "./runtime-BJrfP1e8.mjs";
2
+ import { n as suppressIdleConnectionErrors } from "./runtime-Di_BFzUC.mjs";
3
3
  export { PostgresControlDriver, suppressIdleConnectionErrors };
@@ -1,2 +1,2 @@
1
- import { n as suppressIdleConnectionErrors, t as postgresRuntimeDriverDescriptor } from "./runtime-BJrfP1e8.mjs";
1
+ import { n as suppressIdleConnectionErrors, t as postgresRuntimeDriverDescriptor } from "./runtime-Di_BFzUC.mjs";
2
2
  export { postgresRuntimeDriverDescriptor as default, suppressIdleConnectionErrors };
@@ -3,8 +3,8 @@ import { d as isPostgresSchema, i as PostgresRlsPolicy } from "./postgres-schema
3
3
  import { n as PostgresNamespaceSchemaNode, r as PostgresPolicySchemaNode, t as PostgresDatabaseSchemaNode } from "./postgres-role-schema-node-B8Z5i5D--PObwlU2Z.mjs";
4
4
  import { t as resolveDdlSchemaForNamespaceStorage } from "./resolve-ddl-schema-Cab6g5MC-SRco-A7L.mjs";
5
5
  import { A as RenameIndexCall, T as DropPostgresRlsPolicyCall, j as RenamePostgresRlsPolicyCall, k as RenameCheckConstraintCall, p as CreatePostgresRlsPolicyCall } from "./op-factory-call-CSkQdszU-C43tr0rP.mjs";
6
- import { a as planIssues, c as renderPostgresSuppression, d as resolvePostgresNodeIssueControlPolicySubject, f as resolvePostgresNodeIssueCreationFactoryName, i as issueSchemaName, l as resolveNamespaceIdForDdlSchema, n as conflictForDisallowedCall, o as postgresNodeStorageCoordinate, r as issueNode, s as postgresPlannerStrategies, t as coalesceSubtreeIssues, u as resolvePostgresCallControlPolicySubject } from "./control-policy-HgW6zNnz-Ds9U3rSS.mjs";
7
- import { t as buildPostgresPlanDiff } from "./diff-database-schema-B27W13mM-DmRNUFyg.mjs";
6
+ import { a as planIssues, c as renderPostgresSuppression, d as resolvePostgresNodeIssueControlPolicySubject, f as resolvePostgresNodeIssueCreationFactoryName, i as issueSchemaName, l as resolveNamespaceIdForDdlSchema, n as conflictForDisallowedCall, o as postgresNodeStorageCoordinate, r as issueNode, s as postgresPlannerStrategies, t as coalesceSubtreeIssues, u as resolvePostgresCallControlPolicySubject } from "./control-policy-BN8Ouun3-BtGYeb4f.mjs";
7
+ import { t as buildPostgresPlanDiff } from "./diff-database-schema-C9UxdmYu-BzQjQb1e.mjs";
8
8
  import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-BResV739-meZQaWcU.mjs";
9
9
  import { blindCast } from "@prisma/orm-framework/utils/casts";
10
10
  import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
@@ -13,7 +13,7 @@ import { namingOf, parseWireName } from "@prisma/orm-family-sql/schema-ir/naming
13
13
  import { issueOutcome } from "@prisma/orm-framework/components/control";
14
14
  import { controlPolicyForCall, extractCodecControlHooks, partitionCallsByControlPolicy, partitionIssuesByControlPolicy, planFieldEventOperations, plannerFailure } from "@prisma/orm-family-sql/family/control";
15
15
  import { SqlCheckConstraintIR, SqlIndexIR } from "@prisma/orm-family-sql/schema-ir/types";
16
- //#region ../../../3-targets/3-targets/postgres/dist/planner-CDEcM3hy.mjs
16
+ //#region ../../../3-targets/3-targets/postgres/dist/planner-DtwSy6w3.mjs
17
17
  /**
18
18
  * Resolves the live-database schema name for a given namespace
19
19
  * coordinate. Mirrors `resolveDdlSchemaForNamespace` in
@@ -668,4 +668,4 @@ function policyNodeToContractPolicy(node) {
668
668
  //#endregion
669
669
  export { createPostgresMigrationPlanner as t };
670
670
 
671
- //# sourceMappingURL=planner-CDEcM3hy-Bd4_HNx3.mjs.map
671
+ //# sourceMappingURL=planner-DtwSy6w3--x0IvtI9.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"planner-CDEcM3hy-Bd4_HNx3.mjs","names":["#lowerer"],"sources":["../../../../3-targets/3-targets/postgres/dist/planner-CDEcM3hy.mjs"],"sourcesContent":["import { t as DEFAULT_NAMESPACE_ID } from \"./namespace-ids-xtp_ZY86.mjs\";\nimport { _ as PostgresRlsPolicy, r as isPostgresSchema } from \"./postgres-schema-B3t7Zr52.mjs\";\nimport { i as PostgresDatabaseSchemaNode, n as PostgresPolicySchemaNode, r as PostgresNamespaceSchemaNode } from \"./postgres-role-schema-node-B8Z5i5D-.mjs\";\nimport { t as resolveDdlSchemaForNamespaceStorage } from \"./resolve-ddl-schema-Cab6g5MC.mjs\";\nimport { t as buildPostgresPlanDiff } from \"./diff-database-schema-B27W13mM.mjs\";\nimport { a as resolvePostgresNodeIssueCreationFactoryName, c as issueNode, d as postgresPlannerStrategies, f as postgresNodeStorageCoordinate, i as resolvePostgresNodeIssueControlPolicySubject, l as issueSchemaName, n as resolveNamespaceIdForDdlSchema, o as coalesceSubtreeIssues, r as resolvePostgresCallControlPolicySubject, s as conflictForDisallowedCall, t as renderPostgresSuppression, u as planIssues } from \"./control-policy-HgW6zNnz.mjs\";\nimport { A as RenameIndexCall, T as DropPostgresRlsPolicyCall, j as RenamePostgresRlsPolicyCall, k as RenameCheckConstraintCall, p as CreatePostgresRlsPolicyCall } from \"./op-factory-call-CSkQdszU.mjs\";\nimport { t as TypeScriptRenderablePostgresMigration } from \"./planner-produced-postgres-migration-BResV739.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { UNBOUND_NAMESPACE_ID } from \"@internal/framework-components/ir\";\nimport { controlPolicyForCall, extractCodecControlHooks, partitionCallsByControlPolicy, partitionIssuesByControlPolicy, planFieldEventOperations, plannerFailure } from \"@internal/family-sql/control\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { namingOf, parseWireName } from \"@internal/sql-schema-ir/naming\";\nimport { SqlCheckConstraintIR, SqlIndexIR } from \"@internal/sql-schema-ir/types\";\nimport { issueOutcome } from \"@internal/framework-components/control\";\n//#region src/core/migrations/verify-postgres-namespaces.ts\n/**\n* Resolves the live-database schema name for a given namespace\n* coordinate. Mirrors `resolveDdlSchemaForNamespace` in\n* `planner-strategies.ts` so the verifier's projection and the\n* planner's projection always agree — Postgres-aware namespaces (the\n* production path) dispatch to `ddlSchemaName(storage)`, and bare\n* object payloads (used by some tests) fall back to the coordinate\n* itself.\n*/\nfunction resolveDdlSchemaName(storage, namespaceId) {\n\tconst namespace = storage.namespaces[namespaceId];\n\tif (isPostgresSchema(namespace)) return namespace.ddlSchemaName(storage);\n\treturn namespaceId;\n}\n/**\n* Reads the introspected list of schema names from the database-root schema\n* node. `existingSchemas` is database-level, so it lives on the\n* `PostgresDatabaseSchemaNode` root — not on the per-schema namespace nodes.\n*\n* Defaults to the always-present `public` schema when the node is not the\n* database root — a fresh Postgres database always carries `public` (unless an\n* operator dropped it manually), so any verifier path that runs without an\n* enriched introspection still suppresses the redundant `CREATE SCHEMA\n* \"public\"`.\n*\n* Production introspection (`PostgresControlAdapter.introspect`) is the\n* authoritative source: it queries `pg_namespace` and sets `existingSchemas`\n* on the returned root. Tests that want to assert against a richer initial\n* state construct a `PostgresDatabaseSchemaNode` explicitly.\n*/\nfunction existingSchemasFromSchema(schema) {\n\tif (PostgresDatabaseSchemaNode.is(schema)) return schema.existingSchemas;\n\treturn [DEFAULT_NAMESPACE_ID];\n}\n/**\n* Emits a `postgres-namespace` `not-found` diff issue for every\n* contract-declared Postgres namespace whose live container does not yet\n* exist. The planner prepends these (node-typed, synthesized) to the\n* relational diff issues so a multi-schema plan emits `CREATE SCHEMA`\n* before the tables that need it — a planner-only concern (verify already\n* rejects via the `not-found` table issues a missing schema already\n* produces), so this is not part of the shared diff.\n*\n* A namespace's live container is the schema returned by its\n* polymorphic `ddlSchemaName(storage)` method — named schemas resolve\n* to their own id; the unbound singleton returns `UNBOUND_NAMESPACE_ID`\n* and is skipped explicitly (late-bound namespaces have no fixed DDL\n* schema). Issues are emitted only when the resolved name is a real,\n* creatable schema (not the unbound sentinel) and is missing from the\n* introspected list. `public` is suppressed implicitly because the\n* introspection (or its sensible default) always carries it.\n*\n* Each emitted issue's path is `['database', ddlName]` — an ancestor of\n* every table path under that schema, so it must never be run through\n* `coalesceSubtreeIssues` alongside the table diff (it would swallow the\n* table-level `not-found` issues that drive `CREATE TABLE`); the planner\n* adds these AFTER coalescing the relational issues, and they are not\n* subject to sibling-space ownership scoping (mirrors the retired\n* coordinate walk, which prepended namespace issues after that filter).\n*/\nfunction verifyPostgresNamespacePresence(input) {\n\tconst { contract, schema } = input;\n\tconst existing = new Set(existingSchemasFromSchema(schema));\n\tconst issues = [];\n\tconst namespaceIds = Object.keys(contract.storage.namespaces).sort();\n\tfor (const namespaceId of namespaceIds) {\n\t\tif (namespaceId === UNBOUND_NAMESPACE_ID) continue;\n\t\tconst ddlName = resolveDdlSchemaName(contract.storage, namespaceId);\n\t\tif (ddlName === UNBOUND_NAMESPACE_ID) continue;\n\t\tif (existing.has(ddlName)) continue;\n\t\tconst namespace = new PostgresNamespaceSchemaNode({\n\t\t\tschemaName: ddlName,\n\t\t\ttables: {}\n\t\t});\n\t\tissues.push({\n\t\t\tpath: [\"database\", ddlName],\n\t\t\texpected: namespace\n\t\t});\n\t}\n\treturn issues;\n}\n//#endregion\n//#region src/core/migrations/planner.ts\nfunction createPostgresMigrationPlanner(lowerer) {\n\treturn new PostgresMigrationPlanner(lowerer);\n}\n/**\n* Postgres migration planner — a thin wrapper over `planIssues`.\n*\n* `plan()` diffs the target contract against the live schema via the one\n* differ (`buildPostgresPlanDiff`, producing node-typed `SchemaDiffIssue[]`)\n* and delegates to `planIssues` with the unified `postgresPlannerStrategies`\n* list: NOT-NULL backfill, type-change, nullable-tightening, codec-hook\n* storage types, component-declared dependency installs, and\n* shared-temp-default / empty-table-guarded NOT-NULL add-column. The same\n* strategy list runs for `migration plan`, `db update`, and `db init`;\n* behavior diverges purely on `policy.allowedOperationClasses` (the\n* data-safe strategies short-circuit when `'data'` is excluded). The issue\n* planner applies operation-class policy gates and emits a single\n* `PostgresOpFactoryCall[]` that drives both the runtime-ops view (via\n* `renderOps`) and the `renderTypeScript()` authoring surface. RLS policy\n* drift (the structural half of the same one-differ tree) is handled\n* separately via `planPostgresSchemaDiff`.\n*/\nvar PostgresMigrationPlanner = class {\n\t#lowerer;\n\tconstructor(lowerer) {\n\t\tthis.#lowerer = lowerer;\n\t}\n\tplan(options) {\n\t\treturn this.planSql(options);\n\t}\n\temptyMigration(context, spaceId) {\n\t\treturn new TypeScriptRenderablePostgresMigration([], {\n\t\t\tfrom: context.fromHash,\n\t\t\tto: context.toHash\n\t\t}, spaceId, context.snapshotsImportPath, this.#lowerer);\n\t}\n\tplanSql(options) {\n\t\tconst schemaName = options.schemaName ?? Object.keys(options.contract.storage.namespaces).find((id) => id !== UNBOUND_NAMESPACE_ID) ?? UNBOUND_NAMESPACE_ID;\n\t\tconst policyResult = this.ensureAdditivePolicy(options.policy);\n\t\tif (policyResult) return policyResult;\n\t\tPostgresDatabaseSchemaNode.assert(options.schema);\n\t\tconst { issues: rawIssues } = buildPostgresPlanDiff({\n\t\t\tcontract: options.contract,\n\t\t\tactualSchema: options.schema,\n\t\t\tframeworkComponents: options.frameworkComponents\n\t\t});\n\t\tconst policyDiffIssues = rawIssues.filter((issue) => isPolicyDiffIssue(issue));\n\t\tconst relationalDiffIssues = rawIssues.filter((issue) => !isPolicyDiffIssue(issue));\n\t\tconst strict = options.policy.allowedOperationClasses.includes(\"widening\") || options.policy.allowedOperationClasses.includes(\"destructive\");\n\t\tconst owned = retainUnownedExtras(coalesceSubtreeIssues(relationalDiffIssues), options.ownership, options.contract);\n\t\tconst gated = strict ? owned : owned.filter((issue) => issueOutcome(issue) !== \"not-expected\");\n\t\tconst schemaIssues = [...verifyPostgresNamespacePresence({\n\t\t\tcontract: options.contract,\n\t\t\tschema: options.schema\n\t\t}), ...gated];\n\t\tconst indexRenames = this.pairIndexRenames(options, schemaIssues);\n\t\tconst checkRenames = this.pairCheckRenames(options, schemaIssues);\n\t\tconst renameConsumed = /* @__PURE__ */ new Set([...indexRenames.consumed, ...checkRenames.consumed]);\n\t\tconst plannableIssues = renameConsumed.size === 0 ? schemaIssues : schemaIssues.filter((issue) => !renameConsumed.has(issue));\n\t\tconst codecHooks = extractCodecControlHooks(options.frameworkComponents);\n\t\tconst storageTypes = options.contract.storage.types ?? {};\n\t\tconst relationalSchema = relationalNamespaceNode(options.schema, schemaName);\n\t\tconst issuePartition = partitionIssuesByControlPolicy({\n\t\t\tissues: plannableIssues,\n\t\t\tcontract: options.contract,\n\t\t\tresolveControlPolicySubject: (issue) => resolvePostgresNodeIssueControlPolicySubject(issue, options.contract),\n\t\t\tresolveCreationFactoryName: resolvePostgresNodeIssueCreationFactoryName\n\t\t});\n\t\tconst result = planIssues({\n\t\t\tissues: issuePartition.plannable,\n\t\t\ttoContract: options.contract,\n\t\t\tfromContract: options.fromContract,\n\t\t\tschemaName,\n\t\t\tcodecHooks,\n\t\t\tstorageTypes,\n\t\t\t...ifDefined(\"schema\", relationalSchema),\n\t\t\tpolicy: options.policy,\n\t\t\tframeworkComponents: options.frameworkComponents,\n\t\t\tstrategies: postgresPlannerStrategies\n\t\t});\n\t\tconst schemaDiff = this.planPostgresSchemaDiff(options, policyDiffIssues);\n\t\tif (!result.ok || schemaDiff.conflicts.length > 0) return plannerFailure([...result.ok ? [] : result.failure, ...schemaDiff.conflicts]);\n\t\tconst indexRenamePartition = partitionCallsByControlPolicy({\n\t\t\tcalls: [...indexRenames.calls, ...checkRenames.calls],\n\t\t\tcontract: options.contract,\n\t\t\tresolveControlPolicySubject: (call) => resolvePostgresCallControlPolicySubject(call, options.contract),\n\t\t\tresolveFactoryName: (call) => call.factoryName\n\t\t});\n\t\tconst schemaDiffPartition = partitionCallsByControlPolicy({\n\t\t\tcalls: schemaDiff.calls,\n\t\t\tcontract: options.contract,\n\t\t\tresolveControlPolicySubject: (call) => resolvePostgresCallControlPolicySubject(call, options.contract),\n\t\t\tresolveFactoryName: (call) => call.factoryName\n\t\t});\n\t\tconst fieldEventPartition = partitionCallsByControlPolicy({\n\t\t\tcalls: blindCast(planFieldEventOperations({\n\t\t\t\tpriorContract: options.fromContract,\n\t\t\t\tnewContract: options.contract,\n\t\t\t\tcodecHooks\n\t\t\t})),\n\t\t\tcontract: options.contract,\n\t\t\tresolveControlPolicySubject: (call) => resolvePostgresCallControlPolicySubject(call, options.contract),\n\t\t\tresolveFactoryName: (call) => call.factoryName\n\t\t});\n\t\tconst calls = [\n\t\t\t...result.value.calls,\n\t\t\t...indexRenamePartition.kept,\n\t\t\t...schemaDiffPartition.kept,\n\t\t\t...fieldEventPartition.kept\n\t\t];\n\t\tconst seenWarnings = /* @__PURE__ */ new Set();\n\t\tconst warnings = [\n\t\t\t...issuePartition.suppressions,\n\t\t\t...indexRenamePartition.suppressions,\n\t\t\t...schemaDiff.suppressions,\n\t\t\t...schemaDiffPartition.suppressions,\n\t\t\t...fieldEventPartition.suppressions\n\t\t].map((record) => renderPostgresSuppression(record, options.contract)).filter((warning) => {\n\t\t\tconst key = JSON.stringify(warning);\n\t\t\tif (seenWarnings.has(key)) return false;\n\t\t\tseenWarnings.add(key);\n\t\t\treturn true;\n\t\t});\n\t\treturn Object.freeze({\n\t\t\tkind: \"success\",\n\t\t\tplan: new TypeScriptRenderablePostgresMigration(calls, {\n\t\t\t\tfrom: options.fromContract?.storage.storageHash ?? null,\n\t\t\t\tto: options.contract.storage.storageHash\n\t\t\t}, options.spaceId, options.snapshotsImportPath, this.#lowerer),\n\t\t\t...warnings.length > 0 ? { warnings: Object.freeze(warnings) } : {}\n\t\t});\n\t}\n\t/**\n\t* Rename post-pass for indexes, per `(schema, table)`, widening-only,\n\t* deterministic by sorted names — the same structure as the policy pass\n\t* below (which stays untouched: policies pair by hash only).\n\t*\n\t* Hash pairing (prefix-only renames): extras whose live names parse as\n\t* wire names, grouped by `(schema, table, hash)`; missing nodes iterated\n\t* in sorted-name order consume the sorted-name-first candidate.\n\t*\n\t* Content pairing (exact→wire convergence), after hash pairing has\n\t* consumed its matches: the remaining wire-named-missing nodes\n\t* (`prefix` defined) against the remaining extras of any name shape,\n\t* paired iff content-equal (columns ordered-strict both-defined-or-\n\t* both-undefined, `unique`/`type` strict, `options` loose, bodies\n\t* byte-equal).\n\t*\n\t* Leftovers proceed as create/drop exactly as before; without the\n\t* widening allowance the pass is skipped and pairing degrades to the\n\t* additive half, like the policy pass.\n\t*/\n\tpairIndexRenames(options, issues) {\n\t\tconst consumed = /* @__PURE__ */ new Set();\n\t\tconst calls = [];\n\t\tif (!options.policy.allowedOperationClasses.includes(\"widening\")) return {\n\t\t\tcalls,\n\t\t\tconsumed\n\t\t};\n\t\tconst missing = [];\n\t\tconst extra = [];\n\t\tfor (const issue of issues) {\n\t\t\tconst node = issueNode(issue);\n\t\t\tif (node === void 0 || !SqlIndexIR.is(node)) continue;\n\t\t\tconst ddlSchema = issue.path[1];\n\t\t\tconst tableName = issue.path[2];\n\t\t\tif (ddlSchema === void 0 || tableName === void 0) continue;\n\t\t\tif (issueOutcome(issue) === \"not-found\") missing.push({\n\t\t\t\tissue,\n\t\t\t\tnode,\n\t\t\t\tddlSchema,\n\t\t\t\ttableName\n\t\t\t});\n\t\t\telse if (issueOutcome(issue) === \"not-expected\") extra.push({\n\t\t\t\tissue,\n\t\t\t\tnode,\n\t\t\t\tddlSchema,\n\t\t\t\ttableName\n\t\t\t});\n\t\t}\n\t\tif (missing.length === 0 || extra.length === 0) return {\n\t\t\tcalls,\n\t\t\tconsumed\n\t\t};\n\t\tconst byName = (a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0;\n\t\tconst emissionSchema = (ddlSchema) => resolveNamespaceIdForDdlSchema(options.contract, ddlSchema) === UNBOUND_NAMESPACE_ID ? UNBOUND_NAMESPACE_ID : ddlSchema;\n\t\tconst pairingKey = (finding, hash) => JSON.stringify([\n\t\t\tfinding.ddlSchema,\n\t\t\tfinding.tableName,\n\t\t\thash\n\t\t]);\n\t\tconst rename = (missingFinding, candidate) => {\n\t\t\tconsumed.add(missingFinding.issue);\n\t\t\tconsumed.add(candidate.issue);\n\t\t\tcalls.push(new RenameIndexCall(emissionSchema(missingFinding.ddlSchema), missingFinding.tableName, candidate.node.name, missingFinding.node.name));\n\t\t};\n\t\tconst sortedMissing = [...missing].sort(byName);\n\t\tconst extrasByHash = /* @__PURE__ */ new Map();\n\t\tfor (const finding of extra) {\n\t\t\tconst parsed = parseWireName(finding.node.name);\n\t\t\tif (parsed === void 0) continue;\n\t\t\tconst key = pairingKey(finding, parsed.hash);\n\t\t\tconst group = extrasByHash.get(key) ?? [];\n\t\t\tgroup.push(finding);\n\t\t\textrasByHash.set(key, group);\n\t\t}\n\t\tfor (const group of extrasByHash.values()) group.sort(byName);\n\t\tfor (const missingFinding of sortedMissing) {\n\t\t\tconst parsed = parseWireName(missingFinding.node.name);\n\t\t\tif (parsed === void 0) continue;\n\t\t\tconst candidate = extrasByHash.get(pairingKey(missingFinding, parsed.hash))?.shift();\n\t\t\tif (candidate === void 0) continue;\n\t\t\trename(missingFinding, candidate);\n\t\t}\n\t\tconst sortedExtras = [...extra].sort(byName);\n\t\tfor (const missingFinding of sortedMissing) {\n\t\t\tif (consumed.has(missingFinding.issue)) continue;\n\t\t\tif (missingFinding.node.prefix === void 0) continue;\n\t\t\tconst candidate = sortedExtras.find((extraFinding) => !consumed.has(extraFinding.issue) && extraFinding.ddlSchema === missingFinding.ddlSchema && extraFinding.tableName === missingFinding.tableName && missingFinding.node.contentEquals(extraFinding.node, {\n\t\t\t\tcolumnPresence: \"matching\",\n\t\t\t\tbodies: \"verbatim\"\n\t\t\t}));\n\t\t\tif (candidate === void 0) continue;\n\t\t\trename(missingFinding, candidate);\n\t\t}\n\t\treturn {\n\t\t\tcalls,\n\t\t\tconsumed\n\t\t};\n\t}\n\t/**\n\t* Check-constraint rename post-pass: a `not-found` and a `not-expected`\n\t* check on the same table whose wire-name content hashes match but whose\n\t* prefixes differ is a prefix-only rename, and collapses into one\n\t* `ALTER TABLE … RENAME CONSTRAINT`.\n\t*\n\t* This is the index pass's hash-pairing phase and nothing else. There is\n\t* deliberately no content-pairing phase: a live check body is whatever\n\t* Postgres reprinted, so it never byte-matches the authored text, and\n\t* pairing an exact-named live check by content would bless whatever\n\t* predicate is actually live. Adoption of an old exact-named check stays\n\t* drop + add.\n\t*\n\t* Runs only when the policy allows `widening` (rename's class). Without it\n\t* the pass no-ops and the pair degrades to the slice-1 behavior: an add,\n\t* plus a drop when `destructive` is allowed too.\n\t*/\n\tpairCheckRenames(options, issues) {\n\t\tconst consumed = /* @__PURE__ */ new Set();\n\t\tconst calls = [];\n\t\tif (!options.policy.allowedOperationClasses.includes(\"widening\")) return {\n\t\t\tcalls,\n\t\t\tconsumed\n\t\t};\n\t\tconst missing = [];\n\t\tconst extra = [];\n\t\tfor (const issue of issues) {\n\t\t\tconst node = issueNode(issue);\n\t\t\tif (node === void 0 || !SqlCheckConstraintIR.is(node)) continue;\n\t\t\tconst ddlSchema = issue.path[1];\n\t\t\tconst tableName = issue.path[2];\n\t\t\tif (ddlSchema === void 0 || tableName === void 0) continue;\n\t\t\tif (issueOutcome(issue) === \"not-found\") missing.push({\n\t\t\t\tissue,\n\t\t\t\tnode,\n\t\t\t\tddlSchema,\n\t\t\t\ttableName\n\t\t\t});\n\t\t\telse if (issueOutcome(issue) === \"not-expected\") extra.push({\n\t\t\t\tissue,\n\t\t\t\tnode,\n\t\t\t\tddlSchema,\n\t\t\t\ttableName\n\t\t\t});\n\t\t}\n\t\tif (missing.length === 0 || extra.length === 0) return {\n\t\t\tcalls,\n\t\t\tconsumed\n\t\t};\n\t\tconst byName = (a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0;\n\t\tconst emissionSchema = (ddlSchema) => resolveNamespaceIdForDdlSchema(options.contract, ddlSchema) === UNBOUND_NAMESPACE_ID ? UNBOUND_NAMESPACE_ID : ddlSchema;\n\t\tconst pairingKey = (finding, hash) => JSON.stringify([\n\t\t\tfinding.ddlSchema,\n\t\t\tfinding.tableName,\n\t\t\thash\n\t\t]);\n\t\tconst sortedMissing = [...missing].sort(byName);\n\t\tconst extrasByHash = /* @__PURE__ */ new Map();\n\t\tfor (const finding of extra) {\n\t\t\tconst parsed = parseWireName(finding.node.name);\n\t\t\tif (parsed === void 0) continue;\n\t\t\tconst key = pairingKey(finding, parsed.hash);\n\t\t\tconst group = extrasByHash.get(key) ?? [];\n\t\t\tgroup.push(finding);\n\t\t\textrasByHash.set(key, group);\n\t\t}\n\t\tfor (const group of extrasByHash.values()) group.sort(byName);\n\t\tfor (const missingFinding of sortedMissing) {\n\t\t\tconst parsed = parseWireName(missingFinding.node.name);\n\t\t\tif (parsed === void 0) continue;\n\t\t\tconst candidate = extrasByHash.get(pairingKey(missingFinding, parsed.hash))?.shift();\n\t\t\tif (candidate === void 0) continue;\n\t\t\tconsumed.add(missingFinding.issue);\n\t\t\tconsumed.add(candidate.issue);\n\t\t\tcalls.push(new RenameCheckConstraintCall(emissionSchema(missingFinding.ddlSchema), missingFinding.tableName, candidate.node.name, missingFinding.node.name));\n\t\t}\n\t\treturn {\n\t\t\tcalls,\n\t\t\tconsumed\n\t\t};\n\t}\n\t/**\n\t* Maps the RLS policy findings of the one combined tree diff\n\t* (`buildPostgresPlanDiff`, already ownership-filtered) into\n\t* `CREATE POLICY` / `DROP POLICY` / `ALTER POLICY … RENAME TO` ops — a\n\t* `not-equal` finding (an exact-named policy whose content drifted)\n\t* becomes drop + create, or a disallowed-call conflict when the policy\n\t* forbids the destructive drop. It\n\t* does not re-diff — it consumes exactly the policy-node subset of the\n\t* shared diff's issues. Enablement is NOT decided here: `ENABLE`/`DISABLE\n\t* ROW LEVEL SECURITY` derive from the table's marker-driven `rlsEnabled`\n\t* attribute diff on the relational side.\n\t*\n\t* Rename post-pass (the index pass's structure): hash pairing pairs a\n\t* `not-found` and a `not-expected` policy on the SAME table whose\n\t* wire-name content hashes match but prefixes differ (prefix-only rename);\n\t* content pairing then pairs remaining wire-named-missing policies against remaining\n\t* extras of any name shape by verbatim content (the node-owned `contentEquals` —\n\t* exact→wire adoption). Multi-candidate groups pair deterministically\n\t* by sorted name; leftovers proceed as create/drop; an exact-named\n\t* missing policy never content-pairs.\n\t*\n\t* The pairing runs only when the policy allows `widening` (rename's\n\t* class). Without it (db-init's additive-only set), pairing degrades\n\t* deliberately to the additive half: the new name is CREATEd and the old\n\t* policy survives live until a widening/destructive-allowed plan runs —\n\t* emitting an ungated widening rename would only fail at the runner's\n\t* class re-enforcement.\n\t*/\n\tplanPostgresSchemaDiff(options, filteredDiffIssues) {\n\t\tconst allowsDestructive = options.policy.allowedOperationClasses.includes(\"destructive\");\n\t\tconst allowsWidening = options.policy.allowedOperationClasses.includes(\"widening\");\n\t\tconst missing = [];\n\t\tconst extra = [];\n\t\tconst changed = [];\n\t\tfor (const issue of filteredDiffIssues) if (issueOutcome(issue) === \"not-equal\") {\n\t\t\tconst expected = issue.expected;\n\t\t\tPostgresPolicySchemaNode.assert(expected);\n\t\t\tchanged.push({\n\t\t\t\tnode: expected,\n\t\t\t\tschemaForTable: resolveDdlSchemaForNamespaceStorage(options.contract.storage, expected.namespaceId)\n\t\t\t});\n\t\t} else if (issueOutcome(issue) === \"not-found\") {\n\t\t\tconst expected = issue.expected;\n\t\t\tPostgresPolicySchemaNode.assert(expected);\n\t\t\tmissing.push({\n\t\t\t\tnode: expected,\n\t\t\t\tschemaForTable: resolveDdlSchemaForNamespaceStorage(options.contract.storage, expected.namespaceId)\n\t\t\t});\n\t\t} else if (issueOutcome(issue) === \"not-expected\") {\n\t\t\tconst actual = issue.actual;\n\t\t\tPostgresPolicySchemaNode.assert(actual);\n\t\t\textra.push({\n\t\t\t\tnode: actual,\n\t\t\t\tschemaForTable: resolveDdlSchemaForNamespaceStorage(options.contract.storage, actual.namespaceId)\n\t\t\t});\n\t\t}\n\t\tconst calls = [];\n\t\tconst conflicts = [];\n\t\tconst suppressions = [];\n\t\tconst renamedExtras = /* @__PURE__ */ new Set();\n\t\tconst renamedMissing = /* @__PURE__ */ new Set();\n\t\tconst pairingKey = (finding, hash) => JSON.stringify([\n\t\t\tfinding.schemaForTable,\n\t\t\tfinding.node.tableName,\n\t\t\thash\n\t\t]);\n\t\tif (allowsWidening) {\n\t\t\tconst extrasByGroup = /* @__PURE__ */ new Map();\n\t\t\tfor (const finding of extra) {\n\t\t\t\tconst parsed = parseWireName(finding.node.name);\n\t\t\t\tif (parsed === void 0) continue;\n\t\t\t\tconst key = pairingKey(finding, parsed.hash);\n\t\t\t\tconst group = extrasByGroup.get(key) ?? [];\n\t\t\t\tgroup.push(finding);\n\t\t\t\textrasByGroup.set(key, group);\n\t\t\t}\n\t\t\tfor (const group of extrasByGroup.values()) group.sort((a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0);\n\t\t\tconst sortedMissing = [...missing].sort((a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0);\n\t\t\tfor (const missingFinding of sortedMissing) {\n\t\t\t\tconst parsed = parseWireName(missingFinding.node.name);\n\t\t\t\tif (parsed === void 0) continue;\n\t\t\t\tconst candidate = extrasByGroup.get(pairingKey(missingFinding, parsed.hash))?.shift();\n\t\t\t\tif (candidate === void 0) continue;\n\t\t\t\trenamedExtras.add(candidate);\n\t\t\t\trenamedMissing.add(missingFinding);\n\t\t\t\tcalls.push(new RenamePostgresRlsPolicyCall(missingFinding.schemaForTable, missingFinding.node.tableName, candidate.node.name, missingFinding.node.name));\n\t\t\t}\n\t\t\tconst sortedExtras = [...extra].sort((a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0);\n\t\t\tfor (const missingFinding of sortedMissing) {\n\t\t\t\tif (renamedMissing.has(missingFinding)) continue;\n\t\t\t\tif (missingFinding.node.prefix === void 0) continue;\n\t\t\t\tconst candidate = sortedExtras.find((extraFinding) => !renamedExtras.has(extraFinding) && extraFinding.schemaForTable === missingFinding.schemaForTable && extraFinding.node.tableName === missingFinding.node.tableName && missingFinding.node.contentEquals(extraFinding.node));\n\t\t\t\tif (candidate === void 0) continue;\n\t\t\t\trenamedExtras.add(candidate);\n\t\t\t\trenamedMissing.add(missingFinding);\n\t\t\t\tcalls.push(new RenamePostgresRlsPolicyCall(missingFinding.schemaForTable, missingFinding.node.tableName, candidate.node.name, missingFinding.node.name));\n\t\t\t}\n\t\t}\n\t\tfor (const finding of changed) {\n\t\t\tconst replacement = {\n\t\t\t\tdrop: new DropPostgresRlsPolicyCall(finding.schemaForTable, finding.node.tableName, finding.node.name),\n\t\t\t\tcreate: new CreatePostgresRlsPolicyCall(finding.schemaForTable, finding.node.tableName, policyNodeToContractPolicy(finding.node))\n\t\t\t};\n\t\t\tconst graded = gradePolicyReplacement(replacement, options.contract, options.policy.allowedOperationClasses);\n\t\t\tif (graded.disposition === \"suppress\") {\n\t\t\t\tsuppressions.push(graded.record);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (graded.disposition === \"conflict\") {\n\t\t\t\tconflicts.push(graded.conflict);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tcalls.push(replacement.drop);\n\t\t\tcalls.push(replacement.create);\n\t\t}\n\t\tfor (const finding of missing) {\n\t\t\tif (renamedMissing.has(finding)) continue;\n\t\t\tcalls.push(new CreatePostgresRlsPolicyCall(finding.schemaForTable, finding.node.tableName, policyNodeToContractPolicy(finding.node)));\n\t\t}\n\t\tif (allowsDestructive) for (const finding of extra) {\n\t\t\tif (renamedExtras.has(finding)) continue;\n\t\t\tcalls.push(new DropPostgresRlsPolicyCall(finding.schemaForTable, finding.node.tableName, finding.node.name));\n\t\t}\n\t\treturn {\n\t\t\tcalls,\n\t\t\tconflicts,\n\t\t\tsuppressions\n\t\t};\n\t}\n\tensureAdditivePolicy(policy) {\n\t\tif (!policy.allowedOperationClasses.includes(\"additive\")) return plannerFailure([{\n\t\t\tkind: \"unsupportedOperation\",\n\t\t\tsummary: \"Migration planner requires additive operations be allowed\",\n\t\t\twhy: \"The planner requires the \\\"additive\\\" operation class to be allowed in the policy.\"\n\t\t}]);\n\t\treturn null;\n\t}\n};\n/**\n* A diff issue whose node is an RLS policy — the structural half of the one\n* combined tree diff, routed to `planPostgresSchemaDiff` instead of\n* `planIssues`.\n*/\nfunction isPolicyDiffIssue(issue) {\n\tconst node = issue.expected ?? issue.actual;\n\treturn node !== void 0 && PostgresPolicySchemaNode.is(node);\n}\n/**\n* Drops a `not-expected` issue when it is a whole extra storage entity (a table\n* or a native enum) that some space in the composition owns. Each such node\n* yields its own storage coordinate (see {@link postgresNodeStorageCoordinate}),\n* so `declaresEntity` answers over the whole composition on one uniform\n* coordinate: a positive answer means a sibling owns this entity here — leave\n* it; a negative answer means a genuine orphan — drop it. A node with no storage\n* coordinate (a namespace, or a deeper column/constraint drift on an owned\n* table) is this space's own and is always kept. No oracle ⇒ keep everything.\n*/\nfunction retainUnownedExtras(issues, ownership, contract) {\n\tif (ownership === void 0) return issues;\n\treturn issues.filter((issue) => {\n\t\tif (issueOutcome(issue) !== \"not-expected\") return true;\n\t\tconst node = issueNode(issue);\n\t\tif (node === void 0) return true;\n\t\tconst coordinate = postgresNodeStorageCoordinate(node);\n\t\tif (coordinate === void 0) return true;\n\t\tconst ddlSchemaName = issueSchemaName(issue);\n\t\tif (ddlSchemaName === void 0) return true;\n\t\tconst namespaceId = resolveNamespaceIdForDdlSchema(contract, ddlSchemaName);\n\t\treturn !ownership.declaresEntity({\n\t\t\tnamespaceId,\n\t\t\t...coordinate\n\t\t});\n\t});\n}\n/**\n* Returns the one namespace node the relational strategy layer probes for\n* live-table existence and reads codec-hook context off — the namespace\n* matching the planner's resolved schema name, or the first namespace when\n* none matches. `undefined` when the tree has no namespaces, so the strategy\n* context uses its empty-schema default.\n*\n* The relational strategies key tables by bare name, so they can only probe one\n* namespace at a time; probing across every namespace at once is future work.\n*\n* Returns the real `PostgresNamespaceSchemaNode` reference rather than a\n* projection: `storageTypePlanCallStrategy` hands this same value to codec\n* `planTypeOperations` hooks as `schema`, and hooks read the Postgres-specific\n* `nativeEnums` field off it (via `PostgresNamespaceSchemaNode.is`) to decide\n* whether a native enum type already exists — a projection that only copies\n* `tables` would silently drop that signal. `StrategyContext.schema`'s\n* declared type (`SqlSchemaIR`, shared with SQLite's flat shape) doesn't\n* capture this, so the return is `blindCast` the same way `namespaceSchemaNodes`\n* in the family's relational walk already treats a namespace node as a\n* structurally-`SqlSchemaIR`-shaped value.\n*/\nfunction relationalNamespaceNode(schema, schemaName) {\n\tconst namespaceNodes = Object.values(schema.namespaces);\n\tconst namespaceNode = namespaceNodes.find((node) => node.schemaName === schemaName) ?? namespaceNodes[0];\n\tif (namespaceNode === void 0) return void 0;\n\treturn blindCast(namespaceNode);\n}\n/**\n* Grades a {@link PolicyReplacement} as one unit against the table's\n* control policy, BEFORE the pair becomes calls or a conflict. This runs\n* ahead of `partitionCallsByControlPolicy`, which later re-grades the\n* surviving calls per-call — a no-op here, since only managed units\n* survive this grading.\n*\n* A replacement is deliberately STRICTER than the shared\n* `callAllowedUnderControlPolicy` rule: `tolerated` permits whole-object\n* creation, but a replacement's create is the second half of a repair of\n* an existing object, not a new object — so ANY non-managed control\n* (external, observed, tolerated) suppresses the whole unit. Drift on an\n* object the plan does not manage is reported, never repaired; the\n* suppression subject names the drifted policy (`rlsPolicy`) so the\n* report says which policy drifted, matching the conflict path's\n* `location.rlsPolicy`.\n*/\nfunction gradePolicyReplacement(replacement, contract, allowedOperationClasses) {\n\tconst subject = resolvePostgresCallControlPolicySubject(replacement.drop, contract);\n\tconst controlPolicy = controlPolicyForCall(subject, contract.defaultControlPolicy);\n\tif (controlPolicy !== \"managed\") return {\n\t\tdisposition: \"suppress\",\n\t\trecord: {\n\t\t\tsubject: subject === void 0 ? void 0 : {\n\t\t\t\t...subject,\n\t\t\t\trlsPolicy: replacement.drop.policyName\n\t\t\t},\n\t\t\tpolicy: controlPolicy,\n\t\t\tfactoryName: void 0,\n\t\t\tcreatesNewObject: false\n\t\t}\n\t};\n\tif (!allowedOperationClasses.includes(\"destructive\")) return {\n\t\tdisposition: \"conflict\",\n\t\tconflict: conflictForDisallowedCall(replacement.drop, allowedOperationClasses)\n\t};\n\treturn { disposition: \"plan\" };\n}\n/**\n* Rebuilds the `PostgresRlsPolicy` contract entity `CreatePostgresRlsPolicyCall`\n* carries (its `renderTypeScript`/`createRlsPolicy` paths serialize the whole\n* entity, `namespaceId` included). This reconstructs rather than looking the\n* original up in the contract on purpose: the diff node's `namespaceId` is the\n* *resolved DDL schema* (set when the expected tree was built), which is the\n* value the emitted op must carry; the contract-stored entity holds the raw,\n* pre-resolution coordinate, so a lookup would change the migration output.\n*/\nfunction policyNodeToContractPolicy(node) {\n\treturn new PostgresRlsPolicy({\n\t\tnaming: namingOf(node.name, node.prefix),\n\t\ttableName: node.tableName,\n\t\tnamespaceId: node.namespaceId,\n\t\toperation: node.operation,\n\t\troles: [...node.roles],\n\t\tusing: node.using,\n\t\twithCheck: node.withCheck,\n\t\tpermissive: node.permissive\n\t});\n}\n//#endregion\nexport { createPostgresMigrationPlanner as t };\n\n//# sourceMappingURL=planner-CDEcM3hy.mjs.map"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAS,qBAAqB,SAAS,aAAa;CACnD,MAAM,YAAY,QAAQ,WAAW;CACrC,IAAI,iBAAiB,SAAS,GAAG,OAAO,UAAU,cAAc,OAAO;CACvE,OAAO;AACR;;;;;;;;;;;;;;;;;AAiBA,SAAS,0BAA0B,QAAQ;CAC1C,IAAI,2BAA2B,GAAG,MAAM,GAAG,OAAO,OAAO;CACzD,OAAO,CAAC,oBAAoB;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,gCAAgC,OAAO;CAC/C,MAAM,EAAE,UAAU,WAAW;CAC7B,MAAM,WAAW,IAAI,IAAI,0BAA0B,MAAM,CAAC;CAC1D,MAAM,SAAS,CAAC;CAChB,MAAM,eAAe,OAAO,KAAK,SAAS,QAAQ,UAAU,CAA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EACJ,CAAC;CACF,CAAC;AACF;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAS,wBAAwB,QAAQ,YAAY;CACpD,MAAM,iBAAiB,OAAO,OAAO,OAAO,UAAU;CACtD,MAAM,gBAAgB,eAAe,MAAM,SAAS,KAAK,eAAe,UAAU,KAAK,eAAe;CACtG,IAAI,kBAAkB,KAAK,GAAG,OAAO,KAAK;CAC1C,OAAO,UAAU,aAAa;AAC/B;;;;;;;;;;;;;;;;;;AAkBA,SAAS,uBAAuB,aAAa,UAAU,yBAAyB;CAC/E,MAAM,UAAU,wCAAwC,YAAY,MAAM,QAAQ;CAClF,MAAM,gBAAgB,qBAAqB,SAAS,SAAS,oBAAoB;CACjF,IAAI,kBAAkB,WAAW,OAAO;EACvC,aAAa;EACb,QAAQ;GACP,SAAS,YAAY,KAAK,IAAI,KAAK,IAAI;IACtC,GAAG;IACH,WAAW,YAAY,KAAK;GAC7B;GACA,QAAQ;GACR,aAAa,KAAK;GAClB,kBAAkB;EACnB;CACD;CACA,IAAI,CAAC,wBAAwB,SAAS,aAAa,GAAG,OAAO;EAC5D,aAAa;EACb,UAAU,0BAA0B,YAAY,MAAM,uBAAuB;CAC9E;CACA,OAAO,EAAE,aAAa,OAAO;AAC9B;;;;;;;;;;AAUA,SAAS,2BAA2B,MAAM;CACzC,OAAO,IAAI,kBAAkB;EAC5B,QAAQ,SAAS,KAAK,MAAM,KAAK,MAAM;EACvC,WAAW,KAAK;EAChB,aAAa,KAAK;EAClB,WAAW,KAAK;EAChB,OAAO,CAAC,GAAG,KAAK,KAAK;EACrB,OAAO,KAAK;EACZ,WAAW,KAAK;EAChB,YAAY,KAAK;CAClB,CAAC;AACF"}
1
+ {"version":3,"file":"planner-DtwSy6w3--x0IvtI9.mjs","names":["#lowerer"],"sources":["../../../../3-targets/3-targets/postgres/dist/planner-DtwSy6w3.mjs"],"sourcesContent":["import { t as DEFAULT_NAMESPACE_ID } from \"./namespace-ids-xtp_ZY86.mjs\";\nimport { _ as PostgresRlsPolicy, r as isPostgresSchema } from \"./postgres-schema-B3t7Zr52.mjs\";\nimport { i as PostgresDatabaseSchemaNode, n as PostgresPolicySchemaNode, r as PostgresNamespaceSchemaNode } from \"./postgres-role-schema-node-B8Z5i5D-.mjs\";\nimport { t as resolveDdlSchemaForNamespaceStorage } from \"./resolve-ddl-schema-Cab6g5MC.mjs\";\nimport { t as buildPostgresPlanDiff } from \"./diff-database-schema-C9UxdmYu.mjs\";\nimport { a as resolvePostgresNodeIssueCreationFactoryName, c as issueNode, d as postgresPlannerStrategies, f as postgresNodeStorageCoordinate, i as resolvePostgresNodeIssueControlPolicySubject, l as issueSchemaName, n as resolveNamespaceIdForDdlSchema, o as coalesceSubtreeIssues, r as resolvePostgresCallControlPolicySubject, s as conflictForDisallowedCall, t as renderPostgresSuppression, u as planIssues } from \"./control-policy-BN8Ouun3.mjs\";\nimport { A as RenameIndexCall, T as DropPostgresRlsPolicyCall, j as RenamePostgresRlsPolicyCall, k as RenameCheckConstraintCall, p as CreatePostgresRlsPolicyCall } from \"./op-factory-call-CSkQdszU.mjs\";\nimport { t as TypeScriptRenderablePostgresMigration } from \"./planner-produced-postgres-migration-BResV739.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { UNBOUND_NAMESPACE_ID } from \"@internal/framework-components/ir\";\nimport { controlPolicyForCall, extractCodecControlHooks, partitionCallsByControlPolicy, partitionIssuesByControlPolicy, planFieldEventOperations, plannerFailure } from \"@internal/family-sql/control\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { namingOf, parseWireName } from \"@internal/sql-schema-ir/naming\";\nimport { SqlCheckConstraintIR, SqlIndexIR } from \"@internal/sql-schema-ir/types\";\nimport { issueOutcome } from \"@internal/framework-components/control\";\n//#region src/core/migrations/verify-postgres-namespaces.ts\n/**\n* Resolves the live-database schema name for a given namespace\n* coordinate. Mirrors `resolveDdlSchemaForNamespace` in\n* `planner-strategies.ts` so the verifier's projection and the\n* planner's projection always agree — Postgres-aware namespaces (the\n* production path) dispatch to `ddlSchemaName(storage)`, and bare\n* object payloads (used by some tests) fall back to the coordinate\n* itself.\n*/\nfunction resolveDdlSchemaName(storage, namespaceId) {\n\tconst namespace = storage.namespaces[namespaceId];\n\tif (isPostgresSchema(namespace)) return namespace.ddlSchemaName(storage);\n\treturn namespaceId;\n}\n/**\n* Reads the introspected list of schema names from the database-root schema\n* node. `existingSchemas` is database-level, so it lives on the\n* `PostgresDatabaseSchemaNode` root — not on the per-schema namespace nodes.\n*\n* Defaults to the always-present `public` schema when the node is not the\n* database root — a fresh Postgres database always carries `public` (unless an\n* operator dropped it manually), so any verifier path that runs without an\n* enriched introspection still suppresses the redundant `CREATE SCHEMA\n* \"public\"`.\n*\n* Production introspection (`PostgresControlAdapter.introspect`) is the\n* authoritative source: it queries `pg_namespace` and sets `existingSchemas`\n* on the returned root. Tests that want to assert against a richer initial\n* state construct a `PostgresDatabaseSchemaNode` explicitly.\n*/\nfunction existingSchemasFromSchema(schema) {\n\tif (PostgresDatabaseSchemaNode.is(schema)) return schema.existingSchemas;\n\treturn [DEFAULT_NAMESPACE_ID];\n}\n/**\n* Emits a `postgres-namespace` `not-found` diff issue for every\n* contract-declared Postgres namespace whose live container does not yet\n* exist. The planner prepends these (node-typed, synthesized) to the\n* relational diff issues so a multi-schema plan emits `CREATE SCHEMA`\n* before the tables that need it — a planner-only concern (verify already\n* rejects via the `not-found` table issues a missing schema already\n* produces), so this is not part of the shared diff.\n*\n* A namespace's live container is the schema returned by its\n* polymorphic `ddlSchemaName(storage)` method — named schemas resolve\n* to their own id; the unbound singleton returns `UNBOUND_NAMESPACE_ID`\n* and is skipped explicitly (late-bound namespaces have no fixed DDL\n* schema). Issues are emitted only when the resolved name is a real,\n* creatable schema (not the unbound sentinel) and is missing from the\n* introspected list. `public` is suppressed implicitly because the\n* introspection (or its sensible default) always carries it.\n*\n* Each emitted issue's path is `['database', ddlName]` — an ancestor of\n* every table path under that schema, so it must never be run through\n* `coalesceSubtreeIssues` alongside the table diff (it would swallow the\n* table-level `not-found` issues that drive `CREATE TABLE`); the planner\n* adds these AFTER coalescing the relational issues, and they are not\n* subject to sibling-space ownership scoping (mirrors the retired\n* coordinate walk, which prepended namespace issues after that filter).\n*/\nfunction verifyPostgresNamespacePresence(input) {\n\tconst { contract, schema } = input;\n\tconst existing = new Set(existingSchemasFromSchema(schema));\n\tconst issues = [];\n\tconst namespaceIds = Object.keys(contract.storage.namespaces).sort();\n\tfor (const namespaceId of namespaceIds) {\n\t\tif (namespaceId === UNBOUND_NAMESPACE_ID) continue;\n\t\tconst ddlName = resolveDdlSchemaName(contract.storage, namespaceId);\n\t\tif (ddlName === UNBOUND_NAMESPACE_ID) continue;\n\t\tif (existing.has(ddlName)) continue;\n\t\tconst namespace = new PostgresNamespaceSchemaNode({\n\t\t\tschemaName: ddlName,\n\t\t\ttables: {}\n\t\t});\n\t\tissues.push({\n\t\t\tpath: [\"database\", ddlName],\n\t\t\texpected: namespace\n\t\t});\n\t}\n\treturn issues;\n}\n//#endregion\n//#region src/core/migrations/planner.ts\nfunction createPostgresMigrationPlanner(lowerer) {\n\treturn new PostgresMigrationPlanner(lowerer);\n}\n/**\n* Postgres migration planner — a thin wrapper over `planIssues`.\n*\n* `plan()` diffs the target contract against the live schema via the one\n* differ (`buildPostgresPlanDiff`, producing node-typed `SchemaDiffIssue[]`)\n* and delegates to `planIssues` with the unified `postgresPlannerStrategies`\n* list: NOT-NULL backfill, type-change, nullable-tightening, codec-hook\n* storage types, component-declared dependency installs, and\n* shared-temp-default / empty-table-guarded NOT-NULL add-column. The same\n* strategy list runs for `migration plan`, `db update`, and `db init`;\n* behavior diverges purely on `policy.allowedOperationClasses` (the\n* data-safe strategies short-circuit when `'data'` is excluded). The issue\n* planner applies operation-class policy gates and emits a single\n* `PostgresOpFactoryCall[]` that drives both the runtime-ops view (via\n* `renderOps`) and the `renderTypeScript()` authoring surface. RLS policy\n* drift (the structural half of the same one-differ tree) is handled\n* separately via `planPostgresSchemaDiff`.\n*/\nvar PostgresMigrationPlanner = class {\n\t#lowerer;\n\tconstructor(lowerer) {\n\t\tthis.#lowerer = lowerer;\n\t}\n\tplan(options) {\n\t\treturn this.planSql(options);\n\t}\n\temptyMigration(context, spaceId) {\n\t\treturn new TypeScriptRenderablePostgresMigration([], {\n\t\t\tfrom: context.fromHash,\n\t\t\tto: context.toHash\n\t\t}, spaceId, context.snapshotsImportPath, this.#lowerer);\n\t}\n\tplanSql(options) {\n\t\tconst schemaName = options.schemaName ?? Object.keys(options.contract.storage.namespaces).find((id) => id !== UNBOUND_NAMESPACE_ID) ?? UNBOUND_NAMESPACE_ID;\n\t\tconst policyResult = this.ensureAdditivePolicy(options.policy);\n\t\tif (policyResult) return policyResult;\n\t\tPostgresDatabaseSchemaNode.assert(options.schema);\n\t\tconst { issues: rawIssues } = buildPostgresPlanDiff({\n\t\t\tcontract: options.contract,\n\t\t\tactualSchema: options.schema,\n\t\t\tframeworkComponents: options.frameworkComponents\n\t\t});\n\t\tconst policyDiffIssues = rawIssues.filter((issue) => isPolicyDiffIssue(issue));\n\t\tconst relationalDiffIssues = rawIssues.filter((issue) => !isPolicyDiffIssue(issue));\n\t\tconst strict = options.policy.allowedOperationClasses.includes(\"widening\") || options.policy.allowedOperationClasses.includes(\"destructive\");\n\t\tconst owned = retainUnownedExtras(coalesceSubtreeIssues(relationalDiffIssues), options.ownership, options.contract);\n\t\tconst gated = strict ? owned : owned.filter((issue) => issueOutcome(issue) !== \"not-expected\");\n\t\tconst schemaIssues = [...verifyPostgresNamespacePresence({\n\t\t\tcontract: options.contract,\n\t\t\tschema: options.schema\n\t\t}), ...gated];\n\t\tconst indexRenames = this.pairIndexRenames(options, schemaIssues);\n\t\tconst checkRenames = this.pairCheckRenames(options, schemaIssues);\n\t\tconst renameConsumed = /* @__PURE__ */ new Set([...indexRenames.consumed, ...checkRenames.consumed]);\n\t\tconst plannableIssues = renameConsumed.size === 0 ? schemaIssues : schemaIssues.filter((issue) => !renameConsumed.has(issue));\n\t\tconst codecHooks = extractCodecControlHooks(options.frameworkComponents);\n\t\tconst storageTypes = options.contract.storage.types ?? {};\n\t\tconst relationalSchema = relationalNamespaceNode(options.schema, schemaName);\n\t\tconst issuePartition = partitionIssuesByControlPolicy({\n\t\t\tissues: plannableIssues,\n\t\t\tcontract: options.contract,\n\t\t\tresolveControlPolicySubject: (issue) => resolvePostgresNodeIssueControlPolicySubject(issue, options.contract),\n\t\t\tresolveCreationFactoryName: resolvePostgresNodeIssueCreationFactoryName\n\t\t});\n\t\tconst result = planIssues({\n\t\t\tissues: issuePartition.plannable,\n\t\t\ttoContract: options.contract,\n\t\t\tfromContract: options.fromContract,\n\t\t\tschemaName,\n\t\t\tcodecHooks,\n\t\t\tstorageTypes,\n\t\t\t...ifDefined(\"schema\", relationalSchema),\n\t\t\tpolicy: options.policy,\n\t\t\tframeworkComponents: options.frameworkComponents,\n\t\t\tstrategies: postgresPlannerStrategies\n\t\t});\n\t\tconst schemaDiff = this.planPostgresSchemaDiff(options, policyDiffIssues);\n\t\tif (!result.ok || schemaDiff.conflicts.length > 0) return plannerFailure([...result.ok ? [] : result.failure, ...schemaDiff.conflicts]);\n\t\tconst indexRenamePartition = partitionCallsByControlPolicy({\n\t\t\tcalls: [...indexRenames.calls, ...checkRenames.calls],\n\t\t\tcontract: options.contract,\n\t\t\tresolveControlPolicySubject: (call) => resolvePostgresCallControlPolicySubject(call, options.contract),\n\t\t\tresolveFactoryName: (call) => call.factoryName\n\t\t});\n\t\tconst schemaDiffPartition = partitionCallsByControlPolicy({\n\t\t\tcalls: schemaDiff.calls,\n\t\t\tcontract: options.contract,\n\t\t\tresolveControlPolicySubject: (call) => resolvePostgresCallControlPolicySubject(call, options.contract),\n\t\t\tresolveFactoryName: (call) => call.factoryName\n\t\t});\n\t\tconst fieldEventPartition = partitionCallsByControlPolicy({\n\t\t\tcalls: blindCast(planFieldEventOperations({\n\t\t\t\tpriorContract: options.fromContract,\n\t\t\t\tnewContract: options.contract,\n\t\t\t\tcodecHooks\n\t\t\t})),\n\t\t\tcontract: options.contract,\n\t\t\tresolveControlPolicySubject: (call) => resolvePostgresCallControlPolicySubject(call, options.contract),\n\t\t\tresolveFactoryName: (call) => call.factoryName\n\t\t});\n\t\tconst calls = [\n\t\t\t...result.value.calls,\n\t\t\t...indexRenamePartition.kept,\n\t\t\t...schemaDiffPartition.kept,\n\t\t\t...fieldEventPartition.kept\n\t\t];\n\t\tconst seenWarnings = /* @__PURE__ */ new Set();\n\t\tconst warnings = [\n\t\t\t...issuePartition.suppressions,\n\t\t\t...indexRenamePartition.suppressions,\n\t\t\t...schemaDiff.suppressions,\n\t\t\t...schemaDiffPartition.suppressions,\n\t\t\t...fieldEventPartition.suppressions\n\t\t].map((record) => renderPostgresSuppression(record, options.contract)).filter((warning) => {\n\t\t\tconst key = JSON.stringify(warning);\n\t\t\tif (seenWarnings.has(key)) return false;\n\t\t\tseenWarnings.add(key);\n\t\t\treturn true;\n\t\t});\n\t\treturn Object.freeze({\n\t\t\tkind: \"success\",\n\t\t\tplan: new TypeScriptRenderablePostgresMigration(calls, {\n\t\t\t\tfrom: options.fromContract?.storage.storageHash ?? null,\n\t\t\t\tto: options.contract.storage.storageHash\n\t\t\t}, options.spaceId, options.snapshotsImportPath, this.#lowerer),\n\t\t\t...warnings.length > 0 ? { warnings: Object.freeze(warnings) } : {}\n\t\t});\n\t}\n\t/**\n\t* Rename post-pass for indexes, per `(schema, table)`, widening-only,\n\t* deterministic by sorted names — the same structure as the policy pass\n\t* below (which stays untouched: policies pair by hash only).\n\t*\n\t* Hash pairing (prefix-only renames): extras whose live names parse as\n\t* wire names, grouped by `(schema, table, hash)`; missing nodes iterated\n\t* in sorted-name order consume the sorted-name-first candidate.\n\t*\n\t* Content pairing (exact→wire convergence), after hash pairing has\n\t* consumed its matches: the remaining wire-named-missing nodes\n\t* (`prefix` defined) against the remaining extras of any name shape,\n\t* paired iff content-equal (columns ordered-strict both-defined-or-\n\t* both-undefined, `unique`/`type` strict, `options` loose, bodies\n\t* byte-equal).\n\t*\n\t* Leftovers proceed as create/drop exactly as before; without the\n\t* widening allowance the pass is skipped and pairing degrades to the\n\t* additive half, like the policy pass.\n\t*/\n\tpairIndexRenames(options, issues) {\n\t\tconst consumed = /* @__PURE__ */ new Set();\n\t\tconst calls = [];\n\t\tif (!options.policy.allowedOperationClasses.includes(\"widening\")) return {\n\t\t\tcalls,\n\t\t\tconsumed\n\t\t};\n\t\tconst missing = [];\n\t\tconst extra = [];\n\t\tfor (const issue of issues) {\n\t\t\tconst node = issueNode(issue);\n\t\t\tif (node === void 0 || !SqlIndexIR.is(node)) continue;\n\t\t\tconst ddlSchema = issue.path[1];\n\t\t\tconst tableName = issue.path[2];\n\t\t\tif (ddlSchema === void 0 || tableName === void 0) continue;\n\t\t\tif (issueOutcome(issue) === \"not-found\") missing.push({\n\t\t\t\tissue,\n\t\t\t\tnode,\n\t\t\t\tddlSchema,\n\t\t\t\ttableName\n\t\t\t});\n\t\t\telse if (issueOutcome(issue) === \"not-expected\") extra.push({\n\t\t\t\tissue,\n\t\t\t\tnode,\n\t\t\t\tddlSchema,\n\t\t\t\ttableName\n\t\t\t});\n\t\t}\n\t\tif (missing.length === 0 || extra.length === 0) return {\n\t\t\tcalls,\n\t\t\tconsumed\n\t\t};\n\t\tconst byName = (a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0;\n\t\tconst emissionSchema = (ddlSchema) => resolveNamespaceIdForDdlSchema(options.contract, ddlSchema) === UNBOUND_NAMESPACE_ID ? UNBOUND_NAMESPACE_ID : ddlSchema;\n\t\tconst pairingKey = (finding, hash) => JSON.stringify([\n\t\t\tfinding.ddlSchema,\n\t\t\tfinding.tableName,\n\t\t\thash\n\t\t]);\n\t\tconst rename = (missingFinding, candidate) => {\n\t\t\tconsumed.add(missingFinding.issue);\n\t\t\tconsumed.add(candidate.issue);\n\t\t\tcalls.push(new RenameIndexCall(emissionSchema(missingFinding.ddlSchema), missingFinding.tableName, candidate.node.name, missingFinding.node.name));\n\t\t};\n\t\tconst sortedMissing = [...missing].sort(byName);\n\t\tconst extrasByHash = /* @__PURE__ */ new Map();\n\t\tfor (const finding of extra) {\n\t\t\tconst parsed = parseWireName(finding.node.name);\n\t\t\tif (parsed === void 0) continue;\n\t\t\tconst key = pairingKey(finding, parsed.hash);\n\t\t\tconst group = extrasByHash.get(key) ?? [];\n\t\t\tgroup.push(finding);\n\t\t\textrasByHash.set(key, group);\n\t\t}\n\t\tfor (const group of extrasByHash.values()) group.sort(byName);\n\t\tfor (const missingFinding of sortedMissing) {\n\t\t\tconst parsed = parseWireName(missingFinding.node.name);\n\t\t\tif (parsed === void 0) continue;\n\t\t\tconst candidate = extrasByHash.get(pairingKey(missingFinding, parsed.hash))?.shift();\n\t\t\tif (candidate === void 0) continue;\n\t\t\trename(missingFinding, candidate);\n\t\t}\n\t\tconst sortedExtras = [...extra].sort(byName);\n\t\tfor (const missingFinding of sortedMissing) {\n\t\t\tif (consumed.has(missingFinding.issue)) continue;\n\t\t\tif (missingFinding.node.prefix === void 0) continue;\n\t\t\tconst candidate = sortedExtras.find((extraFinding) => !consumed.has(extraFinding.issue) && extraFinding.ddlSchema === missingFinding.ddlSchema && extraFinding.tableName === missingFinding.tableName && missingFinding.node.contentEquals(extraFinding.node, {\n\t\t\t\tcolumnPresence: \"matching\",\n\t\t\t\tbodies: \"verbatim\"\n\t\t\t}));\n\t\t\tif (candidate === void 0) continue;\n\t\t\trename(missingFinding, candidate);\n\t\t}\n\t\treturn {\n\t\t\tcalls,\n\t\t\tconsumed\n\t\t};\n\t}\n\t/**\n\t* Check-constraint rename post-pass: a `not-found` and a `not-expected`\n\t* check on the same table whose wire-name content hashes match but whose\n\t* prefixes differ is a prefix-only rename, and collapses into one\n\t* `ALTER TABLE … RENAME CONSTRAINT`.\n\t*\n\t* This is the index pass's hash-pairing phase and nothing else. There is\n\t* deliberately no content-pairing phase: a live check body is whatever\n\t* Postgres reprinted, so it never byte-matches the authored text, and\n\t* pairing an exact-named live check by content would bless whatever\n\t* predicate is actually live. Adoption of an old exact-named check stays\n\t* drop + add.\n\t*\n\t* Runs only when the policy allows `widening` (rename's class). Without it\n\t* the pass no-ops and the pair degrades to the slice-1 behavior: an add,\n\t* plus a drop when `destructive` is allowed too.\n\t*/\n\tpairCheckRenames(options, issues) {\n\t\tconst consumed = /* @__PURE__ */ new Set();\n\t\tconst calls = [];\n\t\tif (!options.policy.allowedOperationClasses.includes(\"widening\")) return {\n\t\t\tcalls,\n\t\t\tconsumed\n\t\t};\n\t\tconst missing = [];\n\t\tconst extra = [];\n\t\tfor (const issue of issues) {\n\t\t\tconst node = issueNode(issue);\n\t\t\tif (node === void 0 || !SqlCheckConstraintIR.is(node)) continue;\n\t\t\tconst ddlSchema = issue.path[1];\n\t\t\tconst tableName = issue.path[2];\n\t\t\tif (ddlSchema === void 0 || tableName === void 0) continue;\n\t\t\tif (issueOutcome(issue) === \"not-found\") missing.push({\n\t\t\t\tissue,\n\t\t\t\tnode,\n\t\t\t\tddlSchema,\n\t\t\t\ttableName\n\t\t\t});\n\t\t\telse if (issueOutcome(issue) === \"not-expected\") extra.push({\n\t\t\t\tissue,\n\t\t\t\tnode,\n\t\t\t\tddlSchema,\n\t\t\t\ttableName\n\t\t\t});\n\t\t}\n\t\tif (missing.length === 0 || extra.length === 0) return {\n\t\t\tcalls,\n\t\t\tconsumed\n\t\t};\n\t\tconst byName = (a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0;\n\t\tconst emissionSchema = (ddlSchema) => resolveNamespaceIdForDdlSchema(options.contract, ddlSchema) === UNBOUND_NAMESPACE_ID ? UNBOUND_NAMESPACE_ID : ddlSchema;\n\t\tconst pairingKey = (finding, hash) => JSON.stringify([\n\t\t\tfinding.ddlSchema,\n\t\t\tfinding.tableName,\n\t\t\thash\n\t\t]);\n\t\tconst sortedMissing = [...missing].sort(byName);\n\t\tconst extrasByHash = /* @__PURE__ */ new Map();\n\t\tfor (const finding of extra) {\n\t\t\tconst parsed = parseWireName(finding.node.name);\n\t\t\tif (parsed === void 0) continue;\n\t\t\tconst key = pairingKey(finding, parsed.hash);\n\t\t\tconst group = extrasByHash.get(key) ?? [];\n\t\t\tgroup.push(finding);\n\t\t\textrasByHash.set(key, group);\n\t\t}\n\t\tfor (const group of extrasByHash.values()) group.sort(byName);\n\t\tfor (const missingFinding of sortedMissing) {\n\t\t\tconst parsed = parseWireName(missingFinding.node.name);\n\t\t\tif (parsed === void 0) continue;\n\t\t\tconst candidate = extrasByHash.get(pairingKey(missingFinding, parsed.hash))?.shift();\n\t\t\tif (candidate === void 0) continue;\n\t\t\tconsumed.add(missingFinding.issue);\n\t\t\tconsumed.add(candidate.issue);\n\t\t\tcalls.push(new RenameCheckConstraintCall(emissionSchema(missingFinding.ddlSchema), missingFinding.tableName, candidate.node.name, missingFinding.node.name));\n\t\t}\n\t\treturn {\n\t\t\tcalls,\n\t\t\tconsumed\n\t\t};\n\t}\n\t/**\n\t* Maps the RLS policy findings of the one combined tree diff\n\t* (`buildPostgresPlanDiff`, already ownership-filtered) into\n\t* `CREATE POLICY` / `DROP POLICY` / `ALTER POLICY … RENAME TO` ops — a\n\t* `not-equal` finding (an exact-named policy whose content drifted)\n\t* becomes drop + create, or a disallowed-call conflict when the policy\n\t* forbids the destructive drop. It\n\t* does not re-diff — it consumes exactly the policy-node subset of the\n\t* shared diff's issues. Enablement is NOT decided here: `ENABLE`/`DISABLE\n\t* ROW LEVEL SECURITY` derive from the table's marker-driven `rlsEnabled`\n\t* attribute diff on the relational side.\n\t*\n\t* Rename post-pass (the index pass's structure): hash pairing pairs a\n\t* `not-found` and a `not-expected` policy on the SAME table whose\n\t* wire-name content hashes match but prefixes differ (prefix-only rename);\n\t* content pairing then pairs remaining wire-named-missing policies against remaining\n\t* extras of any name shape by verbatim content (the node-owned `contentEquals` —\n\t* exact→wire adoption). Multi-candidate groups pair deterministically\n\t* by sorted name; leftovers proceed as create/drop; an exact-named\n\t* missing policy never content-pairs.\n\t*\n\t* The pairing runs only when the policy allows `widening` (rename's\n\t* class). Without it (db-init's additive-only set), pairing degrades\n\t* deliberately to the additive half: the new name is CREATEd and the old\n\t* policy survives live until a widening/destructive-allowed plan runs —\n\t* emitting an ungated widening rename would only fail at the runner's\n\t* class re-enforcement.\n\t*/\n\tplanPostgresSchemaDiff(options, filteredDiffIssues) {\n\t\tconst allowsDestructive = options.policy.allowedOperationClasses.includes(\"destructive\");\n\t\tconst allowsWidening = options.policy.allowedOperationClasses.includes(\"widening\");\n\t\tconst missing = [];\n\t\tconst extra = [];\n\t\tconst changed = [];\n\t\tfor (const issue of filteredDiffIssues) if (issueOutcome(issue) === \"not-equal\") {\n\t\t\tconst expected = issue.expected;\n\t\t\tPostgresPolicySchemaNode.assert(expected);\n\t\t\tchanged.push({\n\t\t\t\tnode: expected,\n\t\t\t\tschemaForTable: resolveDdlSchemaForNamespaceStorage(options.contract.storage, expected.namespaceId)\n\t\t\t});\n\t\t} else if (issueOutcome(issue) === \"not-found\") {\n\t\t\tconst expected = issue.expected;\n\t\t\tPostgresPolicySchemaNode.assert(expected);\n\t\t\tmissing.push({\n\t\t\t\tnode: expected,\n\t\t\t\tschemaForTable: resolveDdlSchemaForNamespaceStorage(options.contract.storage, expected.namespaceId)\n\t\t\t});\n\t\t} else if (issueOutcome(issue) === \"not-expected\") {\n\t\t\tconst actual = issue.actual;\n\t\t\tPostgresPolicySchemaNode.assert(actual);\n\t\t\textra.push({\n\t\t\t\tnode: actual,\n\t\t\t\tschemaForTable: resolveDdlSchemaForNamespaceStorage(options.contract.storage, actual.namespaceId)\n\t\t\t});\n\t\t}\n\t\tconst calls = [];\n\t\tconst conflicts = [];\n\t\tconst suppressions = [];\n\t\tconst renamedExtras = /* @__PURE__ */ new Set();\n\t\tconst renamedMissing = /* @__PURE__ */ new Set();\n\t\tconst pairingKey = (finding, hash) => JSON.stringify([\n\t\t\tfinding.schemaForTable,\n\t\t\tfinding.node.tableName,\n\t\t\thash\n\t\t]);\n\t\tif (allowsWidening) {\n\t\t\tconst extrasByGroup = /* @__PURE__ */ new Map();\n\t\t\tfor (const finding of extra) {\n\t\t\t\tconst parsed = parseWireName(finding.node.name);\n\t\t\t\tif (parsed === void 0) continue;\n\t\t\t\tconst key = pairingKey(finding, parsed.hash);\n\t\t\t\tconst group = extrasByGroup.get(key) ?? [];\n\t\t\t\tgroup.push(finding);\n\t\t\t\textrasByGroup.set(key, group);\n\t\t\t}\n\t\t\tfor (const group of extrasByGroup.values()) group.sort((a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0);\n\t\t\tconst sortedMissing = [...missing].sort((a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0);\n\t\t\tfor (const missingFinding of sortedMissing) {\n\t\t\t\tconst parsed = parseWireName(missingFinding.node.name);\n\t\t\t\tif (parsed === void 0) continue;\n\t\t\t\tconst candidate = extrasByGroup.get(pairingKey(missingFinding, parsed.hash))?.shift();\n\t\t\t\tif (candidate === void 0) continue;\n\t\t\t\trenamedExtras.add(candidate);\n\t\t\t\trenamedMissing.add(missingFinding);\n\t\t\t\tcalls.push(new RenamePostgresRlsPolicyCall(missingFinding.schemaForTable, missingFinding.node.tableName, candidate.node.name, missingFinding.node.name));\n\t\t\t}\n\t\t\tconst sortedExtras = [...extra].sort((a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0);\n\t\t\tfor (const missingFinding of sortedMissing) {\n\t\t\t\tif (renamedMissing.has(missingFinding)) continue;\n\t\t\t\tif (missingFinding.node.prefix === void 0) continue;\n\t\t\t\tconst candidate = sortedExtras.find((extraFinding) => !renamedExtras.has(extraFinding) && extraFinding.schemaForTable === missingFinding.schemaForTable && extraFinding.node.tableName === missingFinding.node.tableName && missingFinding.node.contentEquals(extraFinding.node));\n\t\t\t\tif (candidate === void 0) continue;\n\t\t\t\trenamedExtras.add(candidate);\n\t\t\t\trenamedMissing.add(missingFinding);\n\t\t\t\tcalls.push(new RenamePostgresRlsPolicyCall(missingFinding.schemaForTable, missingFinding.node.tableName, candidate.node.name, missingFinding.node.name));\n\t\t\t}\n\t\t}\n\t\tfor (const finding of changed) {\n\t\t\tconst replacement = {\n\t\t\t\tdrop: new DropPostgresRlsPolicyCall(finding.schemaForTable, finding.node.tableName, finding.node.name),\n\t\t\t\tcreate: new CreatePostgresRlsPolicyCall(finding.schemaForTable, finding.node.tableName, policyNodeToContractPolicy(finding.node))\n\t\t\t};\n\t\t\tconst graded = gradePolicyReplacement(replacement, options.contract, options.policy.allowedOperationClasses);\n\t\t\tif (graded.disposition === \"suppress\") {\n\t\t\t\tsuppressions.push(graded.record);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (graded.disposition === \"conflict\") {\n\t\t\t\tconflicts.push(graded.conflict);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tcalls.push(replacement.drop);\n\t\t\tcalls.push(replacement.create);\n\t\t}\n\t\tfor (const finding of missing) {\n\t\t\tif (renamedMissing.has(finding)) continue;\n\t\t\tcalls.push(new CreatePostgresRlsPolicyCall(finding.schemaForTable, finding.node.tableName, policyNodeToContractPolicy(finding.node)));\n\t\t}\n\t\tif (allowsDestructive) for (const finding of extra) {\n\t\t\tif (renamedExtras.has(finding)) continue;\n\t\t\tcalls.push(new DropPostgresRlsPolicyCall(finding.schemaForTable, finding.node.tableName, finding.node.name));\n\t\t}\n\t\treturn {\n\t\t\tcalls,\n\t\t\tconflicts,\n\t\t\tsuppressions\n\t\t};\n\t}\n\tensureAdditivePolicy(policy) {\n\t\tif (!policy.allowedOperationClasses.includes(\"additive\")) return plannerFailure([{\n\t\t\tkind: \"unsupportedOperation\",\n\t\t\tsummary: \"Migration planner requires additive operations be allowed\",\n\t\t\twhy: \"The planner requires the \\\"additive\\\" operation class to be allowed in the policy.\"\n\t\t}]);\n\t\treturn null;\n\t}\n};\n/**\n* A diff issue whose node is an RLS policy — the structural half of the one\n* combined tree diff, routed to `planPostgresSchemaDiff` instead of\n* `planIssues`.\n*/\nfunction isPolicyDiffIssue(issue) {\n\tconst node = issue.expected ?? issue.actual;\n\treturn node !== void 0 && PostgresPolicySchemaNode.is(node);\n}\n/**\n* Drops a `not-expected` issue when it is a whole extra storage entity (a table\n* or a native enum) that some space in the composition owns. Each such node\n* yields its own storage coordinate (see {@link postgresNodeStorageCoordinate}),\n* so `declaresEntity` answers over the whole composition on one uniform\n* coordinate: a positive answer means a sibling owns this entity here — leave\n* it; a negative answer means a genuine orphan — drop it. A node with no storage\n* coordinate (a namespace, or a deeper column/constraint drift on an owned\n* table) is this space's own and is always kept. No oracle ⇒ keep everything.\n*/\nfunction retainUnownedExtras(issues, ownership, contract) {\n\tif (ownership === void 0) return issues;\n\treturn issues.filter((issue) => {\n\t\tif (issueOutcome(issue) !== \"not-expected\") return true;\n\t\tconst node = issueNode(issue);\n\t\tif (node === void 0) return true;\n\t\tconst coordinate = postgresNodeStorageCoordinate(node);\n\t\tif (coordinate === void 0) return true;\n\t\tconst ddlSchemaName = issueSchemaName(issue);\n\t\tif (ddlSchemaName === void 0) return true;\n\t\tconst namespaceId = resolveNamespaceIdForDdlSchema(contract, ddlSchemaName);\n\t\treturn !ownership.declaresEntity({\n\t\t\tnamespaceId,\n\t\t\t...coordinate\n\t\t});\n\t});\n}\n/**\n* Returns the one namespace node the relational strategy layer probes for\n* live-table existence and reads codec-hook context off — the namespace\n* matching the planner's resolved schema name, or the first namespace when\n* none matches. `undefined` when the tree has no namespaces, so the strategy\n* context uses its empty-schema default.\n*\n* The relational strategies key tables by bare name, so they can only probe one\n* namespace at a time; probing across every namespace at once is future work.\n*\n* Returns the real `PostgresNamespaceSchemaNode` reference rather than a\n* projection: `storageTypePlanCallStrategy` hands this same value to codec\n* `planTypeOperations` hooks as `schema`, and hooks read the Postgres-specific\n* `nativeEnums` field off it (via `PostgresNamespaceSchemaNode.is`) to decide\n* whether a native enum type already exists — a projection that only copies\n* `tables` would silently drop that signal. `StrategyContext.schema`'s\n* declared type (`SqlSchemaIR`, shared with SQLite's flat shape) doesn't\n* capture this, so the return is `blindCast` the same way `namespaceSchemaNodes`\n* in the family's relational walk already treats a namespace node as a\n* structurally-`SqlSchemaIR`-shaped value.\n*/\nfunction relationalNamespaceNode(schema, schemaName) {\n\tconst namespaceNodes = Object.values(schema.namespaces);\n\tconst namespaceNode = namespaceNodes.find((node) => node.schemaName === schemaName) ?? namespaceNodes[0];\n\tif (namespaceNode === void 0) return void 0;\n\treturn blindCast(namespaceNode);\n}\n/**\n* Grades a {@link PolicyReplacement} as one unit against the table's\n* control policy, BEFORE the pair becomes calls or a conflict. This runs\n* ahead of `partitionCallsByControlPolicy`, which later re-grades the\n* surviving calls per-call — a no-op here, since only managed units\n* survive this grading.\n*\n* A replacement is deliberately STRICTER than the shared\n* `callAllowedUnderControlPolicy` rule: `tolerated` permits whole-object\n* creation, but a replacement's create is the second half of a repair of\n* an existing object, not a new object — so ANY non-managed control\n* (external, observed, tolerated) suppresses the whole unit. Drift on an\n* object the plan does not manage is reported, never repaired; the\n* suppression subject names the drifted policy (`rlsPolicy`) so the\n* report says which policy drifted, matching the conflict path's\n* `location.rlsPolicy`.\n*/\nfunction gradePolicyReplacement(replacement, contract, allowedOperationClasses) {\n\tconst subject = resolvePostgresCallControlPolicySubject(replacement.drop, contract);\n\tconst controlPolicy = controlPolicyForCall(subject, contract.defaultControlPolicy);\n\tif (controlPolicy !== \"managed\") return {\n\t\tdisposition: \"suppress\",\n\t\trecord: {\n\t\t\tsubject: subject === void 0 ? void 0 : {\n\t\t\t\t...subject,\n\t\t\t\trlsPolicy: replacement.drop.policyName\n\t\t\t},\n\t\t\tpolicy: controlPolicy,\n\t\t\tfactoryName: void 0,\n\t\t\tcreatesNewObject: false\n\t\t}\n\t};\n\tif (!allowedOperationClasses.includes(\"destructive\")) return {\n\t\tdisposition: \"conflict\",\n\t\tconflict: conflictForDisallowedCall(replacement.drop, allowedOperationClasses)\n\t};\n\treturn { disposition: \"plan\" };\n}\n/**\n* Rebuilds the `PostgresRlsPolicy` contract entity `CreatePostgresRlsPolicyCall`\n* carries (its `renderTypeScript`/`createRlsPolicy` paths serialize the whole\n* entity, `namespaceId` included). This reconstructs rather than looking the\n* original up in the contract on purpose: the diff node's `namespaceId` is the\n* *resolved DDL schema* (set when the expected tree was built), which is the\n* value the emitted op must carry; the contract-stored entity holds the raw,\n* pre-resolution coordinate, so a lookup would change the migration output.\n*/\nfunction policyNodeToContractPolicy(node) {\n\treturn new PostgresRlsPolicy({\n\t\tnaming: namingOf(node.name, node.prefix),\n\t\ttableName: node.tableName,\n\t\tnamespaceId: node.namespaceId,\n\t\toperation: node.operation,\n\t\troles: [...node.roles],\n\t\tusing: node.using,\n\t\twithCheck: node.withCheck,\n\t\tpermissive: node.permissive\n\t});\n}\n//#endregion\nexport { createPostgresMigrationPlanner as t };\n\n//# sourceMappingURL=planner-DtwSy6w3.mjs.map"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAS,qBAAqB,SAAS,aAAa;CACnD,MAAM,YAAY,QAAQ,WAAW;CACrC,IAAI,iBAAiB,SAAS,GAAG,OAAO,UAAU,cAAc,OAAO;CACvE,OAAO;AACR;;;;;;;;;;;;;;;;;AAiBA,SAAS,0BAA0B,QAAQ;CAC1C,IAAI,2BAA2B,GAAG,MAAM,GAAG,OAAO,OAAO;CACzD,OAAO,CAAC,oBAAoB;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,gCAAgC,OAAO;CAC/C,MAAM,EAAE,UAAU,WAAW;CAC7B,MAAM,WAAW,IAAI,IAAI,0BAA0B,MAAM,CAAC;CAC1D,MAAM,SAAS,CAAC;CAChB,MAAM,eAAe,OAAO,KAAK,SAAS,QAAQ,UAAU,CAAC,CAAC,KAAK;CACnE,KAAK,MAAM,eAAe,cAAc;EACvC,IAAI,gBAAgB,sBAAsB;EAC1C,MAAM,UAAU,qBAAqB,SAAS,SAAS,WAAW;EAClE,IAAI,YAAY,sBAAsB;EACtC,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,eAAe,MAAM,SAAS,KAAK,eAAe,UAAU,KAAK,eAAe;CACtG,IAAI,kBAAkB,KAAK,GAAG,OAAO,KAAK;CAC1C,OAAO,UAAU,aAAa;AAC/B;;;;;;;;;;;;;;;;;;AAkBA,SAAS,uBAAuB,aAAa,UAAU,yBAAyB;CAC/E,MAAM,UAAU,wCAAwC,YAAY,MAAM,QAAQ;CAClF,MAAM,gBAAgB,qBAAqB,SAAS,SAAS,oBAAoB;CACjF,IAAI,kBAAkB,WAAW,OAAO;EACvC,aAAa;EACb,QAAQ;GACP,SAAS,YAAY,KAAK,IAAI,KAAK,IAAI;IACtC,GAAG;IACH,WAAW,YAAY,KAAK;GAC7B;GACA,QAAQ;GACR,aAAa,KAAK;GAClB,kBAAkB;EACnB;CACD;CACA,IAAI,CAAC,wBAAwB,SAAS,aAAa,GAAG,OAAO;EAC5D,aAAa;EACb,UAAU,0BAA0B,YAAY,MAAM,uBAAuB;CAC9E;CACA,OAAO,EAAE,aAAa,OAAO;AAC9B;;;;;;;;;;AAUA,SAAS,2BAA2B,MAAM;CACzC,OAAO,IAAI,kBAAkB;EAC5B,QAAQ,SAAS,KAAK,MAAM,KAAK,MAAM;EACvC,WAAW,KAAK;EAChB,aAAa,KAAK;EAClB,WAAW,KAAK;EAChB,OAAO,CAAC,GAAG,KAAK,KAAK;EACrB,OAAO,KAAK;EACZ,WAAW,KAAK;EAChB,YAAY,KAAK;CAClB,CAAC;AACF"}
@@ -246,6 +246,7 @@ var PostgresQueryable = class {
246
246
  }
247
247
  async *runQuery(request, name) {
248
248
  const client = await this.acquireClient();
249
+ let rows;
249
250
  try {
250
251
  if (!this.options.cursorDisabled) {
251
252
  const releaseLock = await acquireClientQueryLock(client);
@@ -258,10 +259,11 @@ var PostgresQueryable = class {
258
259
  releaseLock();
259
260
  }
260
261
  }
261
- for await (const row of this.executeBuffered(client, request.sql, request.params, name)) yield blindCast(row);
262
+ rows = await this.executeBuffered(client, request.sql, request.params, name);
262
263
  } finally {
263
264
  await this.releaseClient(client);
264
265
  }
266
+ for (const row of rows) yield blindCast(row);
265
267
  }
266
268
  async explain(request) {
267
269
  const text = `EXPLAIN (FORMAT JSON) ${request.sql}`;
@@ -319,7 +321,7 @@ var PostgresQueryable = class {
319
321
  await closeCursor(cursor);
320
322
  }
321
323
  }
322
- async *executeBuffered(client, sql, params, name) {
324
+ async executeBuffered(client, sql, params, name) {
323
325
  const config = {
324
326
  name,
325
327
  text: sql,
@@ -333,7 +335,7 @@ var PostgresQueryable = class {
333
335
  } finally {
334
336
  releaseLock();
335
337
  }
336
- for (const row of blindCast(result.rows)) yield row;
338
+ return blindCast(result.rows);
337
339
  }
338
340
  };
339
341
  var PostgresConnectionImpl = class extends PostgresQueryable {
@@ -680,4 +682,4 @@ const postgresRuntimeDriverDescriptor = {
680
682
  //#endregion
681
683
  export { suppressIdleConnectionErrors$1 as n, postgresRuntimeDriverDescriptor as t };
682
684
 
683
- //# sourceMappingURL=runtime-BJrfP1e8.mjs.map
685
+ //# sourceMappingURL=runtime-Di_BFzUC.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-Di_BFzUC.mjs","names":["#queue","#connection","#onRelease","#onDestroy","#txState","#onSettled","#settle","#closed","suppressIdleConnectionErrors$1","#connected","#connectionMutex","#closeWhileHoldingLease","#connectPromise","#cursorOpts","#preparedStatements","#delegate","#requireDelegate","#wrapConnection"],"sources":["../../../../3-targets/7-drivers/postgres/dist/runtime.mjs"],"sourcesContent":["import { i as postgresDriverDescriptorMeta, n as isPostgresError, r as normalizePgError, t as isAlreadyConnectedError } from \"./normalize-error-CNjgVO71.mjs\";\nimport { suppressIdleConnectionErrors, suppressIdleConnectionErrors as suppressIdleConnectionErrors$1 } from \"@internal/utils/suppress-idle-connection-errors\";\nimport { Pool, types } from \"pg\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport Cursor from \"pg-cursor\";\n//#region src/driver-error.ts\nfunction driverError(code, message, details) {\n\tconst error = new Error(message);\n\tObject.defineProperty(error, \"name\", {\n\t\tvalue: \"RuntimeError\",\n\t\tconfigurable: true\n\t});\n\treturn details === void 0 ? Object.assign(error, {\n\t\tcode,\n\t\tcategory: \"DRIVER\",\n\t\tseverity: \"error\"\n\t}) : Object.assign(error, {\n\t\tcode,\n\t\tcategory: \"DRIVER\",\n\t\tseverity: \"error\",\n\t\tdetails\n\t});\n}\n//#endregion\n//#region src/callback-to-promise.ts\nfunction callbackToPromise(fn) {\n\treturn new Promise((resolve, reject) => {\n\t\tfn((err, result) => {\n\t\t\tif (err) {\n\t\t\t\treject(err);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolve(result);\n\t\t});\n\t});\n}\n//#endregion\n//#region src/named-cursor.ts\nlet nextNamedPortalId = 1;\n/** Streaming cursor for a server-side named prepared statement. */\nvar NamedCursor = class extends Cursor {\n\tname;\n\tconstructor(opts) {\n\t\tsuper(opts.text, [...opts.values], opts.config);\n\t\tthis.name = opts.name;\n\t\tthis.submit = this.submitNamed;\n\t}\n\tsubmitNamed(connection) {\n\t\tconst self = this;\n\t\tconst conn = connection;\n\t\tself.state = \"submitted\";\n\t\tself.connection = conn;\n\t\tself._portal = `np_${nextNamedPortalId++}`;\n\t\tif (!conn.parsedStatements[this.name]) {\n\t\t\tconst parseMessage = {\n\t\t\t\ttext: self.text,\n\t\t\t\tname: this.name,\n\t\t\t\ttypes: []\n\t\t\t};\n\t\t\tconn.parse(parseMessage, true);\n\t\t}\n\t\tconst bindMessage = {\n\t\t\tportal: self._portal,\n\t\t\tstatement: this.name,\n\t\t\tvalues: self.values ?? []\n\t\t};\n\t\tconn.bind(bindMessage, true);\n\t\tconn.describe({\n\t\t\ttype: \"P\",\n\t\t\tname: self._portal\n\t\t}, true);\n\t\tconn.flush();\n\t\tif (self._conf.types) self._result._getTypeParser = self._conf.types.getTypeParser;\n\t\tconn.once(\"noData\", self._ifNoData);\n\t\tconn.once(\"rowDescription\", self._rowDescription);\n\t}\n};\n//#endregion\n//#region src/temporal-text-parsers.ts\nconst DATE_OID = 1082;\nconst TIME_OID = 1083;\nconst TIMESTAMP_OID = 1114;\nconst TIMESTAMPTZ_OID = 1184;\nconst DATE_ARRAY_OID = 1182;\nconst TIME_ARRAY_OID = 1183;\nconst TIMESTAMP_ARRAY_OID = 1115;\nconst TIMESTAMPTZ_ARRAY_OID = 1185;\nconst TEMPORAL_SCALAR_OIDS = /* @__PURE__ */ new Set([\n\tDATE_OID,\n\tTIME_OID,\n\tTIMESTAMP_OID,\n\tTIMESTAMPTZ_OID\n]);\nconst TEMPORAL_ARRAY_OIDS = /* @__PURE__ */ new Set([\n\tDATE_ARRAY_OID,\n\tTIME_ARRAY_OID,\n\tTIMESTAMP_ARRAY_OID,\n\tTIMESTAMPTZ_ARRAY_OID\n]);\nfunction getTypeParser(oid, format) {\n\treturn blindCast(types.getTypeParser)(oid, format);\n}\nfunction serverText(value) {\n\treturn value;\n}\nfunction parseTextArray(value) {\n\tif (!value) return null;\n\treturn blindCast(types.arrayParser).create(value).parse();\n}\nconst temporalTextTypes = { getTypeParser(oid, format) {\n\tif (TEMPORAL_SCALAR_OIDS.has(oid)) return serverText;\n\tif (TEMPORAL_ARRAY_OIDS.has(oid)) return parseTextArray;\n\treturn getTypeParser(oid, format);\n} };\n//#endregion\n//#region src/postgres-driver.ts\nconst DEFAULT_BATCH_SIZE = 100;\nconst DEFAULT_PREPARED_STATEMENTS = true;\nfunction createHandleAllocator() {\n\tlet next = 1;\n\treturn { mint: () => `pn_${next++}` };\n}\nfunction buildConnectionOptions(options) {\n\treturn {\n\t\t...options.cursor?.disabled ? { cursorDisabled: true } : {\n\t\t\tcursorBatchSize: options.cursor?.batchSize ?? DEFAULT_BATCH_SIZE,\n\t\t\tcursorDisabled: false\n\t\t},\n\t\tpreparedStatementsEnabled: options.preparedStatements ?? DEFAULT_PREPARED_STATEMENTS,\n\t\thandleAllocator: createHandleAllocator()\n\t};\n}\nfunction isStalePreparedStatementError(error) {\n\tif (!(error instanceof Error) || !(\"code\" in error) || typeof error.code !== \"string\") return false;\n\tconst code = error.code;\n\treturn code === \"26000\" || code === \"0A000\";\n}\nvar AsyncMutex = class {\n\t#queue = Promise.resolve();\n\tasync lock() {\n\t\tconst previous = this.#queue;\n\t\tlet releaseLock;\n\t\tthis.#queue = new Promise((resolve) => {\n\t\t\treleaseLock = resolve;\n\t\t});\n\t\tawait previous;\n\t\treturn () => {\n\t\t\treleaseLock?.();\n\t\t\treleaseLock = void 0;\n\t\t};\n\t}\n};\nconst clientQueryLocks = /* @__PURE__ */ new WeakMap();\nfunction acquireClientQueryLock(client) {\n\tlet mutex = clientQueryLocks.get(client);\n\tif (mutex === void 0) {\n\t\tmutex = new AsyncMutex();\n\t\tclientQueryLocks.set(client, mutex);\n\t}\n\treturn mutex.lock();\n}\nvar PostgresQueryable = class {\n\toptions;\n\tconstructor(options) {\n\t\tthis.options = options;\n\t}\n\tasync *query(request) {\n\t\ttry {\n\t\t\tconst preparedStatementHandle = request.preparedStatementHandle;\n\t\t\tif (preparedStatementHandle === void 0 || !this.options.preparedStatementsEnabled) {\n\t\t\t\tyield* this.runQuery(request);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst name = this.preparedStatementName(preparedStatementHandle);\n\t\t\tyield* this.withStaleHandleStreamRetry(preparedStatementHandle, name, (name) => this.runQuery(request, name));\n\t\t} catch (error) {\n\t\t\tthrow normalizePgError(error);\n\t\t}\n\t}\n\tasync execute(request) {\n\t\ttry {\n\t\t\tconst preparedStatementHandle = request.preparedStatementHandle;\n\t\t\tif (preparedStatementHandle === void 0 || !this.options.preparedStatementsEnabled) return await this.runExecute(request);\n\t\t\tconst name = this.preparedStatementName(preparedStatementHandle);\n\t\t\treturn await this.withStaleHandleRetry(preparedStatementHandle, name, (name) => this.runExecute(request, name));\n\t\t} catch (error) {\n\t\t\tthrow normalizePgError(error);\n\t\t}\n\t}\n\tpreparedStatementName(handle) {\n\t\tconst existingName = handle.get();\n\t\tif (typeof existingName === \"string\") return existingName;\n\t\tconst mintedName = this.options.handleAllocator.mint();\n\t\thandle.set(mintedName);\n\t\treturn mintedName;\n\t}\n\tasync withStaleHandleRetry(preparedStatementHandle, name, attempt) {\n\t\ttry {\n\t\t\treturn await attempt(name);\n\t\t} catch (error) {\n\t\t\tif (!isStalePreparedStatementError(error)) throw error;\n\t\t\tconst retryName = this.options.handleAllocator.mint();\n\t\t\tpreparedStatementHandle.set(retryName);\n\t\t\ttry {\n\t\t\t\treturn await attempt(retryName);\n\t\t\t} catch (retryError) {\n\t\t\t\tthrow prepareFailedError(retryError, retryName);\n\t\t\t}\n\t\t}\n\t}\n\tasync *withStaleHandleStreamRetry(preparedStatementHandle, name, attempt) {\n\t\tconst stream = await this.withStaleHandleRetry(preparedStatementHandle, name, async (name) => {\n\t\t\tconst iterator = attempt(name)[Symbol.asyncIterator]();\n\t\t\treturn {\n\t\t\t\titerator,\n\t\t\t\tfirst: await iterator.next()\n\t\t\t};\n\t\t});\n\t\tif (stream.first.done) return;\n\t\tlet streamCompleted = false;\n\t\ttry {\n\t\t\tyield stream.first.value;\n\t\t\twhile (true) {\n\t\t\t\tconst next = await stream.iterator.next();\n\t\t\t\tif (next.done) {\n\t\t\t\t\tstreamCompleted = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tyield next.value;\n\t\t\t}\n\t\t} finally {\n\t\t\tif (!streamCompleted) await stream.iterator.return?.();\n\t\t}\n\t}\n\tasync runExecute(request, name) {\n\t\tconst client = await this.acquireClient();\n\t\ttry {\n\t\t\tconst releaseLock = await acquireClientQueryLock(client);\n\t\t\ttry {\n\t\t\t\treturn { affectedRows: (await client.query({\n\t\t\t\t\tname,\n\t\t\t\t\ttext: request.sql,\n\t\t\t\t\tvalues: blindCast(request.params ?? [])\n\t\t\t\t})).rowCount ?? 0 };\n\t\t\t} finally {\n\t\t\t\treleaseLock();\n\t\t\t}\n\t\t} finally {\n\t\t\tawait this.releaseClient(client);\n\t\t}\n\t}\n\tinExplicitTransaction() {\n\t\treturn false;\n\t}\n\tasync *runQuery(request, name) {\n\t\tconst client = await this.acquireClient();\n\t\tlet rows;\n\t\ttry {\n\t\t\tif (!this.options.cursorDisabled) {\n\t\t\t\tconst releaseLock = await acquireClientQueryLock(client);\n\t\t\t\ttry {\n\t\t\t\t\tfor await (const row of this.streamWithPortalProtection(client, request, this.options.cursorBatchSize, name)) yield blindCast(row);\n\t\t\t\t\treturn;\n\t\t\t\t} catch (cursorError) {\n\t\t\t\t\tif (!(cursorError instanceof Error) || isPostgresError(cursorError)) throw cursorError;\n\t\t\t\t} finally {\n\t\t\t\t\treleaseLock();\n\t\t\t\t}\n\t\t\t}\n\t\t\trows = await this.executeBuffered(client, request.sql, request.params, name);\n\t\t} finally {\n\t\t\tawait this.releaseClient(client);\n\t\t}\n\t\tfor (const row of rows) yield blindCast(row);\n\t}\n\tasync explain(request) {\n\t\tconst text = `EXPLAIN (FORMAT JSON) ${request.sql}`;\n\t\tconst client = await this.acquireClient();\n\t\ttry {\n\t\t\tconst releaseLock = await acquireClientQueryLock(client);\n\t\t\ttry {\n\t\t\t\treturn { rows: blindCast((await client.query(text, request.params === void 0 ? void 0 : [...request.params]).catch(rethrowNormalizedError)).rows) };\n\t\t\t} finally {\n\t\t\t\treleaseLock();\n\t\t\t}\n\t\t} finally {\n\t\t\tawait this.releaseClient(client);\n\t\t}\n\t}\n\tasync *streamWithPortalProtection(client, request, cursorBatchSize, name) {\n\t\tif (this.inExplicitTransaction()) {\n\t\t\tyield* this.executeWithCursor(client, request.sql, request.params, cursorBatchSize, name);\n\t\t\treturn;\n\t\t}\n\t\tawait client.query(\"BEGIN\");\n\t\tlet streamFailed = false;\n\t\ttry {\n\t\t\tyield* this.executeWithCursor(client, request.sql, request.params, cursorBatchSize, name);\n\t\t} catch (error) {\n\t\t\tstreamFailed = true;\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tawait this.commitStreamSpan(client, streamFailed);\n\t\t}\n\t}\n\tasync commitStreamSpan(client, streamFailed) {\n\t\ttry {\n\t\t\tawait client.query(\"COMMIT\");\n\t\t} catch (commitError) {\n\t\t\tif (!streamFailed) throw commitError;\n\t\t}\n\t}\n\tasync *executeWithCursor(client, sql, params, cursorBatchSize, name) {\n\t\tconst values = blindCast(params ?? []);\n\t\tconst config = { types: temporalTextTypes };\n\t\tconst cursor = client.query(name === void 0 ? new Cursor(sql, values, config) : new NamedCursor({\n\t\t\tname,\n\t\t\ttext: sql,\n\t\t\tvalues,\n\t\t\tconfig\n\t\t}));\n\t\ttry {\n\t\t\twhile (true) {\n\t\t\t\tconst rows = await readCursor(cursor, cursorBatchSize);\n\t\t\t\tif (rows.length === 0) break;\n\t\t\t\tfor (const row of rows) yield row;\n\t\t\t}\n\t\t} finally {\n\t\t\tawait closeCursor(cursor);\n\t\t}\n\t}\n\tasync executeBuffered(client, sql, params, name) {\n\t\tconst config = {\n\t\t\tname,\n\t\t\ttext: sql,\n\t\t\tvalues: blindCast(params ?? []),\n\t\t\ttypes: temporalTextTypes\n\t\t};\n\t\tconst releaseLock = await acquireClientQueryLock(client);\n\t\tlet result;\n\t\ttry {\n\t\t\tresult = await client.query(config);\n\t\t} finally {\n\t\t\treleaseLock();\n\t\t}\n\t\treturn blindCast(result.rows);\n\t}\n};\nvar PostgresConnectionImpl = class extends PostgresQueryable {\n\t#connection;\n\t#onRelease;\n\t#onDestroy;\n\t#txState;\n\tconstructor(connection, options, onRelease, onDestroy, txState) {\n\t\tsuper(options);\n\t\tthis.#connection = connection;\n\t\tthis.#onRelease = onRelease;\n\t\tthis.#onDestroy = onDestroy;\n\t\tthis.#txState = txState ?? { open: false };\n\t}\n\tacquireClient() {\n\t\treturn Promise.resolve(this.#connection);\n\t}\n\treleaseClient(_client) {\n\t\treturn Promise.resolve();\n\t}\n\tinExplicitTransaction() {\n\t\treturn this.#txState.open;\n\t}\n\tasync beginTransaction() {\n\t\tconst releaseLock = await acquireClientQueryLock(this.#connection);\n\t\ttry {\n\t\t\tawait this.#connection.query(\"BEGIN\").catch(rethrowNormalizedError);\n\t\t} finally {\n\t\t\treleaseLock();\n\t\t}\n\t\tthis.#txState.open = true;\n\t\treturn new PostgresTransactionImpl(this.#connection, this.options, () => {\n\t\t\tthis.#txState.open = false;\n\t\t});\n\t}\n\tasync release() {\n\t\tconst conn = this.#connection;\n\t\tif (\"release\" in conn) conn.release();\n\t\tconst onRelease = this.#onRelease;\n\t\tthis.#onRelease = void 0;\n\t\tthis.#onDestroy = void 0;\n\t\tonRelease?.();\n\t}\n\tasync destroy(reason) {\n\t\tconst onDestroy = this.#onDestroy;\n\t\tconst onRelease = this.#onRelease;\n\t\tthis.#onDestroy = void 0;\n\t\tthis.#onRelease = void 0;\n\t\tconst conn = this.#connection;\n\t\tif (\"release\" in conn) {\n\t\t\tconst releaseArg = reason instanceof Error ? reason : /* @__PURE__ */ new Error(\"Connection destroyed\");\n\t\t\tconn.release(releaseArg);\n\t\t}\n\t\tif (onDestroy) await onDestroy(reason);\n\t\telse onRelease?.();\n\t}\n};\nvar PostgresTransactionImpl = class extends PostgresQueryable {\n\t#connection;\n\t#onSettled;\n\tconstructor(connection, options, onSettled) {\n\t\tsuper(options);\n\t\tthis.#connection = connection;\n\t\tthis.#onSettled = onSettled;\n\t}\n\tacquireClient() {\n\t\treturn Promise.resolve(this.#connection);\n\t}\n\treleaseClient(_client) {\n\t\treturn Promise.resolve();\n\t}\n\tinExplicitTransaction() {\n\t\treturn true;\n\t}\n\t#settle() {\n\t\tconst onSettled = this.#onSettled;\n\t\tthis.#onSettled = void 0;\n\t\tonSettled?.();\n\t}\n\tasync commit() {\n\t\tconst releaseLock = await acquireClientQueryLock(this.#connection);\n\t\ttry {\n\t\t\tawait this.#connection.query(\"COMMIT\").catch(rethrowNormalizedError);\n\t\t} finally {\n\t\t\treleaseLock();\n\t\t\tthis.#settle();\n\t\t}\n\t}\n\tasync rollback() {\n\t\tconst releaseLock = await acquireClientQueryLock(this.#connection);\n\t\ttry {\n\t\t\tawait this.#connection.query(\"ROLLBACK\").catch(rethrowNormalizedError);\n\t\t} finally {\n\t\t\treleaseLock();\n\t\t\tthis.#settle();\n\t\t}\n\t}\n};\nvar PostgresPoolDriverImpl = class extends PostgresQueryable {\n\tpool;\n\t#closed = false;\n\tconstructor(options) {\n\t\tsuper(buildConnectionOptions(options));\n\t\tthis.pool = options.connect.pool;\n\t}\n\tget state() {\n\t\treturn this.#closed ? \"closed\" : \"connected\";\n\t}\n\tasync connect(_binding) {}\n\tasync acquireConnection() {\n\t\treturn new PostgresConnectionImpl(await this.acquireClient(), this.options);\n\t}\n\tasync close() {\n\t\tif (this.#closed) return;\n\t\tthis.#closed = true;\n\t\tawait this.pool.end();\n\t}\n\tasync acquireClient() {\n\t\treturn suppressIdleConnectionErrors$1(await this.pool.connect());\n\t}\n\tasync releaseClient(client) {\n\t\tclient.release();\n\t}\n};\nvar PostgresDirectDriverImpl = class extends PostgresQueryable {\n\tdirectClient;\n\t#connectionMutex = new AsyncMutex();\n\t#closed = false;\n\t#connected = false;\n\t#connectPromise;\n\t#txState = { open: false };\n\tconstructor(options) {\n\t\tsuper(buildConnectionOptions(options));\n\t\tthis.directClient = options.connect.client;\n\t\tthis.directClient.on(\"error\", () => {\n\t\t\tthis.#closed = true;\n\t\t\tthis.#connected = false;\n\t\t});\n\t}\n\tinExplicitTransaction() {\n\t\treturn this.#txState.open;\n\t}\n\tget state() {\n\t\treturn this.#closed ? \"closed\" : \"connected\";\n\t}\n\tasync connect(_binding) {}\n\tasync acquireConnection() {\n\t\tconst releaseLease = await this.#connectionMutex.lock();\n\t\ttry {\n\t\t\treturn new PostgresConnectionImpl(await this.acquireClient(), this.options, releaseLease, async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.#closeWhileHoldingLease();\n\t\t\t\t} finally {\n\t\t\t\t\treleaseLease();\n\t\t\t\t}\n\t\t\t}, this.#txState);\n\t\t} catch (error) {\n\t\t\treleaseLease();\n\t\t\tthrow error;\n\t\t}\n\t}\n\tasync close() {\n\t\tconst releaseLease = await this.#connectionMutex.lock();\n\t\ttry {\n\t\t\tawait this.#closeWhileHoldingLease();\n\t\t} finally {\n\t\t\treleaseLease();\n\t\t}\n\t}\n\tasync #closeWhileHoldingLease() {\n\t\tif (this.#closed) return;\n\t\tthis.#closed = true;\n\t\tawait this.directClient.end();\n\t\tthis.#connected = false;\n\t}\n\tasync acquireClient() {\n\t\tif (this.#closed) throw driverError(\"DRIVER.NOT_CONNECTED\", \"Postgres connection lost or closed. Create a new client to reconnect.\");\n\t\tif (this.#connected) return this.directClient;\n\t\tif (this.#connectPromise !== void 0) {\n\t\t\tawait this.#connectPromise;\n\t\t\treturn this.directClient;\n\t\t}\n\t\tthis.#connectPromise = (async () => {\n\t\t\ttry {\n\t\t\t\tawait this.directClient.connect();\n\t\t\t} catch (error) {\n\t\t\t\tif (!isAlreadyConnectedError(error)) throw error;\n\t\t\t} finally {\n\t\t\t\tthis.#connectPromise = void 0;\n\t\t\t}\n\t\t\tthis.#connected = true;\n\t\t})();\n\t\tawait this.#connectPromise;\n\t\treturn this.directClient;\n\t}\n\tasync releaseClient(_client) {}\n};\nfunction createBoundDriverFromBinding(binding, cursorOpts, extraOpts) {\n\tconst preparedStatements = extraOpts?.preparedStatements;\n\tswitch (binding.kind) {\n\t\tcase \"url\": return new PostgresPoolDriverImpl({\n\t\t\tconnect: { pool: suppressIdleConnectionErrors$1(new Pool({\n\t\t\t\tconnectionString: binding.url,\n\t\t\t\tconnectionTimeoutMillis: 2e4,\n\t\t\t\tidleTimeoutMillis: 3e4\n\t\t\t})) },\n\t\t\tcursor: cursorOpts,\n\t\t\tpreparedStatements\n\t\t});\n\t\tcase \"pgPool\": return new PostgresPoolDriverImpl({\n\t\t\tconnect: { pool: suppressIdleConnectionErrors$1(binding.pool) },\n\t\t\tcursor: cursorOpts,\n\t\t\tpreparedStatements\n\t\t});\n\t\tcase \"pgClient\": return new PostgresDirectDriverImpl({\n\t\t\tconnect: { client: suppressIdleConnectionErrors$1(binding.client) },\n\t\t\tcursor: cursorOpts,\n\t\t\tpreparedStatements\n\t\t});\n\t}\n}\nfunction readCursor(cursor, size) {\n\treturn callbackToPromise((cb) => {\n\t\tcursor.read(size, (err, rows) => cb(err, rows));\n\t});\n}\nfunction closeCursor(cursor) {\n\treturn callbackToPromise((cb) => cursor.close(cb));\n}\nfunction rethrowNormalizedError(error) {\n\tthrow normalizePgError(error);\n}\nfunction prepareFailedError(retryError, handle) {\n\tconst cause = normalizePgError(retryError);\n\treturn Object.assign(driverError(\"DRIVER.PREPARE_FAILED\", `Prepared statement failed again after re-preparing with a fresh handle: ${cause.message}`, { handle }), { cause });\n}\n//#endregion\n//#region src/exports/runtime.ts\nconst USE_BEFORE_CONNECT_MESSAGE = \"Postgres driver not connected. Call connect(binding) before acquireConnection or execute.\";\nconst ALREADY_CONNECTED_MESSAGE = \"Postgres driver already connected. Call close() before reconnecting with a new binding.\";\nfunction unboundQuery() {\n\treturn { [Symbol.asyncIterator]() {\n\t\treturn { async next() {\n\t\t\tthrow driverError(\"DRIVER.NOT_CONNECTED\", USE_BEFORE_CONNECT_MESSAGE);\n\t\t} };\n\t} };\n}\nvar PostgresUnboundDriverImpl = class {\n\tfamilyId = \"sql\";\n\ttargetId = \"postgres\";\n\t#delegate = null;\n\t#closed = false;\n\t#cursorOpts;\n\t#preparedStatements;\n\tconstructor(options) {\n\t\tthis.#cursorOpts = options?.cursor;\n\t\tthis.#preparedStatements = options?.preparedStatements;\n\t}\n\tget state() {\n\t\tif (this.#delegate !== null) return \"connected\";\n\t\tif (this.#closed) return \"closed\";\n\t\treturn \"unbound\";\n\t}\n\t#requireDelegate() {\n\t\tconst delegate = this.#delegate;\n\t\tif (delegate === null) throw driverError(\"DRIVER.NOT_CONNECTED\", USE_BEFORE_CONNECT_MESSAGE);\n\t\treturn delegate;\n\t}\n\tasync connect(binding) {\n\t\tif (this.#delegate !== null) throw driverError(\"DRIVER.ALREADY_CONNECTED\", ALREADY_CONNECTED_MESSAGE, { bindingKind: binding.kind });\n\t\tthis.#delegate = createBoundDriverFromBinding(binding, this.#cursorOpts, { preparedStatements: this.#preparedStatements });\n\t\tthis.#closed = false;\n\t}\n\tasync acquireConnection() {\n\t\tconst delegate = this.#requireDelegate();\n\t\tconst connection = await delegate.acquireConnection();\n\t\treturn this.#wrapConnection(connection, delegate);\n\t}\n\t/**\n\t* Wraps an acquired connection so that teardown paths which close the\n\t* underlying delegate (notably `destroy()` on a pgClient binding, where\n\t* the single socket means a destroyed connection invalidates the driver)\n\t* also reset our own `#delegate` reference. Without this, a failed\n\t* transaction rollback would leave the outer unbound wrapper reporting\n\t* `connected` while routing subsequent work to an already-ended delegate.\n\t*/\n\t#wrapConnection(connection, delegate) {\n\t\tconst syncDelegateState = () => {\n\t\t\tif (this.#delegate === delegate && delegate.state === \"closed\") {\n\t\t\t\tthis.#delegate = null;\n\t\t\t\tthis.#closed = true;\n\t\t\t}\n\t\t};\n\t\tconst wrapped = {\n\t\t\tbeginTransaction: connection.beginTransaction.bind(connection),\n\t\t\tquery: connection.query.bind(connection),\n\t\t\texecute: connection.execute.bind(connection),\n\t\t\trelease: async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait connection.release();\n\t\t\t\t} finally {\n\t\t\t\t\tsyncDelegateState();\n\t\t\t\t}\n\t\t\t},\n\t\t\tdestroy: async (reason) => {\n\t\t\t\ttry {\n\t\t\t\t\tawait connection.destroy(reason);\n\t\t\t\t} finally {\n\t\t\t\t\tsyncDelegateState();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tif (connection.explain) wrapped.explain = connection.explain.bind(connection);\n\t\treturn wrapped;\n\t}\n\tasync close() {\n\t\tconst delegate = this.#delegate;\n\t\tif (delegate !== null) {\n\t\t\tthis.#delegate = null;\n\t\t\tawait delegate.close();\n\t\t}\n\t\tthis.#closed = true;\n\t}\n\tquery(request) {\n\t\tconst delegate = this.#delegate;\n\t\treturn delegate === null ? unboundQuery() : delegate.query(request);\n\t}\n\tasync execute(request) {\n\t\tconst delegate = this.#delegate;\n\t\tif (delegate === null) throw driverError(\"DRIVER.NOT_CONNECTED\", USE_BEFORE_CONNECT_MESSAGE);\n\t\treturn delegate.execute(request);\n\t}\n\tasync explain(request) {\n\t\tconst delegate = this.#requireDelegate();\n\t\tconst explain = delegate.explain;\n\t\tif (explain === void 0) throw driverError(\"DRIVER.NOT_CONNECTED\", USE_BEFORE_CONNECT_MESSAGE);\n\t\treturn explain.call(delegate, request);\n\t}\n};\nconst postgresRuntimeDriverDescriptor = {\n\t...postgresDriverDescriptorMeta,\n\tcreate(options) {\n\t\treturn new PostgresUnboundDriverImpl(options);\n\t}\n};\n//#endregion\nexport { postgresRuntimeDriverDescriptor as default, suppressIdleConnectionErrors };\n\n//# sourceMappingURL=runtime.mjs.map"],"mappings":";;;;;;AAMA,SAAS,YAAY,MAAM,SAAS,SAAS;CAC5C,MAAM,QAAQ,IAAI,MAAM,OAAO;CAC/B,OAAO,eAAe,OAAO,QAAQ;EACpC,OAAO;EACP,cAAc;CACf,CAAC;CACD,OAAO,YAAY,KAAK,IAAI,OAAO,OAAO,OAAO;EAChD;EACA,UAAU;EACV,UAAU;CACX,CAAC,IAAI,OAAO,OAAO,OAAO;EACzB;EACA,UAAU;EACV,UAAU;EACV;CACD,CAAC;AACF;AAGA,SAAS,kBAAkB,IAAI;CAC9B,OAAO,IAAI,SAAS,SAAS,WAAW;EACvC,IAAI,KAAK,WAAW;GACnB,IAAI,KAAK;IACR,OAAO,GAAG;IACV;GACD;GACA,QAAQ,MAAM;EACf,CAAC;CACF,CAAC;AACF;AAGA,IAAI,oBAAoB;;AAExB,IAAI,cAAc,cAAc,OAAO;CACtC;CACA,YAAY,MAAM;EACjB,MAAM,KAAK,MAAM,CAAC,GAAG,KAAK,MAAM,GAAG,KAAK,MAAM;EAC9C,KAAK,OAAO,KAAK;EACjB,KAAK,SAAS,KAAK;CACpB;CACA,YAAY,YAAY;EACvB,MAAM,OAAO;EACb,MAAM,OAAO;EACb,KAAK,QAAQ;EACb,KAAK,aAAa;EAClB,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KAAK,UAAU,OAAO;CACtC;AACD;AACA,MAAM,kCAAkC;CACvC,GAAG;CACH,OAAO,SAAS;EACf,OAAO,IAAI,0BAA0B,OAAO;CAC7C;AACD"}
package/dist/target.mjs CHANGED
@@ -22,16 +22,16 @@ import { n as buildColumnTypeSql, r as renderDefaultLiteral, t as buildColumnDef
22
22
  import { A as RenameIndexCall, C as DropNativeEnumTypeCall, D as EnableRowLevelSecurityCall, E as DropTableCall, F as createExtension, M as SetDefaultCall, N as SetNotNullCall, O as RawSqlCall, S as DropIndexCall, T as DropPostgresRlsPolicyCall, _ as DisableRowLevelSecurityCall, b as DropConstraintCall, c as AddUniqueCall, d as CreateIndexCall, f as CreateNativeEnumTypeCall, g as DataTransformCall, h as CreateTableCall, i as AddNativeEnumValueCall, j as RenamePostgresRlsPolicyCall, k as RenameCheckConstraintCall, l as AlterColumnTypeCall, m as CreateSchemaCall, n as AddColumnCall, o as AddNotNullColumnWithTempDefaultCall, p as CreatePostgresRlsPolicyCall, r as AddForeignKeyCall, s as AddPrimaryKeyCall, t as AddCheckConstraintCall, u as CreateExtensionCall, v as DropCheckConstraintCall, w as DropNotNullCall, x as DropDefaultCall, y as DropColumnCall } from "./op-factory-call-CSkQdszU-C43tr0rP.mjs";
23
23
  import { n as resolveIdentityValue, t as buildBuiltinIdentityValue } from "./planner-identity-values-BmHn5C6U-BYBbUAyR.mjs";
24
24
  import { i as hasUniqueConstraint, n as hasForeignKey, r as hasIndex, t as buildSchemaLookupMap } from "./planner-schema-lookup-kMIVP2y--CdO4VlnF.mjs";
25
- import { a as planIssues, t as coalesceSubtreeIssues } from "./control-policy-HgW6zNnz-Ds9U3rSS.mjs";
26
- import { n as contractToPostgresDatabaseSchemaNode, t as buildPostgresPlanDiff } from "./diff-database-schema-B27W13mM-DmRNUFyg.mjs";
25
+ import { a as planIssues, t as coalesceSubtreeIssues } from "./control-policy-BN8Ouun3-BtGYeb4f.mjs";
26
+ import { n as contractToPostgresDatabaseSchemaNode, t as buildPostgresPlanDiff } from "./diff-database-schema-C9UxdmYu-BzQjQb1e.mjs";
27
27
  import { n as PostgresContractView, t as PostgresContractSerializer } from "./postgres-contract-view-dWcpuV6T-CJPsHGox.mjs";
28
28
  import { t as dataTransform } from "./data-transform-ChZzy2dP-CxVCat_8.mjs";
29
29
  import { t as PostgresMigration } from "./postgres-migration-DRKw86P7-C1eWF86n.mjs";
30
30
  import { t as renderOps } from "./render-ops-D2vJApKB-B281fzmn.mjs";
31
31
  import { t as renderCallsToTypeScript } from "./render-typescript-Dqp1Spgn-B128r1qw.mjs";
32
32
  import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-BResV739-meZQaWcU.mjs";
33
- import { t as createPostgresMigrationPlanner } from "./planner-CDEcM3hy-Bd4_HNx3.mjs";
34
- import { t as postgresRenderDefault } from "./control-CweD3zgF.mjs";
33
+ import { t as createPostgresMigrationPlanner } from "./planner-DtwSy6w3--x0IvtI9.mjs";
34
+ import { t as postgresRenderDefault } from "./control-CNgGXxV6.mjs";
35
35
  import { a as foreignKey, c as primaryKey, i as fn, l as rawSql, n as checkExpression, o as lit, r as col, s as placeholder, t as MigrationCLI, u as unique } from "./migration-PTHAY9Cv.mjs";
36
36
  import { t as normalizeSchemaNativeType } from "./native-type-normalizer-yvd3tqv-.mjs";
37
37
  export { AddCheckConstraintCall, AddColumnAction, AddColumnCall, AddForeignKeyCall, AddNativeEnumValueCall, AddNotNullColumnWithTempDefaultCall, AddPrimaryKeyCall, AddUniqueCall, AlterColumnTypeCall, CreateExtensionCall, CreateIndexCall, CreateNativeEnumTypeCall, CreatePostgresRlsPolicyCall, CreateSchemaCall, CreateTableCall, DataTransformCall, DisableRowLevelSecurityCall, DropCheckConstraintCall, DropColumnCall, DropConstraintCall, DropDefaultAction, DropDefaultCall, DropIndexCall, DropNativeEnumTypeCall, DropNotNullCall, DropPostgresRlsPolicyCall, DropTableCall, EnableRowLevelSecurityCall, INSTANT_NOW_GENERATOR_ID, PostgresMigration as Migration, MigrationCLI, PG_BIT_CODEC_ID, PG_BOOL_CODEC_ID, PG_BYTEA_CODEC_ID, PG_CHAR_CODEC_ID, PG_DATE_STRING_CODEC_ID, PG_DATE_TEMPORAL_CODEC_ID, PG_ENUM_CODEC_ID, PG_FLOAT4_CODEC_ID, PG_FLOAT8_CODEC_ID, PG_FLOAT_CODEC_ID, PG_INET_CODEC_ID, PG_INT2_CODEC_ID, PG_INT4_CODEC_ID, PG_INT8_CODEC_ID, PG_INT8_NUMBER_CODEC_ID, PG_INTERVAL_CODEC_ID, PG_INT_CODEC_ID, PG_JSONB_CODEC_ID, PG_JSON_CODEC_ID, PG_NUMERIC_CODEC_ID, PG_TEXT_ARRAY_CODEC_ID, PG_TEXT_CODEC_ID, PG_TIMESTAMPTZ_STRING_CODEC_ID, PG_TIMESTAMPTZ_TEMPORAL_CODEC_ID, PG_TIMESTAMP_STRING_CODEC_ID, PG_TIMESTAMP_TEMPORAL_CODEC_ID, PG_TIMETZ_CODEC_ID, PG_TIME_STRING_CODEC_ID, PG_TIME_TEMPORAL_CODEC_ID, PG_UNBOUNDED_INT_CODEC_ID, PG_UUID_CODEC_ID, PG_VARBIT_CODEC_ID, PG_VARCHAR_CODEC_ID, POLICY_OPERATION_PREDICATES, PostgresAlterIndexRename, PostgresAlterPolicyRename, PostgresAlterTable, PostgresCodecDescriptor, PostgresContractSerializer, PostgresContractView, PostgresCreateIndex, PostgresCreatePolicy, PostgresCreateSchema, PostgresCreateTable, PostgresCreateType, PostgresDatabaseSchemaNode, PostgresDdlNode, PostgresDisableRowLevelSecurity, PostgresDropIndex, PostgresDropPolicy, PostgresDropType, PostgresNamespaceSchemaNode, PostgresNativeEnum, PostgresNativeEnumSchemaNode, PostgresPolicySchemaNode, PostgresRlsEnablement, PostgresRlsPolicy, PostgresRole, PostgresRoleSchemaNode, PostgresSchema, PostgresSchemaNodeKind, PostgresTableSchemaNode, PostgresTableSource, PostgresUnboundSchema, RawSqlCall, RenameCheckConstraintCall, RenameIndexCall, RenamePostgresRlsPolicyCall, SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_TEXT_CODEC_ID, SQL_VARCHAR_CODEC_ID, SetDefaultCall, SetNotNullCall, TypeScriptRenderablePostgresMigration, addColumnAction, alterTable, buildBuiltinIdentityValue, buildColumnDefaultSql, buildColumnTypeSql, buildControlTableBootstrapQueries, buildExpectedFormatType, buildPostgresCodecDescriptorRegistry, buildPostgresPlanDiff, buildSchemaLookupMap, buildSignMarkerBootstrapQueries, checkExpression, coalesceSubtreeIssues, col, columnDefaultAst, columnExistsAst, columnNullabilityAst, columnTypeAst, computeContentHash, constraintExistsAst, contractToPostgresDatabaseSchemaNode, createExtension, createPostgresMigrationPlanner, createSchema, createTable, dataTransform, definePostgresCodecs, dropDefaultAction, errorPostgresMigrationStackMissing, escapeLiteral, extensionExistsAst, fn, foreignKey, hasForeignKey, hasIndex, hasUniqueConstraint, indexExistsAst, instantNow, instantNowControlDescriptor, int4, int8, isPgEnumParams, isPostgresCodecDescriptor, isPostgresSchema, jsonb, lit, noNullValuesAst, normalizeSchemaNativeType, parsePostgresDefault, pgBitColumn, pgBoolColumn, pgCharColumn, pgEnumDescriptor, pgFloat4Column, pgFloat8Column, pgFloatColumn, pgInetColumn, pgInt2Column, pgInt4Column, pgInt8Column, pgInt8NumberColumn, pgIntColumn, pgIntervalColumn, pgJsonColumn, pgJsonbColumn, pgNumericColumn, pgTable, pgTextColumn, pgTimetzColumn, pgUnboundedIntColumn, pgUuidColumn, pgVarbitColumn, pgVarcharColumn, placeholder, planIssues, policyInputFromSerialized, postgresAggregateDescriptors, postgresCodec, postgresCodecDescriptorRegistry, postgresCodecRegistry, postgresCreateNamespace, postgresError, postgresRenderCheckExpressions, postgresRenderDefault, postgresResolveDefault, primaryKey, qualifyName, qualifyTableName, quoteIdentifier, quoteQualifiedName, rawSql, renderCallsToTypeScript, renderDefaultLiteral, renderOps, resolveDdlSchemaForNamespaceStorage, resolveIdentityValue, rlsEnabledAst, rlsPolicyExistsAst, tableExistsAst, tableIsEmptyAst, tablePrimaryKeyAst, text, textArray, timestamptz, toRegclass, unique, validateEnumValueLength };
@@ -1,3 +1,3 @@
1
1
  import { r as instantNowControlDescriptor, t as INSTANT_NOW_GENERATOR_ID } from "./authoring-Dm1jBKhq-i8FD48I-.mjs";
2
- import { n as postgresTargetDescriptor, t as postgresRenderDefault } from "./control-CweD3zgF.mjs";
2
+ import { n as postgresTargetDescriptor, t as postgresRenderDefault } from "./control-CNgGXxV6.mjs";
3
3
  export { INSTANT_NOW_GENERATOR_ID, postgresTargetDescriptor as default, instantNowControlDescriptor, postgresRenderDefault };
@@ -1,2 +1,2 @@
1
- import { t as buildPostgresPlanDiff } from "./diff-database-schema-B27W13mM-DmRNUFyg.mjs";
1
+ import { t as buildPostgresPlanDiff } from "./diff-database-schema-C9UxdmYu-BzQjQb1e.mjs";
2
2
  export { buildPostgresPlanDiff };
@@ -1,2 +1,2 @@
1
- import { a as planIssues, t as coalesceSubtreeIssues } from "./control-policy-HgW6zNnz-Ds9U3rSS.mjs";
1
+ import { a as planIssues, t as coalesceSubtreeIssues } from "./control-policy-BN8Ouun3-BtGYeb4f.mjs";
2
2
  export { coalesceSubtreeIssues, planIssues };
@@ -1,3 +1,3 @@
1
- import { n as contractToPostgresDatabaseSchemaNode } from "./diff-database-schema-B27W13mM-DmRNUFyg.mjs";
2
- import { t as createPostgresMigrationPlanner } from "./planner-CDEcM3hy-Bd4_HNx3.mjs";
1
+ import { n as contractToPostgresDatabaseSchemaNode } from "./diff-database-schema-C9UxdmYu-BzQjQb1e.mjs";
2
+ import { t as createPostgresMigrationPlanner } from "./planner-DtwSy6w3--x0IvtI9.mjs";
3
3
  export { contractToPostgresDatabaseSchemaNode, createPostgresMigrationPlanner };