@prisma-next/family-sql 0.12.0-dev.26 → 0.12.0-dev.28
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 +91 -5
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +143 -6
- package/dist/control.mjs.map +1 -1
- package/dist/migration.d.mts +1 -1
- package/dist/{types-DsdKvKFN.d.mts → types-B084B5kI.d.mts} +3 -2
- package/dist/{types-DsdKvKFN.d.mts.map → types-B084B5kI.d.mts.map} +1 -1
- package/package.json +21 -21
- package/src/core/migrations/control-policy.ts +237 -4
- package/src/core/migrations/plan-helpers.ts +16 -0
- package/src/core/migrations/types.ts +3 -1
- package/src/exports/control.ts +5 -1
package/dist/migration.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as SqlPlanTargetDetails, p as SqlMigrationPlanOperation } from "./types-
|
|
1
|
+
import { T as SqlPlanTargetDetails, p as SqlMigrationPlanOperation } from "./types-B084B5kI.mjs";
|
|
2
2
|
import { Migration } from "@prisma-next/migration-tools/migration";
|
|
3
3
|
|
|
4
4
|
//#region src/core/sql-migration.d.ts
|
|
@@ -287,8 +287,9 @@ interface SqlMigrationPlan<TTargetDetails> extends MigrationPlan {
|
|
|
287
287
|
readonly providedInvariants: readonly string[];
|
|
288
288
|
readonly meta?: AnyRecord;
|
|
289
289
|
}
|
|
290
|
-
type SqlPlannerConflictKind = 'typeMismatch' | 'nullabilityConflict' | 'indexIncompatible' | 'foreignKeyConflict' | 'missingButNonAdditive' | 'unsupportedOperation';
|
|
290
|
+
type SqlPlannerConflictKind = 'typeMismatch' | 'nullabilityConflict' | 'indexIncompatible' | 'foreignKeyConflict' | 'missingButNonAdditive' | 'unsupportedOperation' | 'controlPolicySuppressedCall';
|
|
291
291
|
interface SqlPlannerConflictLocation {
|
|
292
|
+
readonly namespace?: string;
|
|
292
293
|
readonly table?: string;
|
|
293
294
|
readonly column?: string;
|
|
294
295
|
readonly index?: string;
|
|
@@ -472,4 +473,4 @@ interface CreateSqlMigrationPlanOptions<TTargetDetails> {
|
|
|
472
473
|
}
|
|
473
474
|
//#endregion
|
|
474
475
|
export { SqlPlannerResult as A, SqlMigrationRunnerResult as C, SqlPlannerConflictKind as D, SqlPlannerConflict as E, StorageTypePlanResult as M, SqlControlFamilyInstance as N, SqlPlannerConflictLocation as O, SqlMigrationRunnerFailure as S, SqlPlanTargetDetails as T, SqlMigrationPlannerPlanOptions as _, FieldEvent as a, SqlMigrationRunnerExecuteCallbacks as b, SqlControlAdapterDescriptor as c, SqlMigrationPlan as d, SqlMigrationPlanContractInfo as f, SqlMigrationPlanner as g, SqlMigrationPlanOperationTarget as h, ExpandNativeTypeInput as i, SqlPlannerSuccessResult as j, SqlPlannerFailureResult as k, SqlControlExtensionDescriptor as l, SqlMigrationPlanOperationStep as m, CodecControlHooks as n, FieldEventContext as o, SqlMigrationPlanOperation as p, CreateSqlMigrationPlanOptions as r, ResolveIdentityValueInput as s, AnyRecord as t, SqlControlTargetDescriptor as u, SqlMigrationRunner as v, SqlMigrationRunnerSuccessValue as w, SqlMigrationRunnerExecuteOptions as x, SqlMigrationRunnerErrorCode as y };
|
|
475
|
-
//# sourceMappingURL=types-
|
|
476
|
+
//# sourceMappingURL=types-B084B5kI.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-B084B5kI.d.mts","names":[],"sources":["../src/core/control-instance.ts","../src/core/migrations/types.ts"],"mappings":";;;;;;;;;;;;;;UA8KU,eAAA;EAAA,SACC,MAAA;EAAA,SACA,QAAA;EAAA,SACA,QAAA;EAAA,SACA,UAAA;AAAA;AAAA,KAGN,uBAAA,GAA0B,GAAG,SAAS,eAAA;AAAA,UAEjC,sBAAA;EAAA,SACC,gBAAA,EAAkB,aAAA,CAAc,eAAA;EAAA,SAChC,YAAA,EAAc,aAAA;EAAA,SACd,oBAAA,EAAsB,uB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SACb,UAAA,WAAqB,yBAAA,CAA0B,cAAA;EAlQxB;;;;;EAAA,SAwQvB,kBAAA;EAAA,SACA,IAAA,GAAO,SAAA;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/family-sql",
|
|
3
|
-
"version": "0.12.0-dev.
|
|
3
|
+
"version": "0.12.0-dev.28",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "SQL family descriptor for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/contract": "0.12.0-dev.
|
|
10
|
-
"@prisma-next/emitter": "0.12.0-dev.
|
|
11
|
-
"@prisma-next/framework-components": "0.12.0-dev.
|
|
12
|
-
"@prisma-next/migration-tools": "0.12.0-dev.
|
|
13
|
-
"@prisma-next/operations": "0.12.0-dev.
|
|
14
|
-
"@prisma-next/sql-contract": "0.12.0-dev.
|
|
15
|
-
"@prisma-next/sql-contract-emitter": "0.12.0-dev.
|
|
16
|
-
"@prisma-next/sql-contract-ts": "0.12.0-dev.
|
|
17
|
-
"@prisma-next/sql-operations": "0.12.0-dev.
|
|
18
|
-
"@prisma-next/sql-relational-core": "0.12.0-dev.
|
|
19
|
-
"@prisma-next/sql-runtime": "0.12.0-dev.
|
|
20
|
-
"@prisma-next/sql-schema-ir": "0.12.0-dev.
|
|
21
|
-
"@prisma-next/utils": "0.12.0-dev.
|
|
9
|
+
"@prisma-next/contract": "0.12.0-dev.28",
|
|
10
|
+
"@prisma-next/emitter": "0.12.0-dev.28",
|
|
11
|
+
"@prisma-next/framework-components": "0.12.0-dev.28",
|
|
12
|
+
"@prisma-next/migration-tools": "0.12.0-dev.28",
|
|
13
|
+
"@prisma-next/operations": "0.12.0-dev.28",
|
|
14
|
+
"@prisma-next/sql-contract": "0.12.0-dev.28",
|
|
15
|
+
"@prisma-next/sql-contract-emitter": "0.12.0-dev.28",
|
|
16
|
+
"@prisma-next/sql-contract-ts": "0.12.0-dev.28",
|
|
17
|
+
"@prisma-next/sql-operations": "0.12.0-dev.28",
|
|
18
|
+
"@prisma-next/sql-relational-core": "0.12.0-dev.28",
|
|
19
|
+
"@prisma-next/sql-runtime": "0.12.0-dev.28",
|
|
20
|
+
"@prisma-next/sql-schema-ir": "0.12.0-dev.28",
|
|
21
|
+
"@prisma-next/utils": "0.12.0-dev.28",
|
|
22
22
|
"arktype": "^2.2.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@prisma-next/driver-postgres": "0.12.0-dev.
|
|
26
|
-
"@prisma-next/psl-parser": "0.12.0-dev.
|
|
27
|
-
"@prisma-next/psl-printer": "0.12.0-dev.
|
|
28
|
-
"@prisma-next/sql-contract-psl": "0.12.0-dev.
|
|
29
|
-
"@prisma-next/test-utils": "0.12.0-dev.
|
|
30
|
-
"@prisma-next/tsconfig": "0.12.0-dev.
|
|
31
|
-
"@prisma-next/tsdown": "0.12.0-dev.
|
|
25
|
+
"@prisma-next/driver-postgres": "0.12.0-dev.28",
|
|
26
|
+
"@prisma-next/psl-parser": "0.12.0-dev.28",
|
|
27
|
+
"@prisma-next/psl-printer": "0.12.0-dev.28",
|
|
28
|
+
"@prisma-next/sql-contract-psl": "0.12.0-dev.28",
|
|
29
|
+
"@prisma-next/test-utils": "0.12.0-dev.28",
|
|
30
|
+
"@prisma-next/tsconfig": "0.12.0-dev.28",
|
|
31
|
+
"@prisma-next/tsdown": "0.12.0-dev.28",
|
|
32
32
|
"tsdown": "0.22.0",
|
|
33
33
|
"typescript": "5.9.3",
|
|
34
34
|
"vitest": "4.1.6"
|
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
effectiveControlPolicy,
|
|
5
5
|
} from '@prisma-next/contract/types';
|
|
6
6
|
import type { SqlStorage } from '@prisma-next/sql-contract/types';
|
|
7
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
8
|
+
import type { SqlPlannerConflict } from './types';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* The target object a control policy governs for a single planner call,
|
|
@@ -34,7 +36,7 @@ export interface ControlPolicySubject {
|
|
|
34
36
|
* policy is forced to `external` regardless of the node's own declaration.
|
|
35
37
|
* Every other default defers to the node's effective control policy.
|
|
36
38
|
*/
|
|
37
|
-
function controlPolicyForCall(
|
|
39
|
+
export function controlPolicyForCall(
|
|
38
40
|
subject: ControlPolicySubject | undefined,
|
|
39
41
|
defaultControlPolicy: ControlPolicy | undefined,
|
|
40
42
|
): ControlPolicy {
|
|
@@ -69,21 +71,252 @@ function callAllowedUnderControlPolicy(
|
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
|
|
74
|
+
function defaultSubjectLabel(
|
|
75
|
+
factoryName: string,
|
|
76
|
+
subject: ControlPolicySubject | undefined,
|
|
77
|
+
): string {
|
|
78
|
+
if (subject?.table) {
|
|
79
|
+
return `${factoryName}(${subject.table})`;
|
|
80
|
+
}
|
|
81
|
+
if (subject?.typeName) {
|
|
82
|
+
return `${factoryName}(${subject.typeName})`;
|
|
83
|
+
}
|
|
84
|
+
return factoryName;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function suppressionSummary(
|
|
88
|
+
subjectLabel: string,
|
|
89
|
+
subject: ControlPolicySubject | undefined,
|
|
90
|
+
effectivePolicy: ControlPolicy,
|
|
91
|
+
): string {
|
|
92
|
+
const namespace = subject?.namespaceId ?? 'unknown';
|
|
93
|
+
const declared = subject?.explicitNodeControlPolicy;
|
|
94
|
+
if (effectivePolicy === 'external' && declared === 'managed') {
|
|
95
|
+
return `control policy suppressed: ${subjectLabel} — namespace '${namespace}' has effective control 'external' but table declared 'managed'`;
|
|
96
|
+
}
|
|
97
|
+
const declaredSuffix = declared ? ` but table declared '${declared}'` : '';
|
|
98
|
+
return `control policy suppressed: ${subjectLabel} — namespace '${namespace}' has effective control '${effectivePolicy}'${declaredSuffix}`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function buildSubjectSuppressionWarning(
|
|
102
|
+
subject: ControlPolicySubject | undefined,
|
|
103
|
+
effectivePolicy: ControlPolicy,
|
|
104
|
+
factoryName: string,
|
|
105
|
+
formatSubjectLabel: (factoryName: string, subject: ControlPolicySubject | undefined) => string,
|
|
106
|
+
): SqlPlannerConflict {
|
|
107
|
+
const subjectLabel = formatSubjectLabel(factoryName, subject);
|
|
108
|
+
return {
|
|
109
|
+
kind: 'controlPolicySuppressedCall',
|
|
110
|
+
summary: suppressionSummary(subjectLabel, subject, effectivePolicy),
|
|
111
|
+
location: {
|
|
112
|
+
...ifDefined('namespace', subject?.namespaceId),
|
|
113
|
+
...ifDefined('table', subject?.table),
|
|
114
|
+
...ifDefined('column', subject?.column),
|
|
115
|
+
...ifDefined('type', subject?.typeName),
|
|
116
|
+
},
|
|
117
|
+
meta: {
|
|
118
|
+
controlPolicy: effectivePolicy,
|
|
119
|
+
factoryName,
|
|
120
|
+
...ifDefined('declaredControlPolicy', subject?.explicitNodeControlPolicy),
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function defaultModificationFactoryNameForSubject(subject: ControlPolicySubject): string {
|
|
126
|
+
if (subject.table) return 'alterTable';
|
|
127
|
+
if (subject.typeName) return 'alterType';
|
|
128
|
+
return 'alterSchema';
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Partition the calls produced for a single set of subjects into those the
|
|
133
|
+
* effective control policy permits (`kept`) and a list of
|
|
134
|
+
* {@link SqlPlannerConflict} warnings describing the suppressed calls.
|
|
135
|
+
*
|
|
136
|
+
* **Prefer {@link partitionIssuesByControlPolicy}** for the schema-issue
|
|
137
|
+
* pipeline: it filters subjects out of the planner's *input* so the planner
|
|
138
|
+
* never has to reason about un-modeled state on `external`/`observed`
|
|
139
|
+
* subjects. This call-level helper remains for paths that bypass the issue
|
|
140
|
+
* pipeline — currently the codec-emitted field-event ops, which originate
|
|
141
|
+
* from declared contract fields rather than from introspected schema state
|
|
142
|
+
* and therefore cannot trip the diff engine.
|
|
143
|
+
*/
|
|
144
|
+
export function partitionCallsByControlPolicy<TCall>(options: {
|
|
73
145
|
readonly calls: readonly TCall[];
|
|
74
146
|
readonly contract: Contract<SqlStorage>;
|
|
75
147
|
readonly resolveControlPolicySubject: (call: TCall) => ControlPolicySubject | undefined;
|
|
76
|
-
|
|
148
|
+
readonly resolveFactoryName: (call: TCall) => string;
|
|
149
|
+
readonly formatSubjectLabel?: (
|
|
150
|
+
factoryName: string,
|
|
151
|
+
subject: ControlPolicySubject | undefined,
|
|
152
|
+
) => string;
|
|
153
|
+
}): {
|
|
154
|
+
readonly kept: readonly TCall[];
|
|
155
|
+
readonly warnings: readonly SqlPlannerConflict[];
|
|
156
|
+
} {
|
|
77
157
|
const defaultControlPolicy = options.contract.defaultControlPolicy;
|
|
158
|
+
const formatSubjectLabel = options.formatSubjectLabel ?? defaultSubjectLabel;
|
|
78
159
|
const kept: TCall[] = [];
|
|
160
|
+
const warnings: SqlPlannerConflict[] = [];
|
|
79
161
|
|
|
80
162
|
for (const call of options.calls) {
|
|
81
163
|
const subject = options.resolveControlPolicySubject(call);
|
|
82
164
|
const policy = controlPolicyForCall(subject, defaultControlPolicy);
|
|
83
165
|
if (callAllowedUnderControlPolicy(policy, subject)) {
|
|
84
166
|
kept.push(call);
|
|
167
|
+
} else {
|
|
168
|
+
const factoryName = options.resolveFactoryName(call);
|
|
169
|
+
warnings.push(
|
|
170
|
+
buildSubjectSuppressionWarning(subject, policy, factoryName, formatSubjectLabel),
|
|
171
|
+
);
|
|
85
172
|
}
|
|
86
173
|
}
|
|
87
174
|
|
|
88
|
-
return Object.freeze(
|
|
175
|
+
return Object.freeze({
|
|
176
|
+
kept: Object.freeze(kept),
|
|
177
|
+
warnings: Object.freeze(warnings),
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Partition a list of schema-issue-shaped inputs by the effective control
|
|
183
|
+
* policy of each issue's subject *before* the planner is invoked.
|
|
184
|
+
*
|
|
185
|
+
* `plannable` is the list of issues whose subject's effective policy permits
|
|
186
|
+
* the planner to act on them (`managed`, or `tolerated` for whole-object
|
|
187
|
+
* creation issues only). Issues for `external`/`observed` subjects, and
|
|
188
|
+
* non-creation issues for `tolerated` subjects, are dropped from the planner's
|
|
189
|
+
* input entirely — they never enter introspection-driven planning, never feed
|
|
190
|
+
* the diff engine, and never produce DDL calls that would have to be
|
|
191
|
+
* post-filtered. This sidesteps a class of failure where the diff engine
|
|
192
|
+
* cannot reason about the live shape of a subject the user marked as
|
|
193
|
+
* out-of-scope (`external`).
|
|
194
|
+
*
|
|
195
|
+
* `warnings` is one {@link SqlPlannerConflict} per suppressed subject (not per
|
|
196
|
+
* suppressed issue). `factoryName` is inferred from the subject's issue mix:
|
|
197
|
+
* if any of the subject's issues is whole-object creation, the warning takes
|
|
198
|
+
* the corresponding creation factoryName (e.g. `createTable`,
|
|
199
|
+
* `createEnumType`, `createSchema`); otherwise it falls back to
|
|
200
|
+
* `defaultModificationFactoryName(subject)` — a synthetic label that names
|
|
201
|
+
* the *kind* of mutation that would have run, since no concrete DDL call was
|
|
202
|
+
* generated.
|
|
203
|
+
*
|
|
204
|
+
* Unresolved-subject issues (`resolveControlPolicySubject` returns
|
|
205
|
+
* `undefined`) emit one warning each; they cannot be deduplicated because
|
|
206
|
+
* they carry no subject coordinate.
|
|
207
|
+
*/
|
|
208
|
+
export function partitionIssuesByControlPolicy<TIssue>(options: {
|
|
209
|
+
readonly issues: readonly TIssue[];
|
|
210
|
+
readonly contract: Contract<SqlStorage>;
|
|
211
|
+
/**
|
|
212
|
+
* Resolve the subject targeted by this issue (or `undefined` to fail-closed:
|
|
213
|
+
* any policy stricter than `managed` drops the issue).
|
|
214
|
+
*/
|
|
215
|
+
readonly resolveControlPolicySubject: (issue: TIssue) => ControlPolicySubject | undefined;
|
|
216
|
+
/**
|
|
217
|
+
* Resolve a creation factoryName for this issue if it represents the
|
|
218
|
+
* absence of the whole top-level object (e.g. `'createTable'` for a
|
|
219
|
+
* missing-table issue). When the issue describes a modification to an
|
|
220
|
+
* existing object, return `undefined`. Both decisions feed off this signal:
|
|
221
|
+
*
|
|
222
|
+
* 1. Under `tolerated`, only issues whose `resolveCreationFactoryName`
|
|
223
|
+
* returns a value flow into the planner (create-if-absent).
|
|
224
|
+
* 2. Subjects that have at least one creation-flavoured issue use the
|
|
225
|
+
* resolved creation factoryName for their suppression warning;
|
|
226
|
+
* otherwise they fall back to `defaultModificationFactoryName`.
|
|
227
|
+
*/
|
|
228
|
+
readonly resolveCreationFactoryName: (issue: TIssue) => string | undefined;
|
|
229
|
+
/**
|
|
230
|
+
* Default modification factoryName for a suppressed subject whose issues
|
|
231
|
+
* are all non-creation (the subject exists but has a different shape).
|
|
232
|
+
* Defaults to `'alterTable'` / `'alterType'` / `'alterSchema'` based on the
|
|
233
|
+
* subject's populated coordinates.
|
|
234
|
+
*/
|
|
235
|
+
readonly defaultModificationFactoryName?: (subject: ControlPolicySubject) => string;
|
|
236
|
+
readonly formatSubjectLabel?: (
|
|
237
|
+
factoryName: string,
|
|
238
|
+
subject: ControlPolicySubject | undefined,
|
|
239
|
+
) => string;
|
|
240
|
+
}): {
|
|
241
|
+
readonly plannable: readonly TIssue[];
|
|
242
|
+
readonly warnings: readonly SqlPlannerConflict[];
|
|
243
|
+
} {
|
|
244
|
+
const defaultControlPolicy = options.contract.defaultControlPolicy;
|
|
245
|
+
const formatSubjectLabel = options.formatSubjectLabel ?? defaultSubjectLabel;
|
|
246
|
+
const inferModificationFactoryName =
|
|
247
|
+
options.defaultModificationFactoryName ?? defaultModificationFactoryNameForSubject;
|
|
248
|
+
|
|
249
|
+
const plannable: TIssue[] = [];
|
|
250
|
+
// Resolved-subject suppressions are deduplicated by subject key so we emit
|
|
251
|
+
// one warning per suppressed subject, not one per suppressed issue.
|
|
252
|
+
// `creationFactoryName` upgrades from `undefined` to a concrete creation
|
|
253
|
+
// name the first time we see a creation-flavoured issue for the subject.
|
|
254
|
+
const suppressedSubjects = new Map<
|
|
255
|
+
string,
|
|
256
|
+
{
|
|
257
|
+
readonly subject: ControlPolicySubject;
|
|
258
|
+
readonly policy: ControlPolicy;
|
|
259
|
+
creationFactoryName?: string;
|
|
260
|
+
}
|
|
261
|
+
>();
|
|
262
|
+
const unresolvedSuppressions: SqlPlannerConflict[] = [];
|
|
263
|
+
|
|
264
|
+
for (const issue of options.issues) {
|
|
265
|
+
const subject = options.resolveControlPolicySubject(issue);
|
|
266
|
+
const policy = controlPolicyForCall(subject, defaultControlPolicy);
|
|
267
|
+
const creationFactoryName = options.resolveCreationFactoryName(issue);
|
|
268
|
+
|
|
269
|
+
if (policy === 'managed') {
|
|
270
|
+
plannable.push(issue);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
if (
|
|
274
|
+
policy === 'tolerated' &&
|
|
275
|
+
subject !== undefined &&
|
|
276
|
+
creationFactoryName !== undefined &&
|
|
277
|
+
subject.createsNewObject
|
|
278
|
+
) {
|
|
279
|
+
plannable.push(issue);
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (subject === undefined) {
|
|
284
|
+
const factoryName = creationFactoryName ?? 'unknown';
|
|
285
|
+
unresolvedSuppressions.push(
|
|
286
|
+
buildSubjectSuppressionWarning(undefined, policy, factoryName, formatSubjectLabel),
|
|
287
|
+
);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const key = subjectKey(subject);
|
|
292
|
+
const existing = suppressedSubjects.get(key);
|
|
293
|
+
if (existing) {
|
|
294
|
+
if (existing.creationFactoryName === undefined && creationFactoryName !== undefined) {
|
|
295
|
+
existing.creationFactoryName = creationFactoryName;
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
suppressedSubjects.set(key, {
|
|
299
|
+
subject,
|
|
300
|
+
policy,
|
|
301
|
+
...ifDefined('creationFactoryName', creationFactoryName),
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const warnings: SqlPlannerConflict[] = [...unresolvedSuppressions];
|
|
307
|
+
for (const entry of suppressedSubjects.values()) {
|
|
308
|
+
const factoryName = entry.creationFactoryName ?? inferModificationFactoryName(entry.subject);
|
|
309
|
+
warnings.push(
|
|
310
|
+
buildSubjectSuppressionWarning(entry.subject, entry.policy, factoryName, formatSubjectLabel),
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return Object.freeze({
|
|
315
|
+
plannable: Object.freeze(plannable),
|
|
316
|
+
warnings: Object.freeze(warnings),
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function subjectKey(subject: ControlPolicySubject): string {
|
|
321
|
+
return `${subject.namespaceId}\u0000${subject.table ?? ''}\u0000${subject.typeName ?? ''}`;
|
|
89
322
|
}
|
|
@@ -111,10 +111,26 @@ export function createMigrationPlan<TTargetDetails>(
|
|
|
111
111
|
|
|
112
112
|
export function plannerSuccess<TTargetDetails>(
|
|
113
113
|
plan: SqlMigrationPlan<TTargetDetails>,
|
|
114
|
+
warnings?: readonly SqlPlannerConflict[],
|
|
114
115
|
): SqlPlannerSuccessResult<TTargetDetails> {
|
|
115
116
|
return Object.freeze({
|
|
116
117
|
kind: 'success',
|
|
117
118
|
plan,
|
|
119
|
+
...(warnings && warnings.length > 0
|
|
120
|
+
? {
|
|
121
|
+
warnings: Object.freeze(
|
|
122
|
+
warnings.map((conflict) =>
|
|
123
|
+
Object.freeze({
|
|
124
|
+
kind: conflict.kind,
|
|
125
|
+
summary: conflict.summary,
|
|
126
|
+
...(conflict.why ? { why: conflict.why } : {}),
|
|
127
|
+
...(conflict.location ? { location: Object.freeze({ ...conflict.location }) } : {}),
|
|
128
|
+
...(conflict.meta ? { meta: cloneRecord(conflict.meta) } : {}),
|
|
129
|
+
}),
|
|
130
|
+
),
|
|
131
|
+
),
|
|
132
|
+
}
|
|
133
|
+
: {}),
|
|
118
134
|
});
|
|
119
135
|
}
|
|
120
136
|
|
|
@@ -270,9 +270,11 @@ export type SqlPlannerConflictKind =
|
|
|
270
270
|
| 'indexIncompatible'
|
|
271
271
|
| 'foreignKeyConflict'
|
|
272
272
|
| 'missingButNonAdditive'
|
|
273
|
-
| 'unsupportedOperation'
|
|
273
|
+
| 'unsupportedOperation'
|
|
274
|
+
| 'controlPolicySuppressedCall';
|
|
274
275
|
|
|
275
276
|
export interface SqlPlannerConflictLocation {
|
|
277
|
+
readonly namespace?: string;
|
|
276
278
|
readonly table?: string;
|
|
277
279
|
readonly column?: string;
|
|
278
280
|
readonly index?: string;
|
package/src/exports/control.ts
CHANGED
|
@@ -26,7 +26,11 @@ export {
|
|
|
26
26
|
detectDestructiveChanges,
|
|
27
27
|
} from '../core/migrations/contract-to-schema-ir';
|
|
28
28
|
export type { ControlPolicySubject } from '../core/migrations/control-policy';
|
|
29
|
-
export {
|
|
29
|
+
export {
|
|
30
|
+
controlPolicyForCall,
|
|
31
|
+
partitionCallsByControlPolicy,
|
|
32
|
+
partitionIssuesByControlPolicy,
|
|
33
|
+
} from '../core/migrations/control-policy';
|
|
30
34
|
export type { PlanFieldEventOperationsOptions } from '../core/migrations/field-event-planner';
|
|
31
35
|
export { planFieldEventOperations } from '../core/migrations/field-event-planner';
|
|
32
36
|
export {
|