@prisma-next/target-postgres 0.4.0-dev.9 → 0.4.1
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.d.mts +1 -9
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +1693 -4798
- package/dist/control.mjs.map +1 -1
- package/dist/migration.d.mts +164 -0
- package/dist/migration.d.mts.map +1 -0
- package/dist/migration.mjs +446 -0
- package/dist/migration.mjs.map +1 -0
- package/dist/planner-target-details-MXb3oeul.d.mts +11 -0
- package/dist/planner-target-details-MXb3oeul.d.mts.map +1 -0
- package/dist/postgres-migration-BsHJHV9O.mjs +2793 -0
- package/dist/postgres-migration-BsHJHV9O.mjs.map +1 -0
- package/package.json +20 -18
- package/src/core/migrations/issue-planner.ts +832 -0
- package/src/core/migrations/op-factory-call.ts +862 -0
- package/src/core/migrations/operations/columns.ts +285 -0
- package/src/core/migrations/operations/constraints.ts +191 -0
- package/src/core/migrations/operations/data-transform.ts +113 -0
- package/src/core/migrations/operations/dependencies.ts +36 -0
- package/src/core/migrations/operations/enums.ts +113 -0
- package/src/core/migrations/operations/indexes.ts +61 -0
- package/src/core/migrations/operations/raw.ts +15 -0
- package/src/core/migrations/operations/shared.ts +67 -0
- package/src/core/migrations/operations/tables.ts +63 -0
- package/src/core/migrations/planner-produced-postgres-migration.ts +67 -0
- package/src/core/migrations/planner-strategies.ts +592 -151
- package/src/core/migrations/planner-target-details.ts +0 -6
- package/src/core/migrations/planner.ts +63 -781
- package/src/core/migrations/postgres-migration.ts +20 -0
- package/src/core/migrations/render-ops.ts +9 -0
- package/src/core/migrations/render-typescript.ts +95 -0
- package/src/exports/control.ts +9 -142
- package/src/exports/migration.ts +40 -0
- package/dist/migration-builders.d.mts +0 -88
- package/dist/migration-builders.d.mts.map +0 -1
- package/dist/migration-builders.mjs +0 -3
- package/dist/operation-descriptors-CxymFSgK.mjs +0 -52
- package/dist/operation-descriptors-CxymFSgK.mjs.map +0 -1
- package/src/core/migrations/descriptor-planner.ts +0 -464
- package/src/core/migrations/operation-descriptors.ts +0 -166
- package/src/core/migrations/operation-resolver.ts +0 -929
- package/src/core/migrations/planner-reconciliation.ts +0 -798
- package/src/core/migrations/scaffolding.ts +0 -140
- package/src/exports/migration-builders.ts +0 -56
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Migration as SqlMigration } from '@prisma-next/family-sql/migration';
|
|
2
|
+
import type { PostgresPlanTargetDetails } from './planner-target-details';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Target-owned base class for Postgres migrations.
|
|
6
|
+
*
|
|
7
|
+
* Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the
|
|
8
|
+
* abstract `targetId` to the Postgres target-id string literal, so both
|
|
9
|
+
* user-authored migrations and renderer-generated scaffolds (the output of
|
|
10
|
+
* `renderCallsToTypeScript`) can extend `PostgresMigration` directly without
|
|
11
|
+
* redeclaring target-local identity.
|
|
12
|
+
*
|
|
13
|
+
* Mirrors `MongoMigration` in `@prisma-next/family-mongo`: the renderer
|
|
14
|
+
* emits `extends Migration` against a target-specific re-export of this
|
|
15
|
+
* class from `@prisma-next/target-postgres/migration`, keeping the
|
|
16
|
+
* authoring surface target-scoped rather than family-scoped.
|
|
17
|
+
*/
|
|
18
|
+
export abstract class PostgresMigration extends SqlMigration<PostgresPlanTargetDetails> {
|
|
19
|
+
readonly targetId = 'postgres' as const;
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';
|
|
2
|
+
import type { PostgresOpFactoryCall } from './op-factory-call';
|
|
3
|
+
import type { PostgresPlanTargetDetails } from './planner-target-details';
|
|
4
|
+
|
|
5
|
+
type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
|
|
6
|
+
|
|
7
|
+
export function renderOps(calls: readonly PostgresOpFactoryCall[]): Op[] {
|
|
8
|
+
return calls.map((c) => c.toOp());
|
|
9
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polymorphic TypeScript emitter for the Postgres migration IR.
|
|
3
|
+
*
|
|
4
|
+
* Each `PostgresOpFactoryCall` renders itself via `renderTypeScript()` and
|
|
5
|
+
* declares its own `importRequirements()`; this file just composes the module
|
|
6
|
+
* source around those contributions. The design mirrors the Mongo target's
|
|
7
|
+
* `render-typescript.ts` deliberately — byte-for-byte alignment isn't required
|
|
8
|
+
* (different factory module specifiers, different base-class name) but the
|
|
9
|
+
* shape is, so future consolidation to a framework-level helper is mechanical.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { detectScaffoldRuntime, shebangLineFor } from '@prisma-next/migration-tools/migration-ts';
|
|
13
|
+
import { type ImportRequirement, jsonToTsSource, renderImports } from '@prisma-next/ts-render';
|
|
14
|
+
import type { PostgresOpFactoryCall } from './op-factory-call';
|
|
15
|
+
|
|
16
|
+
export interface RenderMigrationMeta {
|
|
17
|
+
readonly from: string;
|
|
18
|
+
readonly to: string;
|
|
19
|
+
readonly kind?: string;
|
|
20
|
+
readonly labels?: readonly string[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Always-present base import — the rendered scaffold always extends the
|
|
25
|
+
* target-owned `Migration` (i.e. `PostgresMigration`) re-exported from
|
|
26
|
+
* `@prisma-next/target-postgres/migration`. That re-export fixes the
|
|
27
|
+
* `SqlMigration` generic to `PostgresPlanTargetDetails` and the abstract
|
|
28
|
+
* `targetId` to `'postgres'`, so user-authored migrations don't need to
|
|
29
|
+
* thread target-details or redeclare `targetId`.
|
|
30
|
+
*/
|
|
31
|
+
const BASE_IMPORT: ImportRequirement = {
|
|
32
|
+
moduleSpecifier: '@prisma-next/target-postgres/migration',
|
|
33
|
+
symbol: 'Migration',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function renderCallsToTypeScript(
|
|
37
|
+
calls: ReadonlyArray<PostgresOpFactoryCall>,
|
|
38
|
+
meta: RenderMigrationMeta,
|
|
39
|
+
): string {
|
|
40
|
+
const imports = buildImports(calls);
|
|
41
|
+
const operationsBody = calls.map((c) => c.renderTypeScript()).join(',\n');
|
|
42
|
+
|
|
43
|
+
return [
|
|
44
|
+
shebangLineFor(detectScaffoldRuntime()),
|
|
45
|
+
imports,
|
|
46
|
+
'',
|
|
47
|
+
'export default class M extends Migration {',
|
|
48
|
+
buildDescribeMethod(meta),
|
|
49
|
+
' override get operations() {',
|
|
50
|
+
' return [',
|
|
51
|
+
indent(operationsBody, 6),
|
|
52
|
+
' ];',
|
|
53
|
+
' }',
|
|
54
|
+
'}',
|
|
55
|
+
'',
|
|
56
|
+
'Migration.run(import.meta.url, M);',
|
|
57
|
+
'',
|
|
58
|
+
].join('\n');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function buildImports(calls: ReadonlyArray<PostgresOpFactoryCall>): string {
|
|
62
|
+
const requirements: ImportRequirement[] = [BASE_IMPORT];
|
|
63
|
+
for (const call of calls) {
|
|
64
|
+
for (const req of call.importRequirements()) {
|
|
65
|
+
requirements.push(req);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return renderImports(requirements);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function buildDescribeMethod(meta: RenderMigrationMeta): string {
|
|
72
|
+
const lines: string[] = [];
|
|
73
|
+
lines.push(' override describe() {');
|
|
74
|
+
lines.push(' return {');
|
|
75
|
+
lines.push(` from: ${JSON.stringify(meta.from)},`);
|
|
76
|
+
lines.push(` to: ${JSON.stringify(meta.to)},`);
|
|
77
|
+
if (meta.kind) {
|
|
78
|
+
lines.push(` kind: ${JSON.stringify(meta.kind)},`);
|
|
79
|
+
}
|
|
80
|
+
if (meta.labels && meta.labels.length > 0) {
|
|
81
|
+
lines.push(` labels: ${jsonToTsSource(meta.labels)},`);
|
|
82
|
+
}
|
|
83
|
+
lines.push(' };');
|
|
84
|
+
lines.push(' }');
|
|
85
|
+
lines.push('');
|
|
86
|
+
return lines.join('\n');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function indent(text: string, spaces: number): string {
|
|
90
|
+
const pad = ' '.repeat(spaces);
|
|
91
|
+
return text
|
|
92
|
+
.split('\n')
|
|
93
|
+
.map((line) => (line.trim() ? `${pad}${line}` : line))
|
|
94
|
+
.join('\n');
|
|
95
|
+
}
|
package/src/exports/control.ts
CHANGED
|
@@ -1,86 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
normalizeSchemaNativeType,
|
|
3
|
-
parsePostgresDefault,
|
|
4
|
-
} from '@prisma-next/adapter-postgres/control';
|
|
5
1
|
import type { ColumnDefault, Contract } from '@prisma-next/contract/types';
|
|
6
2
|
import type {
|
|
7
3
|
SqlControlFamilyInstance,
|
|
8
4
|
SqlControlTargetDescriptor,
|
|
9
5
|
} from '@prisma-next/family-sql/control';
|
|
10
|
-
import {
|
|
11
|
-
collectInitDependencies,
|
|
12
|
-
contractToSchemaIR,
|
|
13
|
-
extractCodecControlHooks,
|
|
14
|
-
} from '@prisma-next/family-sql/control';
|
|
15
|
-
import { MigrationDescriptorArraySchema } from '@prisma-next/family-sql/operation-descriptors';
|
|
16
|
-
import { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';
|
|
6
|
+
import { contractToSchemaIR, extractCodecControlHooks } from '@prisma-next/family-sql/control';
|
|
17
7
|
import type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';
|
|
18
8
|
import type {
|
|
19
9
|
ControlTargetInstance,
|
|
20
10
|
MigrationRunner,
|
|
21
|
-
OperationDescriptor,
|
|
22
11
|
} from '@prisma-next/framework-components/control';
|
|
23
|
-
import { sql } from '@prisma-next/sql-builder/runtime';
|
|
24
12
|
import type { SqlStorage, StorageColumn } from '@prisma-next/sql-contract/types';
|
|
25
|
-
import type { SqlOperationEntry } from '@prisma-next/sql-operations';
|
|
26
13
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
27
|
-
import { type } from 'arktype';
|
|
28
14
|
import { postgresTargetDescriptorMeta } from '../core/descriptor-meta';
|
|
29
|
-
import { planDescriptors } from '../core/migrations/descriptor-planner';
|
|
30
|
-
import { resolveOperations } from '../core/migrations/operation-resolver';
|
|
31
15
|
import { createPostgresMigrationPlanner } from '../core/migrations/planner';
|
|
32
16
|
import { renderDefaultLiteral } from '../core/migrations/planner-ddl-builders';
|
|
33
17
|
import type { PostgresPlanTargetDetails } from '../core/migrations/planner-target-details';
|
|
34
18
|
import { createPostgresMigrationRunner } from '../core/migrations/runner';
|
|
35
|
-
import { renderDescriptorTypeScript } from '../core/migrations/scaffolding';
|
|
36
|
-
|
|
37
|
-
function parseDescriptors(descriptors: readonly OperationDescriptor[]) {
|
|
38
|
-
const result = MigrationDescriptorArraySchema([...descriptors]);
|
|
39
|
-
if (result instanceof type.errors) {
|
|
40
|
-
throw new Error(`Invalid migration descriptors:\n${result.summary}`);
|
|
41
|
-
}
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function collectQueryOperationTypes(
|
|
46
|
-
frameworkComponents?: ReadonlyArray<TargetBoundComponentDescriptor<'sql', 'postgres'>>,
|
|
47
|
-
): Readonly<Record<string, SqlOperationEntry>> {
|
|
48
|
-
const entries: Record<string, SqlOperationEntry> = {};
|
|
49
|
-
if (!frameworkComponents) return entries;
|
|
50
|
-
for (const component of frameworkComponents) {
|
|
51
|
-
const ops = (
|
|
52
|
-
component as {
|
|
53
|
-
queryOperations?: () => ReadonlyArray<{ method: string } & SqlOperationEntry>;
|
|
54
|
-
}
|
|
55
|
-
).queryOperations?.();
|
|
56
|
-
if (!ops) continue;
|
|
57
|
-
for (const { method, ...entry } of ops) {
|
|
58
|
-
entries[method] = entry;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return entries;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Creates a SQL DSL client for migration authoring.
|
|
66
|
-
* Only the fields used by the builder are populated — operations, codecs,
|
|
67
|
-
* and types are unused by sql() and stubbed to satisfy the ExecutionContext type.
|
|
68
|
-
*/
|
|
69
|
-
function createMigrationClient(
|
|
70
|
-
toContract: Contract<SqlStorage>,
|
|
71
|
-
frameworkComponents?: ReadonlyArray<TargetBoundComponentDescriptor<'sql', 'postgres'>>,
|
|
72
|
-
) {
|
|
73
|
-
const queryOperationTypes = collectQueryOperationTypes(frameworkComponents);
|
|
74
|
-
// sql() only reads contract, queryOperations.entries(), and applyMutationDefaults
|
|
75
|
-
// from the context. The other fields are for runtime execution, not query building.
|
|
76
|
-
return sql({
|
|
77
|
-
context: {
|
|
78
|
-
contract: toContract,
|
|
79
|
-
queryOperations: { entries: () => queryOperationTypes },
|
|
80
|
-
applyMutationDefaults: () => [],
|
|
81
|
-
} as never,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
19
|
|
|
85
20
|
function buildNativeTypeExpander(
|
|
86
21
|
frameworkComponents?: ReadonlyArray<TargetBoundComponentDescriptor<'sql', 'postgres'>>,
|
|
@@ -95,22 +30,15 @@ function buildNativeTypeExpander(
|
|
|
95
30
|
readonly typeParams?: Record<string, unknown>;
|
|
96
31
|
}) => {
|
|
97
32
|
if (!input.typeParams) return input.nativeType;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
33
|
+
// Mirror `renderExpectedNativeType` in verify-sql-schema: when a codec
|
|
34
|
+
// has no `expandNativeType` hook (e.g. `pg/enum@1`, whose typeParams
|
|
35
|
+
// describe the value set rather than a DDL suffix), fall back to the
|
|
36
|
+
// bare native type rather than throwing. Throwing here would reject
|
|
37
|
+
// every plan involving an enum-/values-typed column as soon as its
|
|
38
|
+
// `typeRef` resolved to a `StorageTypeInstance` carrying typeParams.
|
|
39
|
+
if (!input.codecId) return input.nativeType;
|
|
106
40
|
const hooks = codecHooks.get(input.codecId);
|
|
107
|
-
if (!hooks?.expandNativeType)
|
|
108
|
-
throw new Error(
|
|
109
|
-
`Column declares typeParams for nativeType "${input.nativeType}" ` +
|
|
110
|
-
`but no expandNativeType hook is registered for codecId "${input.codecId}". ` +
|
|
111
|
-
'Ensure the extension providing this codec is included in extensionPacks.',
|
|
112
|
-
);
|
|
113
|
-
}
|
|
41
|
+
if (!hooks?.expandNativeType) return input.nativeType;
|
|
114
42
|
return hooks.expandNativeType(input);
|
|
115
43
|
};
|
|
116
44
|
}
|
|
@@ -141,67 +69,6 @@ const postgresTargetDescriptor: SqlControlTargetDescriptor<'postgres', PostgresP
|
|
|
141
69
|
frameworkComponents: frameworkComponents ?? [],
|
|
142
70
|
});
|
|
143
71
|
},
|
|
144
|
-
planWithDescriptors(context) {
|
|
145
|
-
const toContract = context.toContract as Contract<SqlStorage>;
|
|
146
|
-
const fromContract = context.fromContract as Contract<SqlStorage> | null;
|
|
147
|
-
|
|
148
|
-
// Synthesize schema IR from the fromContract (same as contractToSchema flow)
|
|
149
|
-
const expander = buildNativeTypeExpander(context.frameworkComponents);
|
|
150
|
-
const fromSchemaIR = contractToSchemaIR(fromContract, {
|
|
151
|
-
annotationNamespace: 'pg',
|
|
152
|
-
...ifDefined('expandNativeType', expander),
|
|
153
|
-
renderDefault: postgresRenderDefault,
|
|
154
|
-
frameworkComponents: context.frameworkComponents ?? [],
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
// Collect schema issues via verifier
|
|
158
|
-
const verifyResult = verifySqlSchema({
|
|
159
|
-
contract: toContract,
|
|
160
|
-
schema: fromSchemaIR,
|
|
161
|
-
strict: true,
|
|
162
|
-
typeMetadataRegistry: new Map(),
|
|
163
|
-
frameworkComponents: context.frameworkComponents ?? [],
|
|
164
|
-
normalizeDefault: parsePostgresDefault,
|
|
165
|
-
normalizeNativeType: normalizeSchemaNativeType,
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// Run descriptor planner
|
|
169
|
-
const planResult = planDescriptors({
|
|
170
|
-
issues: verifyResult.schema.issues,
|
|
171
|
-
toContract,
|
|
172
|
-
fromContract,
|
|
173
|
-
});
|
|
174
|
-
if (!planResult.ok) {
|
|
175
|
-
return { ok: false as const, conflicts: planResult.failure };
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return {
|
|
179
|
-
ok: true as const,
|
|
180
|
-
descriptors: planResult.value.descriptors,
|
|
181
|
-
};
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
resolveDescriptors(descriptors, context) {
|
|
185
|
-
const validated = parseDescriptors(descriptors);
|
|
186
|
-
const codecHooks = context.frameworkComponents
|
|
187
|
-
? extractCodecControlHooks(context.frameworkComponents)
|
|
188
|
-
: new Map();
|
|
189
|
-
const dependencies = context.frameworkComponents
|
|
190
|
-
? collectInitDependencies(context.frameworkComponents)
|
|
191
|
-
: [];
|
|
192
|
-
const toContract = context.toContract as Contract<SqlStorage>;
|
|
193
|
-
const db = createMigrationClient(toContract, context.frameworkComponents);
|
|
194
|
-
return resolveOperations(validated, {
|
|
195
|
-
toContract,
|
|
196
|
-
schemaName: context.schemaName ?? 'public',
|
|
197
|
-
codecHooks,
|
|
198
|
-
dependencies,
|
|
199
|
-
db,
|
|
200
|
-
});
|
|
201
|
-
},
|
|
202
|
-
renderDescriptorTypeScript(descriptors, context) {
|
|
203
|
-
return renderDescriptorTypeScript(descriptors, context);
|
|
204
|
-
},
|
|
205
72
|
},
|
|
206
73
|
create(): ControlTargetInstance<'sql', 'postgres'> {
|
|
207
74
|
return {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Re-exported so user-edited migration.ts files only need to depend on
|
|
2
|
+
// `@prisma-next/target-postgres/migration` to fill in planner-emitted
|
|
3
|
+
// `placeholder("…")` slots, instead of pulling in `@prisma-next/errors`
|
|
4
|
+
// directly. The planner emits an import from this same module.
|
|
5
|
+
export { placeholder } from '@prisma-next/errors/migration';
|
|
6
|
+
export {
|
|
7
|
+
addColumn,
|
|
8
|
+
alterColumnType,
|
|
9
|
+
dropColumn,
|
|
10
|
+
dropDefault,
|
|
11
|
+
dropNotNull,
|
|
12
|
+
setDefault,
|
|
13
|
+
setNotNull,
|
|
14
|
+
} from '../core/migrations/operations/columns';
|
|
15
|
+
export {
|
|
16
|
+
addForeignKey,
|
|
17
|
+
addPrimaryKey,
|
|
18
|
+
addUnique,
|
|
19
|
+
dropConstraint,
|
|
20
|
+
} from '../core/migrations/operations/constraints';
|
|
21
|
+
export {
|
|
22
|
+
type DataTransformClosure,
|
|
23
|
+
type DataTransformOptions,
|
|
24
|
+
dataTransform,
|
|
25
|
+
} from '../core/migrations/operations/data-transform';
|
|
26
|
+
export { createExtension, createSchema } from '../core/migrations/operations/dependencies';
|
|
27
|
+
export {
|
|
28
|
+
addEnumValues,
|
|
29
|
+
createEnumType,
|
|
30
|
+
dropEnumType,
|
|
31
|
+
renameType,
|
|
32
|
+
} from '../core/migrations/operations/enums';
|
|
33
|
+
export { createIndex, dropIndex } from '../core/migrations/operations/indexes';
|
|
34
|
+
export { rawSql } from '../core/migrations/operations/raw';
|
|
35
|
+
export { createTable, dropTable } from '../core/migrations/operations/tables';
|
|
36
|
+
// Target-owned base class for migrations. Aliased to `Migration` so
|
|
37
|
+
// user-edited migration.ts files (and the renderer's scaffold) read as
|
|
38
|
+
// `class M extends Migration { … }` without having to thread the
|
|
39
|
+
// target-details generic or redeclare `targetId`.
|
|
40
|
+
export { PostgresMigration as Migration } from '../core/migrations/postgres-migration';
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import * as _prisma_next_family_sql_operation_descriptors0 from "@prisma-next/family-sql/operation-descriptors";
|
|
2
|
-
import { AddColumnDescriptor, AddEnumValuesDescriptor, AddForeignKeyDescriptor, AddPrimaryKeyDescriptor, AddUniqueDescriptor, AlterColumnTypeDescriptor, Buildable, Buildable as Buildable$1, CreateDependencyDescriptor, CreateEnumTypeDescriptor, CreateIndexDescriptor, CreateTableDescriptor, DataTransformDescriptor, DropColumnDescriptor, DropConstraintDescriptor, DropDefaultDescriptor, DropEnumTypeDescriptor, DropIndexDescriptor, DropNotNullDescriptor, DropTableDescriptor, RenameTypeDescriptor, SetDefaultDescriptor, SetNotNullDescriptor, SqlMigrationOpDescriptor, SqlMigrationOpDescriptor as SqlMigrationOpDescriptor$1, TODO, TodoMarker, TodoMarker as TodoMarker$1, addColumn, addEnumValues, addForeignKey, addPrimaryKey, addUnique, alterColumnType, createDependency, createEnumType, createIndex, createTable, dropColumn, dropConstraint, dropDefault, dropEnumType, dropIndex, dropNotNull, dropTable, renameType, setDefault, setNotNull } from "@prisma-next/family-sql/operation-descriptors";
|
|
3
|
-
import { Db, TableProxyContract } from "@prisma-next/sql-builder/types";
|
|
4
|
-
import { SqlQueryPlan } from "@prisma-next/sql-relational-core/plan";
|
|
5
|
-
|
|
6
|
-
//#region src/core/migrations/operation-descriptors.d.ts
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A single query plan input — callback, pre-built plan, or TODO placeholder.
|
|
10
|
-
* @template TContract - The contract type for the Db client. Defaults to any
|
|
11
|
-
* (untyped). Use createBuilders<Contract>() to get typed callbacks.
|
|
12
|
-
*/
|
|
13
|
-
type QueryPlanInput<TContract extends TableProxyContract = any> = ((db: Db<TContract>) => Buildable$1) | SqlQueryPlan | TodoMarker$1;
|
|
14
|
-
/** Run input — a callback returning one or many buildables, or a pre-built plan/TODO. */
|
|
15
|
-
type RunInput<TContract extends TableProxyContract = any> = ((db: Db<TContract>) => Buildable$1 | readonly Buildable$1[]) | SqlQueryPlan | TodoMarker$1;
|
|
16
|
-
type PostgresMigrationOpDescriptor = SqlMigrationOpDescriptor$1 | DataTransformDescriptor;
|
|
17
|
-
declare function dataTransform<TContract extends TableProxyContract = any>(name: string, options: {
|
|
18
|
-
check: QueryPlanInput<TContract> | Buildable$1 | boolean;
|
|
19
|
-
run: RunInput<TContract> | Buildable$1;
|
|
20
|
-
}): DataTransformDescriptor;
|
|
21
|
-
/**
|
|
22
|
-
* Creates typed migration builder functions parameterized by the contract type.
|
|
23
|
-
* The dataTransform callback receives a fully typed Db<TContract> client.
|
|
24
|
-
*
|
|
25
|
-
* Usage:
|
|
26
|
-
* ```typescript
|
|
27
|
-
* import type { Contract } from "../../src/prisma/contract.d"
|
|
28
|
-
* import { createBuilders } from "@prisma-next/target-postgres/migration-builders"
|
|
29
|
-
*
|
|
30
|
-
* const { addColumn, dataTransform, setNotNull } = createBuilders<Contract>()
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
declare function createBuilders<TContract extends TableProxyContract>(): {
|
|
34
|
-
dataTransform: (name: string, options: {
|
|
35
|
-
check: boolean | Buildable$1 | QueryPlanInput<TContract>;
|
|
36
|
-
run: Buildable$1 | RunInput<TContract>;
|
|
37
|
-
}) => DataTransformDescriptor;
|
|
38
|
-
TODO: symbol;
|
|
39
|
-
createTable: typeof _prisma_next_family_sql_operation_descriptors0.createTable;
|
|
40
|
-
dropTable: typeof _prisma_next_family_sql_operation_descriptors0.dropTable;
|
|
41
|
-
addColumn: typeof _prisma_next_family_sql_operation_descriptors0.addColumn;
|
|
42
|
-
dropColumn: typeof _prisma_next_family_sql_operation_descriptors0.dropColumn;
|
|
43
|
-
alterColumnType: typeof _prisma_next_family_sql_operation_descriptors0.alterColumnType;
|
|
44
|
-
setNotNull: typeof _prisma_next_family_sql_operation_descriptors0.setNotNull;
|
|
45
|
-
dropNotNull: typeof _prisma_next_family_sql_operation_descriptors0.dropNotNull;
|
|
46
|
-
setDefault: typeof _prisma_next_family_sql_operation_descriptors0.setDefault;
|
|
47
|
-
dropDefault: typeof _prisma_next_family_sql_operation_descriptors0.dropDefault;
|
|
48
|
-
addPrimaryKey: typeof _prisma_next_family_sql_operation_descriptors0.addPrimaryKey;
|
|
49
|
-
addUnique: typeof _prisma_next_family_sql_operation_descriptors0.addUnique;
|
|
50
|
-
addForeignKey: typeof _prisma_next_family_sql_operation_descriptors0.addForeignKey;
|
|
51
|
-
dropConstraint: typeof _prisma_next_family_sql_operation_descriptors0.dropConstraint;
|
|
52
|
-
createIndex: typeof _prisma_next_family_sql_operation_descriptors0.createIndex;
|
|
53
|
-
dropIndex: typeof _prisma_next_family_sql_operation_descriptors0.dropIndex;
|
|
54
|
-
createEnumType: typeof _prisma_next_family_sql_operation_descriptors0.createEnumType;
|
|
55
|
-
addEnumValues: typeof _prisma_next_family_sql_operation_descriptors0.addEnumValues;
|
|
56
|
-
dropEnumType: typeof _prisma_next_family_sql_operation_descriptors0.dropEnumType;
|
|
57
|
-
renameType: typeof _prisma_next_family_sql_operation_descriptors0.renameType;
|
|
58
|
-
createDependency: typeof _prisma_next_family_sql_operation_descriptors0.createDependency;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* All builder functions keyed by descriptor kind.
|
|
62
|
-
*/
|
|
63
|
-
declare const builders: {
|
|
64
|
-
readonly dataTransform: typeof dataTransform;
|
|
65
|
-
readonly createTable: typeof _prisma_next_family_sql_operation_descriptors0.createTable;
|
|
66
|
-
readonly dropTable: typeof _prisma_next_family_sql_operation_descriptors0.dropTable;
|
|
67
|
-
readonly addColumn: typeof _prisma_next_family_sql_operation_descriptors0.addColumn;
|
|
68
|
-
readonly dropColumn: typeof _prisma_next_family_sql_operation_descriptors0.dropColumn;
|
|
69
|
-
readonly alterColumnType: typeof _prisma_next_family_sql_operation_descriptors0.alterColumnType;
|
|
70
|
-
readonly setNotNull: typeof _prisma_next_family_sql_operation_descriptors0.setNotNull;
|
|
71
|
-
readonly dropNotNull: typeof _prisma_next_family_sql_operation_descriptors0.dropNotNull;
|
|
72
|
-
readonly setDefault: typeof _prisma_next_family_sql_operation_descriptors0.setDefault;
|
|
73
|
-
readonly dropDefault: typeof _prisma_next_family_sql_operation_descriptors0.dropDefault;
|
|
74
|
-
readonly addPrimaryKey: typeof _prisma_next_family_sql_operation_descriptors0.addPrimaryKey;
|
|
75
|
-
readonly addUnique: typeof _prisma_next_family_sql_operation_descriptors0.addUnique;
|
|
76
|
-
readonly addForeignKey: typeof _prisma_next_family_sql_operation_descriptors0.addForeignKey;
|
|
77
|
-
readonly dropConstraint: typeof _prisma_next_family_sql_operation_descriptors0.dropConstraint;
|
|
78
|
-
readonly createIndex: typeof _prisma_next_family_sql_operation_descriptors0.createIndex;
|
|
79
|
-
readonly dropIndex: typeof _prisma_next_family_sql_operation_descriptors0.dropIndex;
|
|
80
|
-
readonly createEnumType: typeof _prisma_next_family_sql_operation_descriptors0.createEnumType;
|
|
81
|
-
readonly addEnumValues: typeof _prisma_next_family_sql_operation_descriptors0.addEnumValues;
|
|
82
|
-
readonly dropEnumType: typeof _prisma_next_family_sql_operation_descriptors0.dropEnumType;
|
|
83
|
-
readonly renameType: typeof _prisma_next_family_sql_operation_descriptors0.renameType;
|
|
84
|
-
readonly createDependency: typeof _prisma_next_family_sql_operation_descriptors0.createDependency;
|
|
85
|
-
};
|
|
86
|
-
//#endregion
|
|
87
|
-
export { type AddColumnDescriptor, type AddEnumValuesDescriptor, type AddForeignKeyDescriptor, type AddPrimaryKeyDescriptor, type AddUniqueDescriptor, type AlterColumnTypeDescriptor, type Buildable, type CreateDependencyDescriptor, type CreateEnumTypeDescriptor, type CreateIndexDescriptor, type CreateTableDescriptor, type DataTransformDescriptor, type DropColumnDescriptor, type DropConstraintDescriptor, type DropDefaultDescriptor, type DropEnumTypeDescriptor, type DropIndexDescriptor, type DropNotNullDescriptor, type DropTableDescriptor, type PostgresMigrationOpDescriptor, type QueryPlanInput, type RenameTypeDescriptor, type RunInput, type SetDefaultDescriptor, type SetNotNullDescriptor, type SqlMigrationOpDescriptor, TODO, type TodoMarker, addColumn, addEnumValues, addForeignKey, addPrimaryKey, addUnique, alterColumnType, builders, createBuilders, createDependency, createEnumType, createIndex, createTable, dataTransform, dropColumn, dropConstraint, dropDefault, dropEnumType, dropIndex, dropNotNull, dropTable, renameType, setDefault, setNotNull };
|
|
88
|
-
//# sourceMappingURL=migration-builders.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migration-builders.d.mts","names":[],"sources":["../src/core/migrations/operation-descriptors.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAsFA;;AACa,KARD,cAQC,CAAA,kBARgC,kBAQhC,GAAA,GAAA,CAAA,GAAA,CAAA,CAAA,EAAA,EAPH,EAOG,CAPA,SAOA,CAAA,EAAA,GAPe,WAOf,CAAA,GANT,YAMS,GALT,YAKS;;AAAe,KADhB,QACgB,CAAA,kBADW,kBACX,GAAA,GAAA,CAAA,GAAA,CAAA,CAAA,EAAA,EAAlB,EAAkB,CAAf,SAAe,CAAA,EAAA,GAAA,WAAA,GAAA,SAAqB,WAArB,EAAA,CAAA,GACxB,YADwB,GAExB,YAFwB;AAAqB,KAQrC,6BAAA,GAAgC,0BARK,GAQsB,uBARtB;AAC7C,iBAsBY,aAtBZ,CAAA,kBAsB4C,kBAtB5C,GAAA,GAAA,CAAA,CAAA,IAAA,EAAA,MAAA,EAAA,OAAA,EAAA;EACA,KAAA,EAwBO,cAxBP,CAwBsB,SAxBtB,CAAA,GAwBmC,WAxBnC,GAAA,OAAA;EAAU,GAAA,EAyBL,QAzBK,CAyBI,SAzBJ,CAAA,GAyBiB,WAzBjB;AAMd,CAAA,CAAA,EAqBG,uBArBS;AAeZ;;;;;;;;;;AAyCA;;iBAAgB,iCAAiC;;;;QAnC9C;;EAAA,WAAA,EAAA,OAAuB,8CAAA,CAAA,WAAvB;EAAuB,SAAA,EAAA,+DAAA;;;;;;;;;;;;;;;;;;;;;AA8C1B;;cAAa"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { C as setDefault, S as renameType, _ as dropDefault, a as addPrimaryKey, b as dropNotNull, c as builders, d as createEnumType, f as createIndex, g as dropConstraint, h as dropColumn, i as addForeignKey, l as createBuilders, m as dataTransform, n as addColumn, o as addUnique, p as createTable, r as addEnumValues, s as alterColumnType, t as TODO, u as createDependency, v as dropEnumType, w as setNotNull, x as dropTable, y as dropIndex } from "./operation-descriptors-CxymFSgK.mjs";
|
|
2
|
-
|
|
3
|
-
export { TODO, addColumn, addEnumValues, addForeignKey, addPrimaryKey, addUnique, alterColumnType, builders, createBuilders, createDependency, createEnumType, createIndex, createTable, dataTransform, dropColumn, dropConstraint, dropDefault, dropEnumType, dropIndex, dropNotNull, dropTable, renameType, setDefault, setNotNull };
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { TODO, TODO as TODO$1, addColumn, addEnumValues, addForeignKey, addPrimaryKey, addUnique, alterColumnType, builders, createDependency, createEnumType, createIndex, createTable, dropColumn, dropConstraint, dropDefault, dropEnumType, dropIndex, dropNotNull, dropTable, renameType, setDefault, setNotNull } from "@prisma-next/family-sql/operation-descriptors";
|
|
2
|
-
|
|
3
|
-
//#region src/core/migrations/operation-descriptors.ts
|
|
4
|
-
function resolveInput(input) {
|
|
5
|
-
if (typeof input === "symbol" || typeof input === "function") return input;
|
|
6
|
-
if ("build" in input && typeof input.build === "function") return input.build();
|
|
7
|
-
return input;
|
|
8
|
-
}
|
|
9
|
-
function dataTransform(name, options) {
|
|
10
|
-
const check = typeof options.check === "boolean" ? options.check : resolveInput(options.check);
|
|
11
|
-
const run = [];
|
|
12
|
-
if (typeof options.run === "function") run.push(options.run);
|
|
13
|
-
else if (typeof options.run === "symbol") run.push(options.run);
|
|
14
|
-
else run.push(resolveInput(options.run));
|
|
15
|
-
return {
|
|
16
|
-
kind: "dataTransform",
|
|
17
|
-
name,
|
|
18
|
-
source: "migration.ts",
|
|
19
|
-
check,
|
|
20
|
-
run
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Creates typed migration builder functions parameterized by the contract type.
|
|
25
|
-
* The dataTransform callback receives a fully typed Db<TContract> client.
|
|
26
|
-
*
|
|
27
|
-
* Usage:
|
|
28
|
-
* ```typescript
|
|
29
|
-
* import type { Contract } from "../../src/prisma/contract.d"
|
|
30
|
-
* import { createBuilders } from "@prisma-next/target-postgres/migration-builders"
|
|
31
|
-
*
|
|
32
|
-
* const { addColumn, dataTransform, setNotNull } = createBuilders<Contract>()
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
function createBuilders() {
|
|
36
|
-
return {
|
|
37
|
-
...builders,
|
|
38
|
-
dataTransform,
|
|
39
|
-
TODO
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* All builder functions keyed by descriptor kind.
|
|
44
|
-
*/
|
|
45
|
-
const builders$1 = {
|
|
46
|
-
...builders,
|
|
47
|
-
dataTransform
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
//#endregion
|
|
51
|
-
export { setDefault as C, renameType as S, dropDefault as _, addPrimaryKey as a, dropNotNull as b, builders$1 as c, createEnumType as d, createIndex as f, dropConstraint as g, dropColumn as h, addForeignKey as i, createBuilders as l, dataTransform as m, addColumn as n, addUnique as o, createTable as p, addEnumValues as r, alterColumnType as s, TODO$1 as t, createDependency as u, dropEnumType as v, setNotNull as w, dropTable as x, dropIndex as y };
|
|
52
|
-
//# sourceMappingURL=operation-descriptors-CxymFSgK.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operation-descriptors-CxymFSgK.mjs","names":["run: (symbol | object | ((...args: never[]) => unknown))[]","structuralBuilders","builders"],"sources":["../src/core/migrations/operation-descriptors.ts"],"sourcesContent":["/**\n * Postgres migration operation descriptors.\n *\n * Re-exports all structural SQL descriptors from @prisma-next/family-sql\n * and adds data transform support with typed query builder callbacks.\n */\n\nimport type { Db, TableProxyContract } from '@prisma-next/sql-builder/types';\nimport type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';\n\n// Re-export structural descriptors from sql-family\nexport {\n type AddColumnDescriptor,\n type AddEnumValuesDescriptor,\n type AddForeignKeyDescriptor,\n type AddPrimaryKeyDescriptor,\n type AddUniqueDescriptor,\n type AlterColumnTypeDescriptor,\n addColumn,\n addEnumValues,\n addForeignKey,\n addPrimaryKey,\n addUnique,\n alterColumnType,\n type Buildable,\n type CreateDependencyDescriptor,\n type CreateEnumTypeDescriptor,\n type CreateIndexDescriptor,\n type CreateTableDescriptor,\n createDependency,\n createEnumType,\n createIndex,\n createTable,\n type DropColumnDescriptor,\n type DropConstraintDescriptor,\n type DropDefaultDescriptor,\n type DropEnumTypeDescriptor,\n type DropIndexDescriptor,\n type DropNotNullDescriptor,\n type DropTableDescriptor,\n dropColumn,\n dropConstraint,\n dropDefault,\n dropEnumType,\n dropIndex,\n dropNotNull,\n dropTable,\n type RenameTypeDescriptor,\n renameType,\n type SetDefaultDescriptor,\n type SetNotNullDescriptor,\n type SqlMigrationOpDescriptor,\n setDefault,\n setNotNull,\n TODO,\n type TodoMarker,\n} from '@prisma-next/family-sql/operation-descriptors';\n\nimport {\n type Buildable,\n type DataTransformDescriptor,\n type SqlMigrationOpDescriptor,\n builders as structuralBuilders,\n TODO,\n type TodoMarker,\n} from '@prisma-next/family-sql/operation-descriptors';\n\nexport type { DataTransformDescriptor };\n\n// ============================================================================\n// Typed data transform inputs (for createBuilders<Contract>())\n// ============================================================================\n\n/**\n * A single query plan input — callback, pre-built plan, or TODO placeholder.\n * @template TContract - The contract type for the Db client. Defaults to any\n * (untyped). Use createBuilders<Contract>() to get typed callbacks.\n */\n// biome-ignore lint/suspicious/noExplicitAny: default is untyped; createBuilders narrows this\nexport type QueryPlanInput<TContract extends TableProxyContract = any> =\n | ((db: Db<TContract>) => Buildable)\n | SqlQueryPlan\n | TodoMarker;\n\n/** Run input — a callback returning one or many buildables, or a pre-built plan/TODO. */\n// biome-ignore lint/suspicious/noExplicitAny: default is untyped; createBuilders narrows this\nexport type RunInput<TContract extends TableProxyContract = any> =\n | ((db: Db<TContract>) => Buildable | readonly Buildable[])\n | SqlQueryPlan\n | TodoMarker;\n\n// ============================================================================\n// Postgres descriptor union = SQL structural + data transforms\n// ============================================================================\n\nexport type PostgresMigrationOpDescriptor = SqlMigrationOpDescriptor | DataTransformDescriptor;\n\n// ============================================================================\n// Data transform builder\n// ============================================================================\n\nfunction resolveInput(input: QueryPlanInput): QueryPlanInput {\n if (typeof input === 'symbol' || typeof input === 'function') return input;\n if ('build' in input && typeof (input as Buildable).build === 'function') {\n return (input as Buildable).build();\n }\n return input;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: default is untyped; createBuilders narrows this\nexport function dataTransform<TContract extends TableProxyContract = any>(\n name: string,\n options: {\n check: QueryPlanInput<TContract> | Buildable | boolean;\n run: RunInput<TContract> | Buildable;\n },\n): DataTransformDescriptor {\n const check =\n typeof options.check === 'boolean'\n ? options.check\n : resolveInput(options.check as QueryPlanInput);\n\n const run: (symbol | object | ((...args: never[]) => unknown))[] = [];\n if (typeof options.run === 'function') {\n run.push(options.run);\n } else if (typeof options.run === 'symbol') {\n run.push(options.run);\n } else {\n run.push(resolveInput(options.run as QueryPlanInput));\n }\n return {\n kind: 'dataTransform' as const,\n name,\n source: 'migration.ts',\n check,\n run,\n };\n}\n\n/**\n * Creates typed migration builder functions parameterized by the contract type.\n * The dataTransform callback receives a fully typed Db<TContract> client.\n *\n * Usage:\n * ```typescript\n * import type { Contract } from \"../../src/prisma/contract.d\"\n * import { createBuilders } from \"@prisma-next/target-postgres/migration-builders\"\n *\n * const { addColumn, dataTransform, setNotNull } = createBuilders<Contract>()\n * ```\n */\nexport function createBuilders<TContract extends TableProxyContract>() {\n return {\n ...structuralBuilders,\n dataTransform: dataTransform<TContract>,\n TODO,\n };\n}\n\n/**\n * All builder functions keyed by descriptor kind.\n */\nexport const builders = {\n ...structuralBuilders,\n dataTransform,\n} as const;\n"],"mappings":";;;AAqGA,SAAS,aAAa,OAAuC;AAC3D,KAAI,OAAO,UAAU,YAAY,OAAO,UAAU,WAAY,QAAO;AACrE,KAAI,WAAW,SAAS,OAAQ,MAAoB,UAAU,WAC5D,QAAQ,MAAoB,OAAO;AAErC,QAAO;;AAIT,SAAgB,cACd,MACA,SAIyB;CACzB,MAAM,QACJ,OAAO,QAAQ,UAAU,YACrB,QAAQ,QACR,aAAa,QAAQ,MAAwB;CAEnD,MAAMA,MAA6D,EAAE;AACrE,KAAI,OAAO,QAAQ,QAAQ,WACzB,KAAI,KAAK,QAAQ,IAAI;UACZ,OAAO,QAAQ,QAAQ,SAChC,KAAI,KAAK,QAAQ,IAAI;KAErB,KAAI,KAAK,aAAa,QAAQ,IAAsB,CAAC;AAEvD,QAAO;EACL,MAAM;EACN;EACA,QAAQ;EACR;EACA;EACD;;;;;;;;;;;;;;AAeH,SAAgB,iBAAuD;AACrE,QAAO;EACL,GAAGC;EACY;EACf;EACD;;;;;AAMH,MAAaC,aAAW;CACtB,GAAGD;CACH;CACD"}
|