@prisma-next/target-postgres 0.4.0-dev.6 → 0.4.0-dev.8
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/dist/control.mjs +138 -4
- package/dist/control.mjs.map +1 -1
- package/dist/descriptor-meta-DkvCmY98.mjs +120 -0
- package/dist/descriptor-meta-DkvCmY98.mjs.map +1 -0
- package/dist/pack.d.mts +79 -6
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +2 -8
- package/dist/runtime.mjs +1 -1
- package/package.json +19 -17
- package/src/core/authoring.ts +89 -1
- package/src/core/descriptor-meta.ts +8 -2
- package/src/core/migrations/planner.ts +84 -7
- package/src/core/migrations/scaffolding.ts +140 -0
- package/src/exports/control.ts +5 -2
- package/src/exports/pack.ts +1 -10
- package/dist/descriptor-meta-CAf16lsJ.mjs +0 -32
- package/dist/descriptor-meta-CAf16lsJ.mjs.map +0 -1
- package/dist/pack.mjs.map +0 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
//#region src/core/authoring.ts
|
|
2
|
+
const postgresAuthoringTypes = { enum: {
|
|
3
|
+
kind: "typeConstructor",
|
|
4
|
+
args: [{ kind: "string" }, { kind: "stringArray" }],
|
|
5
|
+
output: {
|
|
6
|
+
codecId: "pg/enum@1",
|
|
7
|
+
nativeType: {
|
|
8
|
+
kind: "arg",
|
|
9
|
+
index: 0
|
|
10
|
+
},
|
|
11
|
+
typeParams: { values: {
|
|
12
|
+
kind: "arg",
|
|
13
|
+
index: 1
|
|
14
|
+
} }
|
|
15
|
+
}
|
|
16
|
+
} };
|
|
17
|
+
/**
|
|
18
|
+
* Field presets contributed by the Postgres target pack.
|
|
19
|
+
*
|
|
20
|
+
* These mirror the PSL scalar-to-codec mapping used by the Postgres adapter
|
|
21
|
+
* (see `createPostgresPslScalarTypeDescriptors`), so that authoring a field
|
|
22
|
+
* via the TS callback surface (e.g. `field.int()`) and via the PSL scalar
|
|
23
|
+
* surface (e.g. `Int`) lowers to byte-identical contracts.
|
|
24
|
+
*/
|
|
25
|
+
const postgresAuthoringFieldPresets = {
|
|
26
|
+
text: {
|
|
27
|
+
kind: "fieldPreset",
|
|
28
|
+
output: {
|
|
29
|
+
codecId: "pg/text@1",
|
|
30
|
+
nativeType: "text"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
int: {
|
|
34
|
+
kind: "fieldPreset",
|
|
35
|
+
output: {
|
|
36
|
+
codecId: "pg/int4@1",
|
|
37
|
+
nativeType: "int4"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
bigint: {
|
|
41
|
+
kind: "fieldPreset",
|
|
42
|
+
output: {
|
|
43
|
+
codecId: "pg/int8@1",
|
|
44
|
+
nativeType: "int8"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
float: {
|
|
48
|
+
kind: "fieldPreset",
|
|
49
|
+
output: {
|
|
50
|
+
codecId: "pg/float8@1",
|
|
51
|
+
nativeType: "float8"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
decimal: {
|
|
55
|
+
kind: "fieldPreset",
|
|
56
|
+
output: {
|
|
57
|
+
codecId: "pg/numeric@1",
|
|
58
|
+
nativeType: "numeric"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
boolean: {
|
|
62
|
+
kind: "fieldPreset",
|
|
63
|
+
output: {
|
|
64
|
+
codecId: "pg/bool@1",
|
|
65
|
+
nativeType: "bool"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
json: {
|
|
69
|
+
kind: "fieldPreset",
|
|
70
|
+
output: {
|
|
71
|
+
codecId: "pg/jsonb@1",
|
|
72
|
+
nativeType: "jsonb"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
bytes: {
|
|
76
|
+
kind: "fieldPreset",
|
|
77
|
+
output: {
|
|
78
|
+
codecId: "pg/bytea@1",
|
|
79
|
+
nativeType: "bytea"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
dateTime: {
|
|
83
|
+
kind: "fieldPreset",
|
|
84
|
+
output: {
|
|
85
|
+
codecId: "pg/timestamptz@1",
|
|
86
|
+
nativeType: "timestamptz"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
createdAt: {
|
|
90
|
+
kind: "fieldPreset",
|
|
91
|
+
output: {
|
|
92
|
+
codecId: "pg/timestamptz@1",
|
|
93
|
+
nativeType: "timestamptz",
|
|
94
|
+
default: {
|
|
95
|
+
kind: "function",
|
|
96
|
+
expression: "now()"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/core/descriptor-meta.ts
|
|
104
|
+
const postgresTargetDescriptorMetaBase = {
|
|
105
|
+
kind: "target",
|
|
106
|
+
familyId: "sql",
|
|
107
|
+
targetId: "postgres",
|
|
108
|
+
id: "postgres",
|
|
109
|
+
version: "0.0.1",
|
|
110
|
+
capabilities: {},
|
|
111
|
+
authoring: {
|
|
112
|
+
type: postgresAuthoringTypes,
|
|
113
|
+
field: postgresAuthoringFieldPresets
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const postgresTargetDescriptorMeta = postgresTargetDescriptorMetaBase;
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
export { postgresTargetDescriptorMeta as t };
|
|
120
|
+
//# sourceMappingURL=descriptor-meta-DkvCmY98.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-meta-DkvCmY98.mjs","names":["postgresTargetDescriptorMeta: typeof postgresTargetDescriptorMetaBase & {\n readonly __codecTypes?: CodecTypes;\n}"],"sources":["../src/core/authoring.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import type {\n AuthoringFieldNamespace,\n AuthoringTypeNamespace,\n} from '@prisma-next/framework-components/authoring';\n\nexport const postgresAuthoringTypes = {\n enum: {\n kind: 'typeConstructor',\n args: [{ kind: 'string' }, { kind: 'stringArray' }],\n output: {\n codecId: 'pg/enum@1',\n nativeType: { kind: 'arg', index: 0 },\n typeParams: {\n values: { kind: 'arg', index: 1 },\n },\n },\n },\n} as const satisfies AuthoringTypeNamespace;\n\n/**\n * Field presets contributed by the Postgres target pack.\n *\n * These mirror the PSL scalar-to-codec mapping used by the Postgres adapter\n * (see `createPostgresPslScalarTypeDescriptors`), so that authoring a field\n * via the TS callback surface (e.g. `field.int()`) and via the PSL scalar\n * surface (e.g. `Int`) lowers to byte-identical contracts.\n */\nexport const postgresAuthoringFieldPresets = {\n text: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/text@1',\n nativeType: 'text',\n },\n },\n int: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/int4@1',\n nativeType: 'int4',\n },\n },\n bigint: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/int8@1',\n nativeType: 'int8',\n },\n },\n float: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/float8@1',\n nativeType: 'float8',\n },\n },\n decimal: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/numeric@1',\n nativeType: 'numeric',\n },\n },\n boolean: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/bool@1',\n nativeType: 'bool',\n },\n },\n json: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/jsonb@1',\n nativeType: 'jsonb',\n },\n },\n bytes: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/bytea@1',\n nativeType: 'bytea',\n },\n },\n dateTime: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n },\n },\n createdAt: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n default: {\n kind: 'function',\n expression: 'now()',\n },\n },\n },\n} as const satisfies AuthoringFieldNamespace;\n","import type { CodecTypes } from '@prisma-next/adapter-postgres/codec-types';\nimport { postgresAuthoringFieldPresets, postgresAuthoringTypes } from './authoring';\n\nconst postgresTargetDescriptorMetaBase = {\n kind: 'target',\n familyId: 'sql',\n targetId: 'postgres',\n id: 'postgres',\n version: '0.0.1',\n capabilities: {},\n authoring: {\n type: postgresAuthoringTypes,\n field: postgresAuthoringFieldPresets,\n },\n} as const;\n\nexport const postgresTargetDescriptorMeta: typeof postgresTargetDescriptorMetaBase & {\n readonly __codecTypes?: CodecTypes;\n} = postgresTargetDescriptorMetaBase;\n"],"mappings":";AAKA,MAAa,yBAAyB,EACpC,MAAM;CACJ,MAAM;CACN,MAAM,CAAC,EAAE,MAAM,UAAU,EAAE,EAAE,MAAM,eAAe,CAAC;CACnD,QAAQ;EACN,SAAS;EACT,YAAY;GAAE,MAAM;GAAO,OAAO;GAAG;EACrC,YAAY,EACV,QAAQ;GAAE,MAAM;GAAO,OAAO;GAAG,EAClC;EACF;CACF,EACF;;;;;;;;;AAUD,MAAa,gCAAgC;CAC3C,MAAM;EACJ,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACb;EACF;CACD,KAAK;EACH,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACb;EACF;CACD,QAAQ;EACN,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACb;EACF;CACD,OAAO;EACL,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACb;EACF;CACD,SAAS;EACP,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACb;EACF;CACD,SAAS;EACP,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACb;EACF;CACD,MAAM;EACJ,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACb;EACF;CACD,OAAO;EACL,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACb;EACF;CACD,UAAU;EACR,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACb;EACF;CACD,WAAW;EACT,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACZ,SAAS;IACP,MAAM;IACN,YAAY;IACb;GACF;EACF;CACF;;;;ACnGD,MAAM,mCAAmC;CACvC,MAAM;CACN,UAAU;CACV,UAAU;CACV,IAAI;CACJ,SAAS;CACT,cAAc,EAAE;CAChB,WAAW;EACT,MAAM;EACN,OAAO;EACR;CACF;AAED,MAAaA,+BAET"}
|
package/dist/pack.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { CodecTypes } from "@prisma-next/adapter-postgres/codec-types";
|
|
2
|
-
import { TargetPackRef } from "@prisma-next/framework-components/components";
|
|
3
2
|
|
|
4
3
|
//#region src/core/descriptor-meta.d.ts
|
|
5
|
-
declare const
|
|
4
|
+
declare const postgresTargetDescriptorMetaBase: {
|
|
6
5
|
readonly kind: "target";
|
|
7
6
|
readonly familyId: "sql";
|
|
8
7
|
readonly targetId: "postgres";
|
|
@@ -33,13 +32,87 @@ declare const postgresTargetDescriptorMeta: {
|
|
|
33
32
|
};
|
|
34
33
|
};
|
|
35
34
|
};
|
|
35
|
+
readonly field: {
|
|
36
|
+
readonly text: {
|
|
37
|
+
readonly kind: "fieldPreset";
|
|
38
|
+
readonly output: {
|
|
39
|
+
readonly codecId: "pg/text@1";
|
|
40
|
+
readonly nativeType: "text";
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
readonly int: {
|
|
44
|
+
readonly kind: "fieldPreset";
|
|
45
|
+
readonly output: {
|
|
46
|
+
readonly codecId: "pg/int4@1";
|
|
47
|
+
readonly nativeType: "int4";
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
readonly bigint: {
|
|
51
|
+
readonly kind: "fieldPreset";
|
|
52
|
+
readonly output: {
|
|
53
|
+
readonly codecId: "pg/int8@1";
|
|
54
|
+
readonly nativeType: "int8";
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
readonly float: {
|
|
58
|
+
readonly kind: "fieldPreset";
|
|
59
|
+
readonly output: {
|
|
60
|
+
readonly codecId: "pg/float8@1";
|
|
61
|
+
readonly nativeType: "float8";
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
readonly decimal: {
|
|
65
|
+
readonly kind: "fieldPreset";
|
|
66
|
+
readonly output: {
|
|
67
|
+
readonly codecId: "pg/numeric@1";
|
|
68
|
+
readonly nativeType: "numeric";
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
readonly boolean: {
|
|
72
|
+
readonly kind: "fieldPreset";
|
|
73
|
+
readonly output: {
|
|
74
|
+
readonly codecId: "pg/bool@1";
|
|
75
|
+
readonly nativeType: "bool";
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
readonly json: {
|
|
79
|
+
readonly kind: "fieldPreset";
|
|
80
|
+
readonly output: {
|
|
81
|
+
readonly codecId: "pg/jsonb@1";
|
|
82
|
+
readonly nativeType: "jsonb";
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
readonly bytes: {
|
|
86
|
+
readonly kind: "fieldPreset";
|
|
87
|
+
readonly output: {
|
|
88
|
+
readonly codecId: "pg/bytea@1";
|
|
89
|
+
readonly nativeType: "bytea";
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
readonly dateTime: {
|
|
93
|
+
readonly kind: "fieldPreset";
|
|
94
|
+
readonly output: {
|
|
95
|
+
readonly codecId: "pg/timestamptz@1";
|
|
96
|
+
readonly nativeType: "timestamptz";
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
readonly createdAt: {
|
|
100
|
+
readonly kind: "fieldPreset";
|
|
101
|
+
readonly output: {
|
|
102
|
+
readonly codecId: "pg/timestamptz@1";
|
|
103
|
+
readonly nativeType: "timestamptz";
|
|
104
|
+
readonly default: {
|
|
105
|
+
readonly kind: "function";
|
|
106
|
+
readonly expression: "now()";
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
};
|
|
36
111
|
};
|
|
37
112
|
};
|
|
38
|
-
|
|
39
|
-
//#region src/exports/pack.d.ts
|
|
40
|
-
declare const _default: typeof postgresTargetDescriptorMeta & TargetPackRef<"sql", "postgres"> & {
|
|
113
|
+
declare const postgresTargetDescriptorMeta: typeof postgresTargetDescriptorMetaBase & {
|
|
41
114
|
readonly __codecTypes?: CodecTypes;
|
|
42
115
|
};
|
|
43
116
|
//#endregion
|
|
44
|
-
export {
|
|
117
|
+
export { postgresTargetDescriptorMeta as default };
|
|
45
118
|
//# sourceMappingURL=pack.d.mts.map
|
package/dist/pack.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pack.d.mts","names":[],"sources":["../src/core/descriptor-meta.ts"
|
|
1
|
+
{"version":3,"file":"pack.d.mts","names":[],"sources":["../src/core/descriptor-meta.ts"],"sourcesContent":[],"mappings":";;;cAGM;;EAAA,SAAA,QAAA,EAAA,KAAA;EAaO,SAAA,QAAA,EAAA,UAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAA,qCAAqC;0BACxB"}
|
package/dist/pack.mjs
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-
|
|
1
|
+
import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-DkvCmY98.mjs";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const postgresPack = postgresTargetDescriptorMeta;
|
|
5
|
-
var pack_default = postgresPack;
|
|
6
|
-
|
|
7
|
-
//#endregion
|
|
8
|
-
export { pack_default as default };
|
|
9
|
-
//# sourceMappingURL=pack.mjs.map
|
|
3
|
+
export { postgresTargetDescriptorMeta as default };
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-
|
|
1
|
+
import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-DkvCmY98.mjs";
|
|
2
2
|
import { createCodecRegistry } from "@prisma-next/sql-relational-core/ast";
|
|
3
3
|
|
|
4
4
|
//#region src/exports/runtime.ts
|
package/package.json
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/target-postgres",
|
|
3
|
-
"version": "0.4.0-dev.
|
|
3
|
+
"version": "0.4.0-dev.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Postgres target pack for Prisma Next",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"arktype": "^2.0.0",
|
|
9
|
-
"
|
|
10
|
-
"@prisma-next/
|
|
11
|
-
"@prisma-next/
|
|
12
|
-
"@prisma-next/sql
|
|
13
|
-
"@prisma-next/
|
|
14
|
-
"@prisma-next/sql-
|
|
15
|
-
"@prisma-next/sql-errors": "0.4.0-dev.
|
|
16
|
-
"@prisma-next/sql-relational-core": "0.4.0-dev.
|
|
17
|
-
"@prisma-next/sql-
|
|
18
|
-
"@prisma-next/
|
|
19
|
-
"@prisma-next/sql-
|
|
9
|
+
"pathe": "^2.0.3",
|
|
10
|
+
"@prisma-next/contract": "0.4.0-dev.8",
|
|
11
|
+
"@prisma-next/errors": "0.4.0-dev.8",
|
|
12
|
+
"@prisma-next/family-sql": "0.4.0-dev.8",
|
|
13
|
+
"@prisma-next/framework-components": "0.4.0-dev.8",
|
|
14
|
+
"@prisma-next/sql-builder": "0.4.0-dev.8",
|
|
15
|
+
"@prisma-next/sql-errors": "0.4.0-dev.8",
|
|
16
|
+
"@prisma-next/sql-relational-core": "0.4.0-dev.8",
|
|
17
|
+
"@prisma-next/sql-runtime": "0.4.0-dev.8",
|
|
18
|
+
"@prisma-next/sql-operations": "0.4.0-dev.8",
|
|
19
|
+
"@prisma-next/sql-contract": "0.4.0-dev.8",
|
|
20
|
+
"@prisma-next/sql-schema-ir": "0.4.0-dev.8",
|
|
21
|
+
"@prisma-next/utils": "0.4.0-dev.8"
|
|
20
22
|
},
|
|
21
23
|
"devDependencies": {
|
|
22
24
|
"tsdown": "0.18.4",
|
|
23
25
|
"typescript": "5.9.3",
|
|
24
26
|
"vitest": "4.0.17",
|
|
25
|
-
"@prisma-next/adapter-postgres": "0.4.0-dev.
|
|
26
|
-
"@prisma-next/driver-postgres": "0.4.0-dev.
|
|
27
|
-
"@prisma-next/
|
|
28
|
-
"@prisma-next/extension-pgvector": "0.4.0-dev.6",
|
|
27
|
+
"@prisma-next/adapter-postgres": "0.4.0-dev.8",
|
|
28
|
+
"@prisma-next/driver-postgres": "0.4.0-dev.8",
|
|
29
|
+
"@prisma-next/extension-pgvector": "0.4.0-dev.8",
|
|
29
30
|
"@prisma-next/tsconfig": "0.0.0",
|
|
30
|
-
"@prisma-next/tsdown": "0.0.0"
|
|
31
|
+
"@prisma-next/tsdown": "0.0.0",
|
|
32
|
+
"@prisma-next/test-utils": "0.0.1"
|
|
31
33
|
},
|
|
32
34
|
"files": [
|
|
33
35
|
"dist",
|
package/src/core/authoring.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
AuthoringFieldNamespace,
|
|
3
|
+
AuthoringTypeNamespace,
|
|
4
|
+
} from '@prisma-next/framework-components/authoring';
|
|
2
5
|
|
|
3
6
|
export const postgresAuthoringTypes = {
|
|
4
7
|
enum: {
|
|
@@ -13,3 +16,88 @@ export const postgresAuthoringTypes = {
|
|
|
13
16
|
},
|
|
14
17
|
},
|
|
15
18
|
} as const satisfies AuthoringTypeNamespace;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Field presets contributed by the Postgres target pack.
|
|
22
|
+
*
|
|
23
|
+
* These mirror the PSL scalar-to-codec mapping used by the Postgres adapter
|
|
24
|
+
* (see `createPostgresPslScalarTypeDescriptors`), so that authoring a field
|
|
25
|
+
* via the TS callback surface (e.g. `field.int()`) and via the PSL scalar
|
|
26
|
+
* surface (e.g. `Int`) lowers to byte-identical contracts.
|
|
27
|
+
*/
|
|
28
|
+
export const postgresAuthoringFieldPresets = {
|
|
29
|
+
text: {
|
|
30
|
+
kind: 'fieldPreset',
|
|
31
|
+
output: {
|
|
32
|
+
codecId: 'pg/text@1',
|
|
33
|
+
nativeType: 'text',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
int: {
|
|
37
|
+
kind: 'fieldPreset',
|
|
38
|
+
output: {
|
|
39
|
+
codecId: 'pg/int4@1',
|
|
40
|
+
nativeType: 'int4',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
bigint: {
|
|
44
|
+
kind: 'fieldPreset',
|
|
45
|
+
output: {
|
|
46
|
+
codecId: 'pg/int8@1',
|
|
47
|
+
nativeType: 'int8',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
float: {
|
|
51
|
+
kind: 'fieldPreset',
|
|
52
|
+
output: {
|
|
53
|
+
codecId: 'pg/float8@1',
|
|
54
|
+
nativeType: 'float8',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
decimal: {
|
|
58
|
+
kind: 'fieldPreset',
|
|
59
|
+
output: {
|
|
60
|
+
codecId: 'pg/numeric@1',
|
|
61
|
+
nativeType: 'numeric',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
boolean: {
|
|
65
|
+
kind: 'fieldPreset',
|
|
66
|
+
output: {
|
|
67
|
+
codecId: 'pg/bool@1',
|
|
68
|
+
nativeType: 'bool',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
json: {
|
|
72
|
+
kind: 'fieldPreset',
|
|
73
|
+
output: {
|
|
74
|
+
codecId: 'pg/jsonb@1',
|
|
75
|
+
nativeType: 'jsonb',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
bytes: {
|
|
79
|
+
kind: 'fieldPreset',
|
|
80
|
+
output: {
|
|
81
|
+
codecId: 'pg/bytea@1',
|
|
82
|
+
nativeType: 'bytea',
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
dateTime: {
|
|
86
|
+
kind: 'fieldPreset',
|
|
87
|
+
output: {
|
|
88
|
+
codecId: 'pg/timestamptz@1',
|
|
89
|
+
nativeType: 'timestamptz',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
createdAt: {
|
|
93
|
+
kind: 'fieldPreset',
|
|
94
|
+
output: {
|
|
95
|
+
codecId: 'pg/timestamptz@1',
|
|
96
|
+
nativeType: 'timestamptz',
|
|
97
|
+
default: {
|
|
98
|
+
kind: 'function',
|
|
99
|
+
expression: 'now()',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
} as const satisfies AuthoringFieldNamespace;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { CodecTypes } from '@prisma-next/adapter-postgres/codec-types';
|
|
2
|
+
import { postgresAuthoringFieldPresets, postgresAuthoringTypes } from './authoring';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
const postgresTargetDescriptorMetaBase = {
|
|
4
5
|
kind: 'target',
|
|
5
6
|
familyId: 'sql',
|
|
6
7
|
targetId: 'postgres',
|
|
@@ -9,5 +10,10 @@ export const postgresTargetDescriptorMeta = {
|
|
|
9
10
|
capabilities: {},
|
|
10
11
|
authoring: {
|
|
11
12
|
type: postgresAuthoringTypes,
|
|
13
|
+
field: postgresAuthoringFieldPresets,
|
|
12
14
|
},
|
|
13
15
|
} as const;
|
|
16
|
+
|
|
17
|
+
export const postgresTargetDescriptorMeta: typeof postgresTargetDescriptorMetaBase & {
|
|
18
|
+
readonly __codecTypes?: CodecTypes;
|
|
19
|
+
} = postgresTargetDescriptorMetaBase;
|
|
@@ -3,24 +3,30 @@ import {
|
|
|
3
3
|
parsePostgresDefault,
|
|
4
4
|
quoteIdentifier,
|
|
5
5
|
} from '@prisma-next/adapter-postgres/control';
|
|
6
|
+
import { errorPlanDoesNotSupportAuthoringSurface } from '@prisma-next/errors/migration';
|
|
6
7
|
import type {
|
|
7
8
|
CodecControlHooks,
|
|
8
9
|
ComponentDatabaseDependency,
|
|
9
10
|
MigrationOperationPolicy,
|
|
10
|
-
SqlMigrationPlanner,
|
|
11
11
|
SqlMigrationPlannerPlanOptions,
|
|
12
12
|
SqlMigrationPlanOperation,
|
|
13
13
|
SqlPlannerConflict,
|
|
14
|
+
SqlPlannerFailureResult,
|
|
14
15
|
} from '@prisma-next/family-sql/control';
|
|
15
16
|
import {
|
|
16
17
|
collectInitDependencies,
|
|
17
18
|
createMigrationPlan,
|
|
18
19
|
extractCodecControlHooks,
|
|
19
20
|
plannerFailure,
|
|
20
|
-
plannerSuccess,
|
|
21
21
|
} from '@prisma-next/family-sql/control';
|
|
22
22
|
import { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';
|
|
23
|
-
import type {
|
|
23
|
+
import type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';
|
|
24
|
+
import type {
|
|
25
|
+
MigrationPlanner,
|
|
26
|
+
MigrationPlanWithAuthoringSurface,
|
|
27
|
+
MigrationScaffoldContext,
|
|
28
|
+
SchemaIssue,
|
|
29
|
+
} from '@prisma-next/framework-components/control';
|
|
24
30
|
import type {
|
|
25
31
|
StorageColumn,
|
|
26
32
|
StorageTable,
|
|
@@ -58,6 +64,7 @@ import {
|
|
|
58
64
|
type PlanningMode,
|
|
59
65
|
type PostgresPlanTargetDetails,
|
|
60
66
|
} from './planner-target-details';
|
|
67
|
+
import { renderDescriptorTypeScript } from './scaffolding';
|
|
61
68
|
|
|
62
69
|
type PlannerFrameworkComponents = SqlMigrationPlannerPlanOptions extends {
|
|
63
70
|
readonly frameworkComponents: infer T;
|
|
@@ -89,17 +96,79 @@ const DEFAULT_PLANNER_CONFIG: PlannerConfig = {
|
|
|
89
96
|
|
|
90
97
|
export function createPostgresMigrationPlanner(
|
|
91
98
|
config: Partial<PlannerConfig> = {},
|
|
92
|
-
):
|
|
99
|
+
): PostgresMigrationPlanner {
|
|
93
100
|
return new PostgresMigrationPlanner({
|
|
94
101
|
...DEFAULT_PLANNER_CONFIG,
|
|
95
102
|
...config,
|
|
96
103
|
});
|
|
97
104
|
}
|
|
98
105
|
|
|
99
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Postgres planner success plan: the SQL-typed plan (so target-detail
|
|
108
|
+
* typing is preserved for direct SQL callers, including this package's unit
|
|
109
|
+
* tests) plus the framework-required `renderTypeScript()` stub.
|
|
110
|
+
*/
|
|
111
|
+
export type PostgresPlanWithRender = ReturnType<
|
|
112
|
+
typeof createMigrationPlan<PostgresPlanTargetDetails>
|
|
113
|
+
> & {
|
|
114
|
+
renderTypeScript(): string;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Result of `PostgresMigrationPlanner.plan()`. A discriminated union that
|
|
119
|
+
* satisfies both the framework's `MigrationPlannerResult` (success plan
|
|
120
|
+
* carries `renderTypeScript()`) and the SQL family's typed result shape
|
|
121
|
+
* (success plan is a `SqlMigrationPlan<PostgresPlanTargetDetails>`).
|
|
122
|
+
*/
|
|
123
|
+
export type PostgresPlanResult =
|
|
124
|
+
| { readonly kind: 'success'; readonly plan: PostgresPlanWithRender }
|
|
125
|
+
| SqlPlannerFailureResult;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Postgres migration planner.
|
|
129
|
+
*
|
|
130
|
+
* Implements the framework's `MigrationPlanner<'sql', 'postgres'>` directly
|
|
131
|
+
* — meaning it owns `emptyMigration()` and attaches the `renderTypeScript()`
|
|
132
|
+
* stub to success plans (Postgres uses descriptor-flow authoring, so
|
|
133
|
+
* `renderTypeScript()` throws on planner-produced plans). No external wrapper
|
|
134
|
+
* is required at the descriptor level.
|
|
135
|
+
*
|
|
136
|
+
* `plan()` accepts the framework's option shape (with `contract`/`schema`
|
|
137
|
+
* typed as `unknown`); SQL-typed callers may pass the more specific
|
|
138
|
+
* `SqlMigrationPlannerPlanOptions`, since those structurally satisfy the
|
|
139
|
+
* looser framework contract. Internally we treat options as the SQL-typed
|
|
140
|
+
* superset so the existing planner logic stays identical.
|
|
141
|
+
*
|
|
142
|
+
* `fromHash` is accepted but ignored: Postgres is descriptor-flow and never
|
|
143
|
+
* needs it (only class-flow planners like Mongo populate `describe()` from
|
|
144
|
+
* `fromHash`).
|
|
145
|
+
*/
|
|
146
|
+
export class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgres'> {
|
|
100
147
|
constructor(private readonly config: PlannerConfig) {}
|
|
101
148
|
|
|
102
|
-
plan(options:
|
|
149
|
+
plan(options: {
|
|
150
|
+
readonly contract: unknown;
|
|
151
|
+
readonly schema: unknown;
|
|
152
|
+
readonly policy: MigrationOperationPolicy;
|
|
153
|
+
readonly fromHash?: string;
|
|
154
|
+
readonly schemaName?: string;
|
|
155
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
156
|
+
}): PostgresPlanResult {
|
|
157
|
+
return this.planSql(options as SqlMigrationPlannerPlanOptions);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
emptyMigration(context: MigrationScaffoldContext): MigrationPlanWithAuthoringSurface {
|
|
161
|
+
return {
|
|
162
|
+
targetId: 'postgres',
|
|
163
|
+
destination: { storageHash: context.toHash },
|
|
164
|
+
operations: [],
|
|
165
|
+
renderTypeScript(): string {
|
|
166
|
+
return renderDescriptorTypeScript([], context);
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private planSql(options: SqlMigrationPlannerPlanOptions): PostgresPlanResult {
|
|
103
172
|
const schemaName = options.schemaName ?? this.config.defaultSchema;
|
|
104
173
|
const policyResult = this.ensureAdditivePolicy(options.policy);
|
|
105
174
|
if (policyResult) {
|
|
@@ -176,7 +245,15 @@ class PostgresMigrationPlanner implements SqlMigrationPlanner<PostgresPlanTarget
|
|
|
176
245
|
operations,
|
|
177
246
|
});
|
|
178
247
|
|
|
179
|
-
return
|
|
248
|
+
return Object.freeze({
|
|
249
|
+
kind: 'success' as const,
|
|
250
|
+
plan: Object.freeze({
|
|
251
|
+
...plan,
|
|
252
|
+
renderTypeScript(): string {
|
|
253
|
+
throw errorPlanDoesNotSupportAuthoringSurface({ targetId: 'postgres' });
|
|
254
|
+
},
|
|
255
|
+
}),
|
|
256
|
+
});
|
|
180
257
|
}
|
|
181
258
|
|
|
182
259
|
private ensureAdditivePolicy(policy: MigrationOperationPolicy) {
|