@prisma-next/adapter-postgres 0.12.0-dev.3 → 0.12.0-dev.30
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 +13 -20
- package/dist/{adapter-H8BiuXdq.mjs → adapter-Dr2W2Syq.mjs} +4 -2
- package/dist/adapter-Dr2W2Syq.mjs.map +1 -0
- package/dist/adapter.d.mts +2 -1
- package/dist/adapter.d.mts.map +1 -1
- package/dist/adapter.mjs +1 -1
- package/dist/control.d.mts +20 -3
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +61 -1
- package/dist/control.mjs.map +1 -1
- package/dist/runtime.d.mts +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/{sql-renderer-DlZhVI9B.mjs → sql-renderer-DqVeL4hP.mjs} +69 -16
- package/dist/sql-renderer-DqVeL4hP.mjs.map +1 -0
- package/package.json +22 -22
- package/src/core/adapter.ts +10 -1
- package/src/core/control-adapter.ts +101 -2
- package/src/core/ddl-renderer.ts +73 -0
- package/src/core/sql-renderer.ts +54 -18
- package/dist/adapter-H8BiuXdq.mjs.map +0 -1
- package/dist/sql-renderer-DlZhVI9B.mjs.map +0 -1
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 JSON aggregation (`json_agg`, `json_build_object`) and scalar subqueries
|
|
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) with ON conditions
|
|
93
|
-
- Renders
|
|
92
|
+
- Renders joins (INNER, LEFT, RIGHT, FULL, LATERAL) with ON conditions
|
|
93
|
+
- Renders JSON aggregation (`json_agg`, `json_build_object`) and scalar subqueries
|
|
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
|
|
195
|
+
- **`jsonAgg: true`** - Supports JSON aggregation functions (`json_agg`)
|
|
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,29 +205,22 @@ 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
|
+
## JSON Aggregation
|
|
209
209
|
|
|
210
|
-
The
|
|
210
|
+
The renderer lowers JSON-aggregation AST nodes to PostgreSQL's `json_agg`:
|
|
211
211
|
|
|
212
|
-
|
|
213
|
-
-
|
|
214
|
-
-
|
|
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
|
|
212
|
+
- `json_agg(json_build_object(...))` aggregates a row set into a JSON array of objects
|
|
213
|
+
- A scalar subquery (`SubqueryExpr`) in the SELECT list correlates against the outer row through its WHERE clause
|
|
214
|
+
- When the subquery carries an inner `ORDER BY` and `LIMIT`, its rows are wrapped in an inner SELECT, then aggregated with `json_agg(row_to_json(sub.*))`
|
|
221
215
|
|
|
222
216
|
**Example SQL Output:**
|
|
223
217
|
```sql
|
|
224
|
-
SELECT "user"."id" AS "id",
|
|
225
|
-
FROM "user"
|
|
226
|
-
LEFT JOIN LATERAL (
|
|
218
|
+
SELECT "user"."id" AS "id", (
|
|
227
219
|
SELECT json_agg(json_build_object('id', "post"."id", 'title', "post"."title")) AS "posts"
|
|
228
220
|
FROM "post"
|
|
229
221
|
WHERE "user"."id" = "post"."userId"
|
|
230
|
-
) AS "
|
|
222
|
+
) AS "posts"
|
|
223
|
+
FROM "user"
|
|
231
224
|
```
|
|
232
225
|
|
|
233
226
|
## DML Operations with RETURNING
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { n as createPostgresBuiltinCodecLookup, t as renderLoweredSql } from "./sql-renderer-
|
|
1
|
+
import { n as renderLoweredDdl, r as createPostgresBuiltinCodecLookup, t as renderLoweredSql } from "./sql-renderer-DqVeL4hP.mjs";
|
|
2
2
|
import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
|
|
3
|
+
import { isDdlNode } from "@prisma-next/sql-relational-core/ast";
|
|
3
4
|
import { parseContractMarkerRow } from "@prisma-next/sql-runtime";
|
|
4
5
|
//#region src/core/adapter.ts
|
|
5
6
|
const defaultCapabilities = Object.freeze({
|
|
@@ -33,6 +34,7 @@ var PostgresAdapterImpl = class {
|
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
lower(ast, context) {
|
|
37
|
+
if (isDdlNode(ast)) return renderLoweredDdl(ast);
|
|
36
38
|
return renderLoweredSql(ast, context.contract, this.codecLookup);
|
|
37
39
|
}
|
|
38
40
|
};
|
|
@@ -62,4 +64,4 @@ function createPostgresAdapter(options) {
|
|
|
62
64
|
//#endregion
|
|
63
65
|
export { postgresRawCodecInferer as n, createPostgresAdapter as t };
|
|
64
66
|
|
|
65
|
-
//# sourceMappingURL=adapter-
|
|
67
|
+
//# sourceMappingURL=adapter-Dr2W2Syq.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-Dr2W2Syq.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 { isDdlNode } 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 type { PostgresDdlNode } from '@prisma-next/target-postgres/ddl';\nimport { createPostgresBuiltinCodecLookup } from './codec-lookup';\nimport { renderLoweredDdl } from './ddl-renderer';\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(\n ast: AnyQueryAst | PostgresDdlNode,\n context: LowererContext<PostgresContract>,\n ): PostgresLoweredStatement {\n if (isDdlNode(ast)) {\n return renderLoweredDdl(ast);\n }\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":";;;;;AAoBA,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,MACE,KACA,SAC0B;EAC1B,IAAI,UAAU,GAAG,GACf,OAAO,iBAAiB,GAAG;EAE7B,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,6 +1,7 @@
|
|
|
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";
|
|
4
5
|
|
|
5
6
|
//#region src/core/adapter.d.ts
|
|
6
7
|
declare class PostgresAdapterImpl implements Adapter<AnyQueryAst, PostgresContract, PostgresLoweredStatement> {
|
|
@@ -9,7 +10,7 @@ declare class PostgresAdapterImpl implements Adapter<AnyQueryAst, PostgresContra
|
|
|
9
10
|
readonly profile: AdapterProfile<'postgres'>;
|
|
10
11
|
private readonly codecLookup;
|
|
11
12
|
constructor(options?: PostgresAdapterOptions);
|
|
12
|
-
lower(ast: AnyQueryAst, context: LowererContext<PostgresContract>): PostgresLoweredStatement;
|
|
13
|
+
lower(ast: AnyQueryAst | PostgresDdlNode, context: LowererContext<PostgresContract>): PostgresLoweredStatement;
|
|
13
14
|
}
|
|
14
15
|
/** Codec-id lookup for bare-literal interpolations used by `fns.raw` on a postgres client. Contributed as the descriptor's static `rawCodecInferer` slot. */
|
|
15
16
|
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":";;;;;;cAqCM,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,CACE,GAAA,EAAK,WAAA,GAAc,eAAA,EACnB,OAAA,EAAS,cAAA,CAAe,gBAAA,IACvB,wBAAA;AAAA;;cASQ,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-Dr2W2Syq.mjs";
|
|
2
2
|
export { createPostgresAdapter, postgresRawCodecInferer };
|
package/dist/control.d.mts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { ControlDriverInstance } from "@prisma-next/framework-components/control";
|
|
2
|
-
import { AnyQueryAst, LoweredStatement, LowererContext } from "@prisma-next/sql-relational-core/ast";
|
|
2
|
+
import { AnyQueryAst, DdlNode, 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";
|
|
4
5
|
import { parsePostgresDefault, parsePostgresDefault as parsePostgresDefault$1 } from "@prisma-next/target-postgres/default-normalizer";
|
|
5
6
|
import { normalizeSchemaNativeType, normalizeSchemaNativeType as normalizeSchemaNativeType$1 } from "@prisma-next/target-postgres/native-type-normalizer";
|
|
6
7
|
import { SqlControlAdapterDescriptor } from "@prisma-next/family-sql/control";
|
|
7
|
-
import {
|
|
8
|
+
import { PostgresDdlNode } from "@prisma-next/target-postgres/ddl";
|
|
9
|
+
import { Contract, ContractMarkerRecord, LedgerEntryRecord } from "@prisma-next/contract/types";
|
|
8
10
|
import { CodecLookup } from "@prisma-next/framework-components/codec";
|
|
9
11
|
import { PostgresEnumStorageEntry, SqlStorage } from "@prisma-next/sql-contract/types";
|
|
10
12
|
import { SqlControlAdapter } from "@prisma-next/family-sql/control-adapter";
|
|
@@ -38,6 +40,12 @@ declare class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
38
40
|
* before comparison with contract native types.
|
|
39
41
|
*/
|
|
40
42
|
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;
|
|
41
49
|
/**
|
|
42
50
|
* Bridges native `PostgresEnumStorageEntry` IR walks against the Postgres
|
|
43
51
|
* introspection shape (`schema.annotations.pg.storageTypes`). Lets
|
|
@@ -46,6 +54,8 @@ declare class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
46
54
|
*/
|
|
47
55
|
readonly resolveExistingEnumValues: (schema: SqlSchemaIR, enumType: PostgresEnumStorageEntry, namespaceId: string) => readonly string[] | null;
|
|
48
56
|
readonly resolveExistingEnumValuesForContract: (contract: Contract<SqlStorage>) => (schema: SqlSchemaIR, enumType: PostgresEnumStorageEntry, namespaceId: string) => readonly string[] | null;
|
|
57
|
+
bootstrapControlTableQueries(): readonly DdlNode[];
|
|
58
|
+
bootstrapSignMarkerQueries(): readonly DdlNode[];
|
|
49
59
|
/**
|
|
50
60
|
* Lower a SQL query AST into a Postgres-flavored `{ sql, params }` payload.
|
|
51
61
|
*
|
|
@@ -54,7 +64,7 @@ declare class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
54
64
|
* and contract. Used at migration plan/emit time (e.g. by `dataTransform`)
|
|
55
65
|
* without instantiating the runtime adapter.
|
|
56
66
|
*/
|
|
57
|
-
lower(ast: AnyQueryAst, context: LowererContext<unknown>): LoweredStatement;
|
|
67
|
+
lower(ast: AnyQueryAst | PostgresDdlNode, context: LowererContext<unknown>): LoweredStatement;
|
|
58
68
|
/**
|
|
59
69
|
* Reads the contract marker from `prisma_contract.marker`. Probes
|
|
60
70
|
* `information_schema.tables` first so a fresh database (where the
|
|
@@ -71,6 +81,13 @@ declare class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
71
81
|
* map rather than raising "relation does not exist".
|
|
72
82
|
*/
|
|
73
83
|
readAllMarkers(driver: ControlDriverInstance<'sql', 'postgres'>): Promise<ReadonlyMap<string, ContractMarkerRecord>>;
|
|
84
|
+
/**
|
|
85
|
+
* Reads per-migration ledger rows from `prisma_contract.ledger` in apply
|
|
86
|
+
* order. Probes `information_schema.tables` first so a fresh database
|
|
87
|
+
* without the ledger table returns `[]` instead of raising "relation does
|
|
88
|
+
* not exist".
|
|
89
|
+
*/
|
|
90
|
+
readLedger(driver: ControlDriverInstance<'sql', 'postgres'>, space?: string): Promise<readonly LedgerEntryRecord[]>;
|
|
74
91
|
/**
|
|
75
92
|
* Introspects a Postgres database schema and returns a raw SqlSchemaIR.
|
|
76
93
|
*
|
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":";;;;;;;;;;;;;;;;;;;cAiEa,sBAAA,YAAkC,iBAAA;EAAA,SACpC,QAAA;EAAA,SACA,QAAA;EAAA,iBAEQ,WAAA;EAiBQ;;;;;;;cARb,WAAA,GAAc,WAAA;EA0CqD;;;;EAAA,SAlCtE,gBAAA,SAAgB,sBAAA;EAqD0B;;;;;EAAA,SA9C1C,mBAAA,SAAmB,2BAAA;EAyHG;;;;;EAAA,SAlHtB,iBAAA,SAAiB,yBAAA;EAsQhB;;;;;;EAAA,SA9PD,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;EAG/E,4BAAA,CAAA,YAAyC,OAAA;EAIzC,0BAAA,CAAA,YAAuC,OAAA;;;;;;;;;EAYvC,KAAA,CAAM,GAAA,EAAK,WAAA,GAAc,eAAA,EAAiB,OAAA,EAAS,cAAA,YAA0B,gBAAA;EA/BpE;;;;;;;;EA8CH,UAAA,CACJ,MAAA,EAAQ,qBAAA,qBACR,KAAA,WACC,OAAA,CAAQ,oBAAA;EArCsC;;;;;;EA4F3C,cAAA,CACJ,MAAA,EAAQ,qBAAA,sBACP,OAAA,CAAQ,WAAA,SAAoB,oBAAA;EA3FU;;;;;;EA0JnC,UAAA,CACJ,MAAA,EAAQ,qBAAA,qBACR,KAAA,YACC,OAAA,UAAiB,iBAAA;EA7I+B;;;;;;;;;;;;;;;;;;;;;;;;EA8N7C,UAAA,CACJ,MAAA,EAAQ,qBAAA,qBACR,QAAA,YACA,MAAA,YACC,OAAA,CAAQ,WAAA;EADT;;;;;;;;EAAA,QA+BY,mBAAA;;;;ACpYgC;;;;UDyZhC,oBAAA;;;;;;UAgEA,gBAAA;;;;UA8ZA,kBAAA;AAAA;;;cC92BV,yBAAA,EAA2B,2BAA2B"}
|
package/dist/control.mjs
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
|
-
import { n as createPostgresBuiltinCodecLookup, t as renderLoweredSql } from "./sql-renderer-
|
|
1
|
+
import { n as renderLoweredDdl, r as createPostgresBuiltinCodecLookup, t as renderLoweredSql } from "./sql-renderer-DqVeL4hP.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";
|
|
4
5
|
import { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier } from "@prisma-next/target-postgres/sql-utils";
|
|
5
6
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
6
7
|
import { PG_ENUM_CODEC_ID } from "@prisma-next/target-postgres/codec-ids";
|
|
7
8
|
import { parseMarkerRowSafely, withMarkerReadErrorHandling } from "@prisma-next/errors/execution";
|
|
8
9
|
import { parseContractMarkerRow } from "@prisma-next/family-sql/verify";
|
|
9
10
|
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";
|
|
10
13
|
import { parsePostgresDefault, parsePostgresDefault as parsePostgresDefault$1 } from "@prisma-next/target-postgres/default-normalizer";
|
|
11
14
|
import { createResolveExistingEnumValues, enumStorageCompoundKey, readExistingEnumValues, readPostgresSchemaIrAnnotations } from "@prisma-next/target-postgres/enum-planning";
|
|
12
15
|
import { normalizeSchemaNativeType, normalizeSchemaNativeType as normalizeSchemaNativeType$1 } from "@prisma-next/target-postgres/native-type-normalizer";
|
|
13
16
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
14
17
|
import { timestampNowControlDescriptor } from "@prisma-next/family-sql/control";
|
|
15
18
|
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
|
|
16
25
|
//#region src/core/enum-control-hooks.ts
|
|
17
26
|
const ENUM_INTROSPECT_QUERY = `
|
|
18
27
|
SELECT
|
|
@@ -106,6 +115,7 @@ async function introspectPostgresEnumTypes(options) {
|
|
|
106
115
|
//#endregion
|
|
107
116
|
//#region src/core/control-adapter.ts
|
|
108
117
|
const POSTGRES_MARKER_TABLE = "prisma_contract.marker";
|
|
118
|
+
const POSTGRES_LEDGER_TABLE = "prisma_contract.ledger";
|
|
109
119
|
/**
|
|
110
120
|
* Postgres control plane adapter for control-plane operations like introspection.
|
|
111
121
|
* Provides target-specific implementations for control-plane domain actions.
|
|
@@ -136,6 +146,12 @@ var PostgresControlAdapter = class {
|
|
|
136
146
|
*/
|
|
137
147
|
normalizeNativeType = normalizeSchemaNativeType$1;
|
|
138
148
|
/**
|
|
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
|
+
/**
|
|
139
155
|
* Bridges native `PostgresEnumStorageEntry` IR walks against the Postgres
|
|
140
156
|
* introspection shape (`schema.annotations.pg.storageTypes`). Lets
|
|
141
157
|
* the family-level schema verifier walk enum types without reaching
|
|
@@ -145,6 +161,12 @@ var PostgresControlAdapter = class {
|
|
|
145
161
|
return readExistingEnumValues(schema, namespaceId === UNBOUND_NAMESPACE_ID ? readPostgresSchemaIrAnnotations(schema).schema ?? "public" : namespaceId, enumType.nativeType);
|
|
146
162
|
};
|
|
147
163
|
resolveExistingEnumValuesForContract = (contract) => createResolveExistingEnumValues(contract.storage);
|
|
164
|
+
bootstrapControlTableQueries() {
|
|
165
|
+
return buildControlTableBootstrapQueries();
|
|
166
|
+
}
|
|
167
|
+
bootstrapSignMarkerQueries() {
|
|
168
|
+
return buildSignMarkerBootstrapQueries();
|
|
169
|
+
}
|
|
148
170
|
/**
|
|
149
171
|
* Lower a SQL query AST into a Postgres-flavored `{ sql, params }` payload.
|
|
150
172
|
*
|
|
@@ -154,6 +176,7 @@ var PostgresControlAdapter = class {
|
|
|
154
176
|
* without instantiating the runtime adapter.
|
|
155
177
|
*/
|
|
156
178
|
lower(ast, context) {
|
|
179
|
+
if (isDdlNode(ast)) return renderLoweredDdl(ast);
|
|
157
180
|
return renderLoweredSql(ast, context.contract, this.codecLookup);
|
|
158
181
|
}
|
|
159
182
|
/**
|
|
@@ -219,6 +242,43 @@ var PostgresControlAdapter = class {
|
|
|
219
242
|
return rows;
|
|
220
243
|
}
|
|
221
244
|
/**
|
|
245
|
+
* Reads per-migration ledger rows from `prisma_contract.ledger` in apply
|
|
246
|
+
* order. Probes `information_schema.tables` first so a fresh database
|
|
247
|
+
* without the ledger table returns `[]` instead of raising "relation does
|
|
248
|
+
* not exist".
|
|
249
|
+
*/
|
|
250
|
+
async readLedger(driver, space) {
|
|
251
|
+
const ledgerContext = {
|
|
252
|
+
space: 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
|
+
let sql = `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
|
+
if (space !== void 0) sql += `
|
|
268
|
+
where space = $1`;
|
|
269
|
+
sql += `
|
|
270
|
+
order by id`;
|
|
271
|
+
return (await withMarkerReadErrorHandling(() => driver.query(sql, space === void 0 ? void 0 : [space]), ledgerContext)).rows.map((row) => ({
|
|
272
|
+
space: row.space,
|
|
273
|
+
migrationName: row.migration_name,
|
|
274
|
+
migrationHash: row.migration_hash,
|
|
275
|
+
from: ledgerOriginFromStored(row.origin_core_hash),
|
|
276
|
+
to: row.destination_core_hash,
|
|
277
|
+
appliedAt: row.created_at instanceof Date ? row.created_at : new Date(row.created_at),
|
|
278
|
+
operationCount: Array.isArray(row.operations) ? row.operations.length : 0
|
|
279
|
+
}));
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
222
282
|
* Introspects a Postgres database schema and returns a raw SqlSchemaIR.
|
|
223
283
|
*
|
|
224
284
|
* This is a pure schema discovery operation that queries the Postgres catalog
|