@prisma-next/adapter-postgres 0.12.0-dev.17 → 0.12.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -13
- package/dist/{adapter-Dr2W2Syq.mjs → adapter-H8BiuXdq.mjs} +2 -4
- package/dist/adapter-H8BiuXdq.mjs.map +1 -0
- package/dist/adapter.d.mts +1 -2
- package/dist/adapter.d.mts.map +1 -1
- package/dist/adapter.mjs +1 -1
- package/dist/control.d.mts +3 -20
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +1 -58
- package/dist/control.mjs.map +1 -1
- package/dist/runtime.d.mts +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/{sql-renderer-DqVeL4hP.mjs → sql-renderer-DlZhVI9B.mjs} +16 -69
- package/dist/sql-renderer-DlZhVI9B.mjs.map +1 -0
- package/package.json +22 -22
- package/src/core/adapter.ts +1 -10
- package/src/core/control-adapter.ts +2 -98
- package/src/core/sql-renderer.ts +18 -54
- package/dist/adapter-Dr2W2Syq.mjs.map +0 -1
- package/dist/sql-renderer-DqVeL4hP.mjs.map +0 -1
- package/src/core/ddl-renderer.ts +0 -73
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Provide PostgreSQL-specific adapter implementation, codecs, and capabilities. En
|
|
|
20
20
|
|
|
21
21
|
- **Adapter Implementation**: Implement `Adapter` SPI for PostgreSQL
|
|
22
22
|
- Lower SQL ASTs to PostgreSQL dialect SQL
|
|
23
|
-
- Render
|
|
23
|
+
- Render `includeMany` as `LEFT JOIN LATERAL` with `json_agg` for nested array includes
|
|
24
24
|
- Advertise PostgreSQL capabilities (`lateral`, `jsonAgg`)
|
|
25
25
|
- Normalize PostgreSQL EXPLAIN output
|
|
26
26
|
- Map PostgreSQL errors to `RuntimeError` envelope
|
|
@@ -89,8 +89,8 @@ flowchart TD
|
|
|
89
89
|
**Adapter (`adapter.ts`)**
|
|
90
90
|
- Main adapter implementation
|
|
91
91
|
- Lowers SQL ASTs to PostgreSQL SQL
|
|
92
|
-
- Renders joins (INNER, LEFT, RIGHT, FULL
|
|
93
|
-
- Renders
|
|
92
|
+
- Renders joins (INNER, LEFT, RIGHT, FULL) with ON conditions
|
|
93
|
+
- Renders `includeMany` as `LEFT JOIN LATERAL` with `json_agg` for nested array includes
|
|
94
94
|
- Renders DML operations (INSERT, UPDATE, DELETE) with RETURNING clauses
|
|
95
95
|
- Advertises PostgreSQL capabilities (`lateral`, `jsonAgg`, `returning`)
|
|
96
96
|
- Maps PostgreSQL errors to `RuntimeError`
|
|
@@ -191,8 +191,8 @@ The adapter declares the following PostgreSQL capabilities:
|
|
|
191
191
|
|
|
192
192
|
- **`orderBy: true`** - Supports ORDER BY clauses
|
|
193
193
|
- **`limit: true`** - Supports LIMIT clauses
|
|
194
|
-
- **`lateral: true`** - Supports LATERAL joins
|
|
195
|
-
- **`jsonAgg: true`** - Supports JSON aggregation functions (`json_agg`)
|
|
194
|
+
- **`lateral: true`** - Supports LATERAL joins for `includeMany` nested array includes
|
|
195
|
+
- **`jsonAgg: true`** - Supports JSON aggregation functions (`json_agg`) for `includeMany`
|
|
196
196
|
- **`returning: true`** - Supports RETURNING clauses for DML operations (INSERT, UPDATE, DELETE)
|
|
197
197
|
- **`sql.enums: true`** - Supports contract-defined enum storage types
|
|
198
198
|
|
|
@@ -205,22 +205,29 @@ The capabilities on the descriptor must match the capabilities in code. If they
|
|
|
205
205
|
|
|
206
206
|
See `docs/reference/capabilities.md` and `docs/architecture docs/subsystems/5. Adapters & Targets.md` for details.
|
|
207
207
|
|
|
208
|
-
##
|
|
208
|
+
## includeMany Support
|
|
209
209
|
|
|
210
|
-
The
|
|
210
|
+
The adapter supports `includeMany` for nested array includes using PostgreSQL's `LATERAL` joins and `json_agg`:
|
|
211
211
|
|
|
212
|
-
|
|
213
|
-
-
|
|
214
|
-
-
|
|
212
|
+
**Lowering Strategy:**
|
|
213
|
+
- Renders `includeMany` as `LEFT JOIN LATERAL` with a subquery that uses `json_agg(json_build_object(...))` to aggregate child rows into a JSON array
|
|
214
|
+
- The ON condition from the include is moved into the WHERE clause of the lateral subquery
|
|
215
|
+
- When both `ORDER BY` and `LIMIT` are present, wraps the query in an inner SELECT that projects individual columns with aliases, then uses `json_agg(row_to_json(sub.*))` on the result
|
|
216
|
+
- Uses different aliases for the table (`{alias}_lateral`) and column (`{alias}`) to avoid ambiguity
|
|
217
|
+
|
|
218
|
+
**Capabilities Required:**
|
|
219
|
+
- `lateral: true` - Enables LATERAL join support
|
|
220
|
+
- `jsonAgg: true` - Enables `json_agg` function support
|
|
215
221
|
|
|
216
222
|
**Example SQL Output:**
|
|
217
223
|
```sql
|
|
218
|
-
SELECT "user"."id" AS "id",
|
|
224
|
+
SELECT "user"."id" AS "id", "posts_lateral"."posts" AS "posts"
|
|
225
|
+
FROM "user"
|
|
226
|
+
LEFT JOIN LATERAL (
|
|
219
227
|
SELECT json_agg(json_build_object('id', "post"."id", 'title', "post"."title")) AS "posts"
|
|
220
228
|
FROM "post"
|
|
221
229
|
WHERE "user"."id" = "post"."userId"
|
|
222
|
-
) AS "
|
|
223
|
-
FROM "user"
|
|
230
|
+
) AS "posts_lateral" ON true
|
|
224
231
|
```
|
|
225
232
|
|
|
226
233
|
## DML Operations with RETURNING
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { n as createPostgresBuiltinCodecLookup, t as renderLoweredSql } from "./sql-renderer-DlZhVI9B.mjs";
|
|
2
2
|
import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
|
|
3
|
-
import { isDdlNode } from "@prisma-next/sql-relational-core/ast";
|
|
4
3
|
import { parseContractMarkerRow } from "@prisma-next/sql-runtime";
|
|
5
4
|
//#region src/core/adapter.ts
|
|
6
5
|
const defaultCapabilities = Object.freeze({
|
|
@@ -34,7 +33,6 @@ var PostgresAdapterImpl = class {
|
|
|
34
33
|
});
|
|
35
34
|
}
|
|
36
35
|
lower(ast, context) {
|
|
37
|
-
if (isDdlNode(ast)) return renderLoweredDdl(ast);
|
|
38
36
|
return renderLoweredSql(ast, context.contract, this.codecLookup);
|
|
39
37
|
}
|
|
40
38
|
};
|
|
@@ -64,4 +62,4 @@ function createPostgresAdapter(options) {
|
|
|
64
62
|
//#endregion
|
|
65
63
|
export { postgresRawCodecInferer as n, createPostgresAdapter as t };
|
|
66
64
|
|
|
67
|
-
//# sourceMappingURL=adapter-
|
|
65
|
+
//# sourceMappingURL=adapter-H8BiuXdq.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-H8BiuXdq.mjs","names":[],"sources":["../src/core/adapter.ts"],"sourcesContent":["import type { CodecLookup } from '@prisma-next/framework-components/codec';\nimport { APP_SPACE_ID } from '@prisma-next/framework-components/control';\nimport type {\n Adapter,\n AdapterProfile,\n AnyQueryAst,\n LowererContext,\n MarkerReadResult,\n RawSqlLiteral,\n SqlQueryable,\n} from '@prisma-next/sql-relational-core/ast';\nimport type { RawCodecInferer } from '@prisma-next/sql-relational-core/expression';\nimport { parseContractMarkerRow } from '@prisma-next/sql-runtime';\nimport { createPostgresBuiltinCodecLookup } from './codec-lookup';\nimport { renderLoweredSql } from './sql-renderer';\nimport type { PostgresAdapterOptions, PostgresContract, PostgresLoweredStatement } from './types';\n\nconst defaultCapabilities = Object.freeze({\n postgres: {\n orderBy: true,\n limit: true,\n lateral: true,\n jsonAgg: true,\n returning: true,\n distinctOn: true,\n },\n sql: {\n enums: true,\n returning: true,\n defaultInInsert: true,\n lateral: true,\n },\n});\n\nclass PostgresAdapterImpl\n implements Adapter<AnyQueryAst, PostgresContract, PostgresLoweredStatement>\n{\n // These fields make the adapter instance structurally compatible with RuntimeAdapterInstance<'sql', 'postgres'> without introducing a runtime-plane dependency.\n readonly familyId = 'sql' as const;\n readonly targetId = 'postgres' as const;\n\n readonly profile: AdapterProfile<'postgres'>;\n private readonly codecLookup: CodecLookup;\n\n constructor(options?: PostgresAdapterOptions) {\n this.codecLookup = options?.codecLookup ?? createPostgresBuiltinCodecLookup();\n this.profile = Object.freeze({\n id: options?.profileId ?? 'postgres/default@1',\n target: 'postgres',\n capabilities: defaultCapabilities,\n readMarker: (queryable: SqlQueryable) => readPostgresMarker(queryable),\n });\n }\n\n lower(ast: AnyQueryAst, context: LowererContext<PostgresContract>): PostgresLoweredStatement {\n return renderLoweredSql(ast, context.contract, this.codecLookup);\n }\n}\n\n/** Codec-id lookup for bare-literal interpolations used by `fns.raw` on a postgres client. Contributed as the descriptor's static `rawCodecInferer` slot. */\nexport const postgresRawCodecInferer: RawCodecInferer = {\n inferCodec(value: RawSqlLiteral): string {\n switch (typeof value) {\n case 'number':\n return Number.isSafeInteger(value) && value % 1 === 0 ? 'pg/int4' : 'pg/float8';\n case 'bigint':\n return 'pg/int8';\n case 'string':\n return 'pg/text';\n case 'boolean':\n return 'pg/bool';\n case 'object':\n if (value instanceof Uint8Array) return 'pg/bytea';\n }\n throw new Error(\n 'unsupported JS value type for raw-SQL interpolation: wrap this value in `param(...)` with an explicit codec',\n );\n },\n};\n\nasync function readPostgresMarker(queryable: SqlQueryable): Promise<MarkerReadResult> {\n const exists = await queryable.query(\n 'select 1 from information_schema.tables where table_schema = $1 and table_name = $2',\n ['prisma_contract', 'marker'],\n );\n if (exists.rows.length === 0) {\n return { kind: 'no-table' };\n }\n\n const result = await queryable.query(\n 'select core_hash, profile_hash, contract_json, canonical_version, updated_at, app_tag, meta, invariants from prisma_contract.marker where space = $1',\n [APP_SPACE_ID],\n );\n const row = result.rows[0];\n if (!row) {\n return { kind: 'absent' };\n }\n // Postgres' driver hydrates `text[]` columns as native JS arrays, so the row is already in the shape the shared parser expects.\n return { kind: 'present', record: parseContractMarkerRow(row) };\n}\n\nexport function createPostgresAdapter(options?: PostgresAdapterOptions) {\n return Object.freeze(new PostgresAdapterImpl(options));\n}\n"],"mappings":";;;;AAiBA,MAAM,sBAAsB,OAAO,OAAO;CACxC,UAAU;EACR,SAAS;EACT,OAAO;EACP,SAAS;EACT,SAAS;EACT,WAAW;EACX,YAAY;CACd;CACA,KAAK;EACH,OAAO;EACP,WAAW;EACX,iBAAiB;EACjB,SAAS;CACX;AACF,CAAC;AAED,IAAM,sBAAN,MAEA;CAEE,WAAoB;CACpB,WAAoB;CAEpB;CACA;CAEA,YAAY,SAAkC;EAC5C,KAAK,cAAc,SAAS,eAAe,iCAAiC;EAC5E,KAAK,UAAU,OAAO,OAAO;GAC3B,IAAI,SAAS,aAAa;GAC1B,QAAQ;GACR,cAAc;GACd,aAAa,cAA4B,mBAAmB,SAAS;EACvE,CAAC;CACH;CAEA,MAAM,KAAkB,SAAqE;EAC3F,OAAO,iBAAiB,KAAK,QAAQ,UAAU,KAAK,WAAW;CACjE;AACF;;AAGA,MAAa,0BAA2C,EACtD,WAAW,OAA8B;CACvC,QAAQ,OAAO,OAAf;EACE,KAAK,UACH,OAAO,OAAO,cAAc,KAAK,KAAK,QAAQ,MAAM,IAAI,YAAY;EACtE,KAAK,UACH,OAAO;EACT,KAAK,UACH,OAAO;EACT,KAAK,WACH,OAAO;EACT,KAAK,UACH,IAAI,iBAAiB,YAAY,OAAO;CAC5C;CACA,MAAM,IAAI,MACR,6GACF;AACF,EACF;AAEA,eAAe,mBAAmB,WAAoD;CAKpF,KAAI,MAJiB,UAAU,MAC7B,uFACA,CAAC,mBAAmB,QAAQ,CAC9B,GACW,KAAK,WAAW,GACzB,OAAO,EAAE,MAAM,WAAW;CAO5B,MAAM,OAAM,MAJS,UAAU,MAC7B,wJACA,CAAC,YAAY,CACf,GACmB,KAAK;CACxB,IAAI,CAAC,KACH,OAAO,EAAE,MAAM,SAAS;CAG1B,OAAO;EAAE,MAAM;EAAW,QAAQ,uBAAuB,GAAG;CAAE;AAChE;AAEA,SAAgB,sBAAsB,SAAkC;CACtE,OAAO,OAAO,OAAO,IAAI,oBAAoB,OAAO,CAAC;AACvD"}
|
package/dist/adapter.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { c as PostgresContract, l as PostgresLoweredStatement, s as PostgresAdapterOptions } from "./types-B1eiuBHQ.mjs";
|
|
2
2
|
import { Adapter, AdapterProfile, AnyQueryAst, LowererContext } from "@prisma-next/sql-relational-core/ast";
|
|
3
3
|
import { RawCodecInferer } from "@prisma-next/sql-relational-core/expression";
|
|
4
|
-
import { PostgresDdlNode } from "@prisma-next/target-postgres/ddl";
|
|
5
4
|
|
|
6
5
|
//#region src/core/adapter.d.ts
|
|
7
6
|
declare class PostgresAdapterImpl implements Adapter<AnyQueryAst, PostgresContract, PostgresLoweredStatement> {
|
|
@@ -10,7 +9,7 @@ declare class PostgresAdapterImpl implements Adapter<AnyQueryAst, PostgresContra
|
|
|
10
9
|
readonly profile: AdapterProfile<'postgres'>;
|
|
11
10
|
private readonly codecLookup;
|
|
12
11
|
constructor(options?: PostgresAdapterOptions);
|
|
13
|
-
lower(ast: AnyQueryAst
|
|
12
|
+
lower(ast: AnyQueryAst, context: LowererContext<PostgresContract>): PostgresLoweredStatement;
|
|
14
13
|
}
|
|
15
14
|
/** Codec-id lookup for bare-literal interpolations used by `fns.raw` on a postgres client. Contributed as the descriptor's static `rawCodecInferer` slot. */
|
|
16
15
|
declare const postgresRawCodecInferer: RawCodecInferer;
|
package/dist/adapter.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.mts","names":[],"sources":["../src/core/adapter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"adapter.d.mts","names":[],"sources":["../src/core/adapter.ts"],"mappings":";;;;;cAkCM,mBAAA,YACO,OAAA,CAAQ,WAAA,EAAa,gBAAA,EAAkB,wBAAA;EAAA,SAGzC,QAAA;EAAA,SACA,QAAA;EAAA,SAEA,OAAA,EAAS,cAAA;EAAA,iBACD,WAAA;cAEL,OAAA,GAAU,sBAAA;EAUtB,KAAA,CAAM,GAAA,EAAK,WAAA,EAAa,OAAA,EAAS,cAAA,CAAe,gBAAA,IAAoB,wBAAA;AAAA;;cAMzD,uBAAA,EAAyB,eAkBrC;AAAA,iBAuBe,qBAAA,CAAsB,OAAA,GAAU,sBAAA,GAAsB,QAAA,CAAA,mBAAA"}
|
package/dist/adapter.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as postgresRawCodecInferer, t as createPostgresAdapter } from "./adapter-
|
|
1
|
+
import { n as postgresRawCodecInferer, t as createPostgresAdapter } from "./adapter-H8BiuXdq.mjs";
|
|
2
2
|
export { createPostgresAdapter, postgresRawCodecInferer };
|
package/dist/control.d.mts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { ControlDriverInstance } from "@prisma-next/framework-components/control";
|
|
2
|
-
import { AnyQueryAst,
|
|
2
|
+
import { AnyQueryAst, LoweredStatement, LowererContext } from "@prisma-next/sql-relational-core/ast";
|
|
3
3
|
import { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier } from "@prisma-next/target-postgres/sql-utils";
|
|
4
|
-
import { postgresColumnsCompatible } from "@prisma-next/target-postgres/column-type-compatibility";
|
|
5
4
|
import { parsePostgresDefault, parsePostgresDefault as parsePostgresDefault$1 } from "@prisma-next/target-postgres/default-normalizer";
|
|
6
5
|
import { normalizeSchemaNativeType, normalizeSchemaNativeType as normalizeSchemaNativeType$1 } from "@prisma-next/target-postgres/native-type-normalizer";
|
|
7
6
|
import { SqlControlAdapterDescriptor } from "@prisma-next/family-sql/control";
|
|
8
|
-
import {
|
|
9
|
-
import { Contract, ContractMarkerRecord, LedgerEntryRecord } from "@prisma-next/contract/types";
|
|
7
|
+
import { Contract, ContractMarkerRecord } from "@prisma-next/contract/types";
|
|
10
8
|
import { CodecLookup } from "@prisma-next/framework-components/codec";
|
|
11
9
|
import { PostgresEnumStorageEntry, SqlStorage } from "@prisma-next/sql-contract/types";
|
|
12
10
|
import { SqlControlAdapter } from "@prisma-next/family-sql/control-adapter";
|
|
@@ -40,12 +38,6 @@ declare class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
40
38
|
* before comparison with contract native types.
|
|
41
39
|
*/
|
|
42
40
|
readonly normalizeNativeType: typeof normalizeSchemaNativeType$1;
|
|
43
|
-
/**
|
|
44
|
-
* Target-supplied compatible-shape relation used under the `external`
|
|
45
|
-
* control policy. Threading the same relation the migration planner/runner
|
|
46
|
-
* use keeps runtime verify and migration verify in agreement.
|
|
47
|
-
*/
|
|
48
|
-
readonly columnsCompatible: typeof postgresColumnsCompatible;
|
|
49
41
|
/**
|
|
50
42
|
* Bridges native `PostgresEnumStorageEntry` IR walks against the Postgres
|
|
51
43
|
* introspection shape (`schema.annotations.pg.storageTypes`). Lets
|
|
@@ -54,8 +46,6 @@ declare class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
54
46
|
*/
|
|
55
47
|
readonly resolveExistingEnumValues: (schema: SqlSchemaIR, enumType: PostgresEnumStorageEntry, namespaceId: string) => readonly string[] | null;
|
|
56
48
|
readonly resolveExistingEnumValuesForContract: (contract: Contract<SqlStorage>) => (schema: SqlSchemaIR, enumType: PostgresEnumStorageEntry, namespaceId: string) => readonly string[] | null;
|
|
57
|
-
bootstrapControlTableQueries(): readonly DdlNode[];
|
|
58
|
-
bootstrapSignMarkerQueries(): readonly DdlNode[];
|
|
59
49
|
/**
|
|
60
50
|
* Lower a SQL query AST into a Postgres-flavored `{ sql, params }` payload.
|
|
61
51
|
*
|
|
@@ -64,7 +54,7 @@ declare class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
64
54
|
* and contract. Used at migration plan/emit time (e.g. by `dataTransform`)
|
|
65
55
|
* without instantiating the runtime adapter.
|
|
66
56
|
*/
|
|
67
|
-
lower(ast: AnyQueryAst
|
|
57
|
+
lower(ast: AnyQueryAst, context: LowererContext<unknown>): LoweredStatement;
|
|
68
58
|
/**
|
|
69
59
|
* Reads the contract marker from `prisma_contract.marker`. Probes
|
|
70
60
|
* `information_schema.tables` first so a fresh database (where the
|
|
@@ -81,13 +71,6 @@ declare class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
81
71
|
* map rather than raising "relation does not exist".
|
|
82
72
|
*/
|
|
83
73
|
readAllMarkers(driver: ControlDriverInstance<'sql', 'postgres'>): Promise<ReadonlyMap<string, ContractMarkerRecord>>;
|
|
84
|
-
/**
|
|
85
|
-
* Reads per-migration ledger rows for `space` from `prisma_contract.ledger`
|
|
86
|
-
* in apply order. Probes `information_schema.tables` first so a fresh
|
|
87
|
-
* database without the ledger table returns `[]` instead of raising
|
|
88
|
-
* "relation does not exist".
|
|
89
|
-
*/
|
|
90
|
-
readLedger(driver: ControlDriverInstance<'sql', 'postgres'>, space: string): Promise<readonly LedgerEntryRecord[]>;
|
|
91
74
|
/**
|
|
92
75
|
* Introspects a Postgres database schema and returns a raw SqlSchemaIR.
|
|
93
76
|
*
|
package/dist/control.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-adapter.ts","../src/exports/control.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-adapter.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;;;;;;;;cAkDa,sBAAA,YAAkC,iBAAA;EAAA,SACpC,QAAA;EAAA,SACA,QAAA;EAAA,iBAEQ,WAAA;EAiBQ;;;;;;;cARb,WAAA,GAAc,WAAA;EA8Cf;;;;EAAA,SAtCF,gBAAA,SAAgB,sBAAA;EAqDtB;;;;;EAAA,SA9CM,mBAAA,SAAmB,2BAAA;EA4LjB;;;;;;EAAA,SApLF,yBAAA,GACP,MAAA,EAAQ,WAAA,EACR,QAAA,EAAU,wBAAA,EACV,WAAA;EAAA,SASO,oCAAA,GAAwC,QAAA,EAAU,QAAA,CAAS,UAAA,OAAW,MAAA,EAAA,WAAA,EAAA,QAAA,EAAA,wBAAA,EAAA,WAAA;EA5C9D;;;;;;;;EAuDjB,KAAA,CAAM,GAAA,EAAK,WAAA,EAAa,OAAA,EAAS,cAAA,YAA0B,gBAAA;EAtBjD;;;;;;;;EAkCJ,UAAA,CACJ,MAAA,EAAQ,qBAAA,qBACR,KAAA,WACC,OAAA,CAAQ,oBAAA;EA1BoE;;;;;;EAiFzE,cAAA,CACJ,MAAA,EAAQ,qBAAA,sBACP,OAAA,CAAQ,WAAA,SAAoB,oBAAA;EAxEzB;;;;;;;;;;;;;;;;;;;;;;;;EAyJA,UAAA,CACJ,MAAA,EAAQ,qBAAA,qBACR,QAAA,YACA,MAAA,YACC,OAAA,CAAQ,WAAA;EAmHG;;;AA8ZkB;;;;ACpxBc;EDsXhC,QArFA,mBAAA;;;ACxR4C;;;;;UD6S5C,oBAAA;;;;;;UAgEA,gBAAA;;;;UA8ZA,kBAAA;AAAA;;;cC3wBV,yBAAA,EAA2B,2BAA2B"}
|
package/dist/control.mjs
CHANGED
|
@@ -1,27 +1,18 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { n as createPostgresBuiltinCodecLookup, t as renderLoweredSql } from "./sql-renderer-DlZhVI9B.mjs";
|
|
2
2
|
import { t as postgresAdapterDescriptorMeta } from "./descriptor-meta-C1wNCHkd.mjs";
|
|
3
3
|
import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
|
|
4
|
-
import { isDdlNode } from "@prisma-next/sql-relational-core/ast";
|
|
5
4
|
import { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier } from "@prisma-next/target-postgres/sql-utils";
|
|
6
5
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
7
6
|
import { PG_ENUM_CODEC_ID } from "@prisma-next/target-postgres/codec-ids";
|
|
8
7
|
import { parseMarkerRowSafely, withMarkerReadErrorHandling } from "@prisma-next/errors/execution";
|
|
9
8
|
import { parseContractMarkerRow } from "@prisma-next/family-sql/verify";
|
|
10
9
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
11
|
-
import { postgresColumnsCompatible } from "@prisma-next/target-postgres/column-type-compatibility";
|
|
12
|
-
import { buildControlTableBootstrapQueries, buildSignMarkerBootstrapQueries } from "@prisma-next/target-postgres/contract-free";
|
|
13
10
|
import { parsePostgresDefault, parsePostgresDefault as parsePostgresDefault$1 } from "@prisma-next/target-postgres/default-normalizer";
|
|
14
11
|
import { createResolveExistingEnumValues, enumStorageCompoundKey, readExistingEnumValues, readPostgresSchemaIrAnnotations } from "@prisma-next/target-postgres/enum-planning";
|
|
15
12
|
import { normalizeSchemaNativeType, normalizeSchemaNativeType as normalizeSchemaNativeType$1 } from "@prisma-next/target-postgres/native-type-normalizer";
|
|
16
13
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
17
14
|
import { timestampNowControlDescriptor } from "@prisma-next/family-sql/control";
|
|
18
15
|
import { builtinGeneratorRegistryMetadata, resolveBuiltinGeneratedColumnDescriptor } from "@prisma-next/ids";
|
|
19
|
-
//#region ../../../1-framework/3-tooling/migration/dist/exports/ledger-origin.mjs
|
|
20
|
-
function ledgerOriginFromStored(originCoreHash) {
|
|
21
|
-
if (originCoreHash === null || originCoreHash === "" || originCoreHash === "sha256:empty") return null;
|
|
22
|
-
return originCoreHash;
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
16
|
//#region src/core/enum-control-hooks.ts
|
|
26
17
|
const ENUM_INTROSPECT_QUERY = `
|
|
27
18
|
SELECT
|
|
@@ -115,7 +106,6 @@ async function introspectPostgresEnumTypes(options) {
|
|
|
115
106
|
//#endregion
|
|
116
107
|
//#region src/core/control-adapter.ts
|
|
117
108
|
const POSTGRES_MARKER_TABLE = "prisma_contract.marker";
|
|
118
|
-
const POSTGRES_LEDGER_TABLE = "prisma_contract.ledger";
|
|
119
109
|
/**
|
|
120
110
|
* Postgres control plane adapter for control-plane operations like introspection.
|
|
121
111
|
* Provides target-specific implementations for control-plane domain actions.
|
|
@@ -146,12 +136,6 @@ var PostgresControlAdapter = class {
|
|
|
146
136
|
*/
|
|
147
137
|
normalizeNativeType = normalizeSchemaNativeType$1;
|
|
148
138
|
/**
|
|
149
|
-
* Target-supplied compatible-shape relation used under the `external`
|
|
150
|
-
* control policy. Threading the same relation the migration planner/runner
|
|
151
|
-
* use keeps runtime verify and migration verify in agreement.
|
|
152
|
-
*/
|
|
153
|
-
columnsCompatible = postgresColumnsCompatible;
|
|
154
|
-
/**
|
|
155
139
|
* Bridges native `PostgresEnumStorageEntry` IR walks against the Postgres
|
|
156
140
|
* introspection shape (`schema.annotations.pg.storageTypes`). Lets
|
|
157
141
|
* the family-level schema verifier walk enum types without reaching
|
|
@@ -161,12 +145,6 @@ var PostgresControlAdapter = class {
|
|
|
161
145
|
return readExistingEnumValues(schema, namespaceId === UNBOUND_NAMESPACE_ID ? readPostgresSchemaIrAnnotations(schema).schema ?? "public" : namespaceId, enumType.nativeType);
|
|
162
146
|
};
|
|
163
147
|
resolveExistingEnumValuesForContract = (contract) => createResolveExistingEnumValues(contract.storage);
|
|
164
|
-
bootstrapControlTableQueries() {
|
|
165
|
-
return buildControlTableBootstrapQueries();
|
|
166
|
-
}
|
|
167
|
-
bootstrapSignMarkerQueries() {
|
|
168
|
-
return buildSignMarkerBootstrapQueries();
|
|
169
|
-
}
|
|
170
148
|
/**
|
|
171
149
|
* Lower a SQL query AST into a Postgres-flavored `{ sql, params }` payload.
|
|
172
150
|
*
|
|
@@ -176,7 +154,6 @@ var PostgresControlAdapter = class {
|
|
|
176
154
|
* without instantiating the runtime adapter.
|
|
177
155
|
*/
|
|
178
156
|
lower(ast, context) {
|
|
179
|
-
if (isDdlNode(ast)) return renderLoweredDdl(ast);
|
|
180
157
|
return renderLoweredSql(ast, context.contract, this.codecLookup);
|
|
181
158
|
}
|
|
182
159
|
/**
|
|
@@ -242,40 +219,6 @@ var PostgresControlAdapter = class {
|
|
|
242
219
|
return rows;
|
|
243
220
|
}
|
|
244
221
|
/**
|
|
245
|
-
* Reads per-migration ledger rows for `space` from `prisma_contract.ledger`
|
|
246
|
-
* in apply order. Probes `information_schema.tables` first so a fresh
|
|
247
|
-
* database without the ledger table returns `[]` instead of raising
|
|
248
|
-
* "relation does not exist".
|
|
249
|
-
*/
|
|
250
|
-
async readLedger(driver, space) {
|
|
251
|
-
const ledgerContext = {
|
|
252
|
-
space,
|
|
253
|
-
markerLocation: POSTGRES_LEDGER_TABLE
|
|
254
|
-
};
|
|
255
|
-
if ((await withMarkerReadErrorHandling(() => driver.query(`select 1
|
|
256
|
-
from information_schema.tables
|
|
257
|
-
where table_schema = $1 and table_name = $2`, ["prisma_contract", "ledger"]), ledgerContext)).rows.length === 0) return [];
|
|
258
|
-
return (await withMarkerReadErrorHandling(() => driver.query(`select
|
|
259
|
-
space,
|
|
260
|
-
migration_name,
|
|
261
|
-
migration_hash,
|
|
262
|
-
origin_core_hash,
|
|
263
|
-
destination_core_hash,
|
|
264
|
-
operations,
|
|
265
|
-
created_at
|
|
266
|
-
from prisma_contract.ledger
|
|
267
|
-
where space = $1
|
|
268
|
-
order by id`, [space]), ledgerContext)).rows.map((row) => ({
|
|
269
|
-
space: row.space,
|
|
270
|
-
migrationName: row.migration_name,
|
|
271
|
-
migrationHash: row.migration_hash,
|
|
272
|
-
from: ledgerOriginFromStored(row.origin_core_hash),
|
|
273
|
-
to: row.destination_core_hash,
|
|
274
|
-
appliedAt: row.created_at instanceof Date ? row.created_at : new Date(row.created_at),
|
|
275
|
-
operationCount: Array.isArray(row.operations) ? row.operations.length : 0
|
|
276
|
-
}));
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
222
|
* Introspects a Postgres database schema and returns a raw SqlSchemaIR.
|
|
280
223
|
*
|
|
281
224
|
* This is a pure schema discovery operation that queries the Postgres catalog
|