@marinoscar/platform-db 0.1.0-next.3 → 0.1.0-next.31
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/CHANGELOG.md +109 -0
- package/README.md +158 -13
- package/dist/baseline/deps.d.ts.map +1 -1
- package/dist/baseline/deps.js +2 -0
- package/dist/baseline/deps.js.map +1 -1
- package/dist/baseline/errors.d.ts +3 -1
- package/dist/baseline/errors.d.ts.map +1 -1
- package/dist/baseline/errors.js.map +1 -1
- package/dist/baseline/report.d.ts +3 -1
- package/dist/baseline/report.d.ts.map +1 -1
- package/dist/baseline/report.js +4 -0
- package/dist/baseline/report.js.map +1 -1
- package/dist/baseline/run.d.ts +12 -1
- package/dist/baseline/run.d.ts.map +1 -1
- package/dist/baseline/run.js +19 -0
- package/dist/baseline/run.js.map +1 -1
- package/dist/bin/db-commands.d.ts +1 -1
- package/dist/bin/db-commands.d.ts.map +1 -1
- package/dist/bin/db-commands.js +40 -5
- package/dist/bin/db-commands.js.map +1 -1
- package/dist/drift/app-objects.d.ts +107 -0
- package/dist/drift/app-objects.d.ts.map +1 -0
- package/dist/drift/app-objects.js +193 -0
- package/dist/drift/app-objects.js.map +1 -0
- package/dist/drift/db-conformance.d.ts +3 -0
- package/dist/drift/db-conformance.d.ts.map +1 -1
- package/dist/drift/db-conformance.js +24 -0
- package/dist/drift/db-conformance.js.map +1 -1
- package/dist/drift/index.d.ts +5 -2
- package/dist/drift/index.d.ts.map +1 -1
- package/dist/drift/index.js +18 -1
- package/dist/drift/index.js.map +1 -1
- package/dist/drift/raw-sql-tripwire.d.ts +44 -3
- package/dist/drift/raw-sql-tripwire.d.ts.map +1 -1
- package/dist/drift/raw-sql-tripwire.js +39 -11
- package/dist/drift/raw-sql-tripwire.js.map +1 -1
- package/dist/drift/rls-policies.d.ts +226 -0
- package/dist/drift/rls-policies.d.ts.map +1 -0
- package/dist/drift/rls-policies.js +317 -0
- package/dist/drift/rls-policies.js.map +1 -0
- package/dist/drift/run.d.ts +24 -0
- package/dist/drift/run.d.ts.map +1 -1
- package/dist/drift/run.js +52 -1
- package/dist/drift/run.js.map +1 -1
- package/dist/drift/sql-expression.d.ts +27 -0
- package/dist/drift/sql-expression.d.ts.map +1 -0
- package/dist/drift/sql-expression.js +64 -0
- package/dist/drift/sql-expression.js.map +1 -0
- package/dist/lock/index.d.ts +1 -1
- package/dist/lock/index.d.ts.map +1 -1
- package/dist/lock/index.js.map +1 -1
- package/dist/lock/lock.d.ts +37 -0
- package/dist/lock/lock.d.ts.map +1 -1
- package/dist/lock/lock.js +11 -0
- package/dist/lock/lock.js.map +1 -1
- package/dist/lock/manifest.d.ts +8 -0
- package/dist/lock/manifest.d.ts.map +1 -1
- package/dist/lock/manifest.js +1 -0
- package/dist/lock/manifest.js.map +1 -1
- package/dist/seed/index.d.ts +1 -0
- package/dist/seed/index.d.ts.map +1 -1
- package/dist/seed/index.js +7 -1
- package/dist/seed/index.js.map +1 -1
- package/dist/seed/seed-platform.d.ts +16 -3
- package/dist/seed/seed-platform.d.ts.map +1 -1
- package/dist/seed/seed-platform.js +37 -5
- package/dist/seed/seed-platform.js.map +1 -1
- package/dist/seed/steps.d.ts +172 -0
- package/dist/seed/steps.d.ts.map +1 -0
- package/dist/seed/steps.js +136 -0
- package/dist/seed/steps.js.map +1 -0
- package/dist/seed/types.d.ts +12 -2
- package/dist/seed/types.d.ts.map +1 -1
- package/dist/sync/app-migrations.d.ts +52 -0
- package/dist/sync/app-migrations.d.ts.map +1 -0
- package/dist/sync/app-migrations.js +62 -0
- package/dist/sync/app-migrations.js.map +1 -0
- package/dist/sync/apply.d.ts.map +1 -1
- package/dist/sync/apply.js +1 -0
- package/dist/sync/apply.js.map +1 -1
- package/dist/sync/check.d.ts +5 -2
- package/dist/sync/check.d.ts.map +1 -1
- package/dist/sync/check.js +8 -1
- package/dist/sync/check.js.map +1 -1
- package/dist/sync/errors.d.ts +2 -1
- package/dist/sync/errors.d.ts.map +1 -1
- package/dist/sync/errors.js.map +1 -1
- package/dist/sync/index.d.ts +1 -0
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +3 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/plan.d.ts +3 -1
- package/dist/sync/plan.d.ts.map +1 -1
- package/dist/sync/plan.js +9 -2
- package/dist/sync/plan.js.map +1 -1
- package/dist/sync/promote.d.ts +4 -0
- package/dist/sync/promote.d.ts.map +1 -1
- package/dist/sync/promote.js +2 -0
- package/dist/sync/promote.js.map +1 -1
- package/migrations/0025_org_scoped_rls/migration.sql +215 -0
- package/migrations/0026_add_groups/migration.sql +165 -0
- package/migrations/0027_add_grants/migration.sql +117 -0
- package/migrations/0028_add_org_settings/migration.sql +49 -0
- package/migrations/0029_add_org_credentials/migration.sql +54 -0
- package/migrations/0030_add_jobs_org_id/migration.sql +18 -0
- package/migrations/0031_add_jobs_org_id_status_index/migration.sql +6 -0
- package/migrations/0032_add_broadcast_target_org/migration.sql +21 -0
- package/migrations/0033_add_android_app/migration.sql +60 -0
- package/migrations/0034_open_job_reason/migration.sql +16 -0
- package/migrations/0035_ai_usage_feature/migration.sql +37 -0
- package/migrations/0036_add_app_metadata/migration.sql +49 -0
- package/migrations/0037_open_sharing_vocabularies/migration.sql +97 -0
- package/migrations/0038_add_worker_node_events/migration.sql +21 -0
- package/migrations/0039_add_webhooks/migration.sql +125 -0
- package/migrations/0040_add_alerts/migration.sql +66 -0
- package/migrations/0041_notifications_state_counted/migration.sql +19 -0
- package/migrations/0042_add_storage_migrations/migration.sql +130 -0
- package/migrations/manifest.json +185 -0
- package/package.json +5 -2
- package/raw-sql-indexes.json +72 -0
- package/rls-policies.json +102 -0
- package/schema/ai.prisma +59 -2
- package/schema/alerts.prisma +75 -0
- package/schema/android-app.prisma +47 -0
- package/schema/credentials.prisma +62 -0
- package/schema/identity.prisma +34 -1
- package/schema/jobs.prisma +69 -7
- package/schema/notifications.prisma +84 -5
- package/schema/settings.prisma +25 -0
- package/schema/sharing.prisma +223 -0
- package/schema/storage.prisma +143 -4
- package/schema/webhooks.prisma +108 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import type { PlatformSeedInput, SeedLogger, SeedPrisma, SeedSummary } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* What a {@link SeedStep} reports: how many rows it inserted and how many it
|
|
4
|
+
* changed. The idempotence contract is about the first number: a second run
|
|
5
|
+
* over an unchanged database creates 0.
|
|
6
|
+
*
|
|
7
|
+
* @stability experimental
|
|
8
|
+
*/
|
|
9
|
+
export interface SeedStepResult {
|
|
10
|
+
/** Rows inserted by this run. A second run over the same database inserts none. */
|
|
11
|
+
created: number;
|
|
12
|
+
/** Rows an existing value was refreshed on. Not constrained by the contract (a step may rewrite a derived column every run). */
|
|
13
|
+
updated: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* What a {@link SeedStep} receives besides its client.
|
|
17
|
+
*
|
|
18
|
+
* @stability experimental
|
|
19
|
+
*/
|
|
20
|
+
export interface SeedStepContext {
|
|
21
|
+
/** The seed's logger: the step's own lines go through the same sink as the platform's, so one run reads as one log. */
|
|
22
|
+
log: SeedLogger;
|
|
23
|
+
/** The input the platform half ran with (roles, permissions, `initialAdminEmail`, ...). Read-only. */
|
|
24
|
+
input: Readonly<PlatformSeedInput>;
|
|
25
|
+
/** What the platform half did, so a step can depend on it (for example on `defaultOrganizationCreated`). */
|
|
26
|
+
platform: Readonly<SeedSummary>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* One app seed step: a named, idempotent write, run after the platform's own.
|
|
30
|
+
*
|
|
31
|
+
* Rules, the same as the platform's:
|
|
32
|
+
* - **Idempotent.** Every write is an upsert keyed on a natural unique, never a `findFirst` followed by a `create`. A second run reports `created: 0`.
|
|
33
|
+
* - **Never deletes**, and never overwrites a value an administrator may have edited (`update: {}`).
|
|
34
|
+
* - **Nest-free.** The seed runs under `ts-node --transpile-only` in an image that has no `src/`.
|
|
35
|
+
*
|
|
36
|
+
* `Tx` is the client type the step writes through: with a real Prisma client,
|
|
37
|
+
* `seedPlatform` runs the step inside `prisma.$transaction`, so `tx` is the
|
|
38
|
+
* transaction client and a failing step leaves none of its writes; with a
|
|
39
|
+
* client that has no `$transaction` (a test fake) `tx` is the client itself.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* // Prisma.TransactionClient is the generated client's transaction type.
|
|
44
|
+
* export const seedCoachDefaults: SeedStep<Prisma.TransactionClient> = {
|
|
45
|
+
* id: 'coach.defaults',
|
|
46
|
+
* async run(tx) {
|
|
47
|
+
* const before = await tx.allowedEmail.count({ where: { email: 'coach@example.test' } });
|
|
48
|
+
* await tx.allowedEmail.upsert({ where: { email: 'coach@example.test' }, update: {}, create: { email: 'coach@example.test', notes: 'Seeded coach' } });
|
|
49
|
+
* return { created: before === 0 ? 1 : 0, updated: 0 };
|
|
50
|
+
* },
|
|
51
|
+
* };
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @extensionPoint option
|
|
55
|
+
* @stability experimental
|
|
56
|
+
*/
|
|
57
|
+
export interface SeedStep<Tx = SeedPrisma> {
|
|
58
|
+
/**
|
|
59
|
+
* Stable id, `lower-case.words-or_dashes` (`coach.defaults`). It names the step in the log and in the summary, must be unique among the run's steps and must not be one of the platform's own step names ({@link PLATFORM_SEED_STEP_IDS}).
|
|
60
|
+
*/
|
|
61
|
+
id: string;
|
|
62
|
+
/**
|
|
63
|
+
* Writes the step's rows.
|
|
64
|
+
*
|
|
65
|
+
* @param tx - The transaction client (see the interface note).
|
|
66
|
+
* @param ctx - The logger, the platform input and what the platform half did.
|
|
67
|
+
* @returns How many rows were created and updated.
|
|
68
|
+
*/
|
|
69
|
+
run(tx: Tx, ctx: SeedStepContext): Promise<SeedStepResult>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* What one extra step did in a run, as `SeedSummary.extras` lists it.
|
|
73
|
+
*
|
|
74
|
+
* @stability experimental
|
|
75
|
+
*/
|
|
76
|
+
export interface SeedStepSummary extends SeedStepResult {
|
|
77
|
+
/** The step's id. */
|
|
78
|
+
id: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The options of {@link seedPlatform}'s third argument (a bare `SeedLogger` is still accepted).
|
|
82
|
+
*
|
|
83
|
+
* @extensionPoint option
|
|
84
|
+
* @stability experimental
|
|
85
|
+
*/
|
|
86
|
+
export interface SeedPlatformOptions<Tx = SeedPrisma> {
|
|
87
|
+
/** Receives one line per step, the platform's and the extras'. Default: silent. */
|
|
88
|
+
log?: SeedLogger;
|
|
89
|
+
/** App steps, run in array order after the platform's own, each in its own transaction. */
|
|
90
|
+
extras?: ReadonlyArray<SeedStep<Tx>>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The ids the platform half logs under; an extra step may not reuse one.
|
|
94
|
+
*
|
|
95
|
+
* @stability experimental
|
|
96
|
+
*/
|
|
97
|
+
export declare const PLATFORM_SEED_STEP_IDS: ReadonlyArray<string>;
|
|
98
|
+
/**
|
|
99
|
+
* A refusal of the seed's extra steps: a malformed or duplicate id, a step
|
|
100
|
+
* that returned a malformed result, or a step that threw.
|
|
101
|
+
*
|
|
102
|
+
* @stability experimental
|
|
103
|
+
*/
|
|
104
|
+
export declare class SeedStepError extends Error {
|
|
105
|
+
/** The step the error is about. */
|
|
106
|
+
readonly stepId: string;
|
|
107
|
+
/**
|
|
108
|
+
* @param stepId - The step.
|
|
109
|
+
* @param message - What is wrong.
|
|
110
|
+
* @param options - The thrown value, when a step threw.
|
|
111
|
+
*/
|
|
112
|
+
constructor(stepId: string, message: string, options?: {
|
|
113
|
+
cause?: unknown;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Checks a run's extra steps before anything is written.
|
|
118
|
+
*
|
|
119
|
+
* @param extras - The steps.
|
|
120
|
+
* @throws SeedStepError for a malformed id, a reserved id, a duplicate id or a `run` that is not a function.
|
|
121
|
+
* @stability experimental
|
|
122
|
+
*/
|
|
123
|
+
export declare function assertSeedSteps(extras: ReadonlyArray<SeedStep<never>>): void;
|
|
124
|
+
/**
|
|
125
|
+
* Validates what a step returned.
|
|
126
|
+
*
|
|
127
|
+
* @param id - The step.
|
|
128
|
+
* @param value - The value `run` resolved to.
|
|
129
|
+
* @returns The result, as `{ created, updated }`.
|
|
130
|
+
* @throws SeedStepError when a count is missing, negative, fractional or not a number.
|
|
131
|
+
* @stability experimental
|
|
132
|
+
*/
|
|
133
|
+
export declare function readSeedStepResult(id: string, value: unknown): SeedStepResult;
|
|
134
|
+
/**
|
|
135
|
+
* Both runs of {@link assertSeedIdempotent}.
|
|
136
|
+
*
|
|
137
|
+
* @stability experimental
|
|
138
|
+
*/
|
|
139
|
+
export interface SeedIdempotenceResult {
|
|
140
|
+
/** The summary of the first run. */
|
|
141
|
+
first: SeedSummary;
|
|
142
|
+
/** The summary of the second run, which created nothing. */
|
|
143
|
+
second: SeedSummary;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The idempotence conformance helper: runs the seed twice over the same
|
|
147
|
+
* database and fails when the second run creates a row. Call it from the
|
|
148
|
+
* app's real-database test, with the same input and steps `seed.ts` uses.
|
|
149
|
+
* Jest- and Vitest-agnostic: it throws, it does not assert through a runner.
|
|
150
|
+
*
|
|
151
|
+
* @param seed - Runs the whole seed once and returns its summary: `() => seedPlatform(prisma, input, { extras })`.
|
|
152
|
+
* @returns Both summaries, for further assertions.
|
|
153
|
+
* @throws Error naming every step whose second run created rows (the platform's default organization included).
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* await assertSeedIdempotent(() => seedPlatform(prisma, platformSeedInputFrom(SEED_SNAPSHOT, {}), { extras: appSeedSteps }));
|
|
157
|
+
* ```
|
|
158
|
+
* @stability experimental
|
|
159
|
+
*/
|
|
160
|
+
export declare function assertSeedIdempotent(seed: () => Promise<SeedSummary>): Promise<SeedIdempotenceResult>;
|
|
161
|
+
/** @internal The structural slice of a client `seedPlatform` needs to open a transaction. */
|
|
162
|
+
export interface SeedTransactionHost {
|
|
163
|
+
$transaction?: <R>(fn: (tx: never) => Promise<R>) => Promise<R>;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Runs one step: inside `prisma.$transaction` when the client has one, else
|
|
167
|
+
* against the client itself.
|
|
168
|
+
*
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
171
|
+
export declare function runSeedStep(prisma: SeedPrisma & SeedTransactionHost, step: SeedStep<never>, ctx: SeedStepContext): Promise<SeedStepResult>;
|
|
172
|
+
//# sourceMappingURL=steps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"steps.d.ts","sourceRoot":"","sources":["../../src/seed/steps.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzF;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAC;IAChB,gIAAgI;IAChI,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,uHAAuH;IACvH,GAAG,EAAE,UAAU,CAAC;IAChB,sGAAsG;IACtG,KAAK,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IACnC,4GAA4G;IAC5G,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,QAAQ,CAAC,EAAE,GAAG,UAAU;IACvC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAC5D;AAED;;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AAE,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;CACjE;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,UAAU,GAAG,mBAAmB,EACxC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,EACrB,GAAG,EAAE,eAAe,GACnB,OAAO,CAAC,cAAc,CAAC,CAWzB"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The seed hook (PP-14.27): app-owned steps that run after the platform's own,
|
|
3
|
+
// under one idempotence contract and one log. Types and helpers only; the
|
|
4
|
+
// loop lives in seed-platform.ts.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SeedStepError = exports.PLATFORM_SEED_STEP_IDS = void 0;
|
|
7
|
+
exports.assertSeedSteps = assertSeedSteps;
|
|
8
|
+
exports.readSeedStepResult = readSeedStepResult;
|
|
9
|
+
exports.assertSeedIdempotent = assertSeedIdempotent;
|
|
10
|
+
exports.runSeedStep = runSeedStep;
|
|
11
|
+
/**
|
|
12
|
+
* The ids the platform half logs under; an extra step may not reuse one.
|
|
13
|
+
*
|
|
14
|
+
* @stability experimental
|
|
15
|
+
*/
|
|
16
|
+
exports.PLATFORM_SEED_STEP_IDS = Object.freeze([
|
|
17
|
+
'roles',
|
|
18
|
+
'permissions',
|
|
19
|
+
'role-permissions',
|
|
20
|
+
'system-settings',
|
|
21
|
+
'allowlist',
|
|
22
|
+
'default-organization',
|
|
23
|
+
]);
|
|
24
|
+
const STEP_ID = /^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/;
|
|
25
|
+
/**
|
|
26
|
+
* A refusal of the seed's extra steps: a malformed or duplicate id, a step
|
|
27
|
+
* that returned a malformed result, or a step that threw.
|
|
28
|
+
*
|
|
29
|
+
* @stability experimental
|
|
30
|
+
*/
|
|
31
|
+
class SeedStepError extends Error {
|
|
32
|
+
/** The step the error is about. */
|
|
33
|
+
stepId;
|
|
34
|
+
/**
|
|
35
|
+
* @param stepId - The step.
|
|
36
|
+
* @param message - What is wrong.
|
|
37
|
+
* @param options - The thrown value, when a step threw.
|
|
38
|
+
*/
|
|
39
|
+
constructor(stepId, message, options) {
|
|
40
|
+
super(`seed step "${stepId}": ${message}`, options);
|
|
41
|
+
this.name = 'SeedStepError';
|
|
42
|
+
this.stepId = stepId;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.SeedStepError = SeedStepError;
|
|
46
|
+
/**
|
|
47
|
+
* Checks a run's extra steps before anything is written.
|
|
48
|
+
*
|
|
49
|
+
* @param extras - The steps.
|
|
50
|
+
* @throws SeedStepError for a malformed id, a reserved id, a duplicate id or a `run` that is not a function.
|
|
51
|
+
* @stability experimental
|
|
52
|
+
*/
|
|
53
|
+
function assertSeedSteps(extras) {
|
|
54
|
+
const seen = new Set();
|
|
55
|
+
for (const step of extras) {
|
|
56
|
+
if (typeof step.id !== 'string' || !STEP_ID.test(step.id)) {
|
|
57
|
+
throw new SeedStepError(String(step.id), 'the id must be lower-case words joined by ".", "-" or "_" (for example "coach.defaults")');
|
|
58
|
+
}
|
|
59
|
+
if (exports.PLATFORM_SEED_STEP_IDS.includes(step.id))
|
|
60
|
+
throw new SeedStepError(step.id, 'the id is one of the platform seed steps');
|
|
61
|
+
if (seen.has(step.id))
|
|
62
|
+
throw new SeedStepError(step.id, 'two steps share this id');
|
|
63
|
+
if (typeof step.run !== 'function')
|
|
64
|
+
throw new SeedStepError(step.id, 'run must be a function');
|
|
65
|
+
seen.add(step.id);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Validates what a step returned.
|
|
70
|
+
*
|
|
71
|
+
* @param id - The step.
|
|
72
|
+
* @param value - The value `run` resolved to.
|
|
73
|
+
* @returns The result, as `{ created, updated }`.
|
|
74
|
+
* @throws SeedStepError when a count is missing, negative, fractional or not a number.
|
|
75
|
+
* @stability experimental
|
|
76
|
+
*/
|
|
77
|
+
function readSeedStepResult(id, value) {
|
|
78
|
+
const result = value;
|
|
79
|
+
for (const field of ['created', 'updated']) {
|
|
80
|
+
const count = result?.[field];
|
|
81
|
+
if (typeof count !== 'number' || !Number.isInteger(count) || count < 0) {
|
|
82
|
+
throw new SeedStepError(id, `run must resolve to { created, updated } with non-negative integers; got ${field}=${String(count)}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return { created: result.created, updated: result.updated };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The idempotence conformance helper: runs the seed twice over the same
|
|
89
|
+
* database and fails when the second run creates a row. Call it from the
|
|
90
|
+
* app's real-database test, with the same input and steps `seed.ts` uses.
|
|
91
|
+
* Jest- and Vitest-agnostic: it throws, it does not assert through a runner.
|
|
92
|
+
*
|
|
93
|
+
* @param seed - Runs the whole seed once and returns its summary: `() => seedPlatform(prisma, input, { extras })`.
|
|
94
|
+
* @returns Both summaries, for further assertions.
|
|
95
|
+
* @throws Error naming every step whose second run created rows (the platform's default organization included).
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* await assertSeedIdempotent(() => seedPlatform(prisma, platformSeedInputFrom(SEED_SNAPSHOT, {}), { extras: appSeedSteps }));
|
|
99
|
+
* ```
|
|
100
|
+
* @stability experimental
|
|
101
|
+
*/
|
|
102
|
+
async function assertSeedIdempotent(seed) {
|
|
103
|
+
const first = await seed();
|
|
104
|
+
const second = await seed();
|
|
105
|
+
const offenders = [];
|
|
106
|
+
if (second.defaultOrganizationCreated)
|
|
107
|
+
offenders.push('default-organization: created again');
|
|
108
|
+
for (const step of second.extras ?? []) {
|
|
109
|
+
if (step.created !== 0)
|
|
110
|
+
offenders.push(`${step.id}: created ${step.created} row(s) on the second run`);
|
|
111
|
+
}
|
|
112
|
+
if (offenders.length > 0) {
|
|
113
|
+
throw new Error(`the seed is not idempotent (a second run must create 0):\n${offenders.map((line) => ` ${line}`).join('\n')}`);
|
|
114
|
+
}
|
|
115
|
+
return { first, second };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Runs one step: inside `prisma.$transaction` when the client has one, else
|
|
119
|
+
* against the client itself.
|
|
120
|
+
*
|
|
121
|
+
* @internal
|
|
122
|
+
*/
|
|
123
|
+
async function runSeedStep(prisma, step, ctx) {
|
|
124
|
+
try {
|
|
125
|
+
const raw = typeof prisma.$transaction === 'function'
|
|
126
|
+
? await prisma.$transaction((tx) => step.run(tx, ctx))
|
|
127
|
+
: await step.run(prisma, ctx);
|
|
128
|
+
return readSeedStepResult(step.id, raw);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (error instanceof SeedStepError)
|
|
132
|
+
throw error;
|
|
133
|
+
throw new SeedStepError(step.id, error?.message ?? String(error), { cause: error });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=steps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"steps.js","sourceRoot":"","sources":["../../src/seed/steps.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,0EAA0E;AAC1E,kCAAkC;;;AAgJlC,0CAWC;AAWD,gDASC;AA6BD,oDAYC;AAaD,kCAeC;AAjJD;;;;GAIG;AACU,QAAA,sBAAsB,GAA0B,MAAM,CAAC,MAAM,CAAC;IACzE,OAAO;IACP,aAAa;IACb,kBAAkB;IAClB,iBAAiB;IACjB,WAAW;IACX,sBAAsB;CACvB,CAAC,CAAC;AAEH,MAAM,OAAO,GAAG,qCAAqC,CAAC;AAEtD;;;;;GAKG;AACH,MAAa,aAAc,SAAQ,KAAK;IACtC,mCAAmC;IAC1B,MAAM,CAAS;IAExB;;;;OAIG;IACH,YAAY,MAAc,EAAE,OAAe,EAAE,OAA6B;QACxE,KAAK,CAAC,cAAc,MAAM,MAAM,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;Q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AY,KAAK,UAAU;YACvC,CAAC,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;YACtD,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,MAAe,EAAE,GAAG,CAAC,CAAC;QAC3C,OAAO,kBAAkB,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,aAAa;YAAE,MAAM,KAAK,CAAC;QAChD,MAAM,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,EAAG,KAAe,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACjG,CAAC;AACH,CAAC"}
|
package/dist/seed/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SeedStepSummary } from './steps.js';
|
|
1
2
|
/**
|
|
2
3
|
* A JSON value, the shape of a `SystemSettings.value` column.
|
|
3
4
|
*
|
|
@@ -105,6 +106,8 @@ export interface SeedSummary {
|
|
|
105
106
|
allowlistedEmail: string | null;
|
|
106
107
|
/** True when this run created the default organization; false when one already existed. */
|
|
107
108
|
defaultOrganizationCreated: boolean;
|
|
109
|
+
/** What each extra step did, in run order. Present only when the run was given `extras`. */
|
|
110
|
+
extras?: SeedStepSummary[];
|
|
108
111
|
}
|
|
109
112
|
/**
|
|
110
113
|
* The arguments of an upsert, as the seed writes them.
|
|
@@ -231,13 +234,16 @@ export interface SeedOrganizationDelegate {
|
|
|
231
234
|
/**
|
|
232
235
|
* Find the default organization, whatever its slug has become.
|
|
233
236
|
*
|
|
234
|
-
* @param args - Filters on `isDefault
|
|
237
|
+
* @param args - Filters on `isDefault` and selects only `id`, so the seed never reads a column a later migration adds.
|
|
235
238
|
* @returns The row, or `null` when none is flagged default.
|
|
236
239
|
*/
|
|
237
240
|
findFirst(args: {
|
|
238
241
|
where: {
|
|
239
242
|
isDefault: true;
|
|
240
243
|
};
|
|
244
|
+
select: {
|
|
245
|
+
id: true;
|
|
246
|
+
};
|
|
241
247
|
}): PromiseLike<SeedRowId | null>;
|
|
242
248
|
/**
|
|
243
249
|
* Create the default organization when its slug is free; an existing row is left as it is.
|
|
@@ -251,7 +257,11 @@ export interface SeedOrganizationDelegate {
|
|
|
251
257
|
name: string;
|
|
252
258
|
slug: string;
|
|
253
259
|
isDefault: true;
|
|
254
|
-
}>
|
|
260
|
+
}> & {
|
|
261
|
+
select: {
|
|
262
|
+
id: true;
|
|
263
|
+
};
|
|
264
|
+
}): PromiseLike<unknown>;
|
|
255
265
|
}
|
|
256
266
|
/**
|
|
257
267
|
* The part of a generated Prisma client the seed uses, as a structural type.
|
package/dist/seed/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/seed/types.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,aAAa,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;CAAE,CAAC;AAElH;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEzC;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,iBAAiB;IAChC,0EAA0E;IAC1E,KAAK,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACrC,gFAAgF;IAChF,W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AM,EAAE;YAAE,EAAE,EAAE,IAAI,CAAA;SAAE,CAAA;KAAE,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;CACzK;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,yBAAyB;IACzB,IAAI,EAAE,iBAAiB,CAAC;IACxB,+BAA+B;IAC/B,UAAU,EAAE,iBAAiB,CAAC;IAC9B,oCAAoC;IACpC,cAAc,EAAE,0BAA0B,CAAC;IAC3C,mCAAmC;IACnC,cAAc,EAAE,0BAA0B,CAAC;IAC3C,kCAAkC;IAClC,YAAY,EAAE,wBAAwB,CAAC;IACvC,iCAAiC;IACjC,YAAY,EAAE,wBAAwB,CAAC;CACxC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ManifestEntry, PlatformLock } from '../lock/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The class of an app-migration ordering failure.
|
|
4
|
+
*
|
|
5
|
+
* - `APP_MIGRATION_ID_COLLISION`: an app-authored migration directory is named exactly like a package migration (its id or directory), so the history cannot tell the two apart.
|
|
6
|
+
* - `APP_MIGRATION_OUT_OF_ORDER`: an app-authored migration directory sorts before an installed platform migration but was not there when `platform db sync` last wrote the lock, so a fresh database would apply it before platform migrations that were already applied elsewhere (it reorders history).
|
|
7
|
+
*
|
|
8
|
+
* @stability experimental
|
|
9
|
+
*/
|
|
10
|
+
export type AppMigrationProblemCode = 'APP_MIGRATION_ID_COLLISION' | 'APP_MIGRATION_OUT_OF_ORDER';
|
|
11
|
+
/**
|
|
12
|
+
* One app-authored migration that would collide with, or reorder, the installed platform history.
|
|
13
|
+
*
|
|
14
|
+
* @stability experimental
|
|
15
|
+
*/
|
|
16
|
+
export interface AppMigrationProblem {
|
|
17
|
+
/** The class of failure. */
|
|
18
|
+
code: AppMigrationProblemCode;
|
|
19
|
+
/** The offending app-authored directory. */
|
|
20
|
+
localDir: string;
|
|
21
|
+
/** A one-line explanation naming the directory and the fix. */
|
|
22
|
+
message: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Finds the app-authored migrations that collide with, or would reorder, the
|
|
26
|
+
* installed platform history. An app-authored directory is one under
|
|
27
|
+
* `prisma/migrations` that no `platform.lock` entry names.
|
|
28
|
+
*
|
|
29
|
+
* Two rules, both offline:
|
|
30
|
+
*
|
|
31
|
+
* 1. **Id collision.** An app-authored directory must not be named like a
|
|
32
|
+
* package migration (`0036_add_app_metadata`): the history would hold two
|
|
33
|
+
* migrations the tooling cannot tell apart.
|
|
34
|
+
* 2. **Order.** `platform db sync` always installs a platform migration under
|
|
35
|
+
* a timestamp later than everything in the history, so an app migration that
|
|
36
|
+
* existed at that moment sorts before it by design (an app's own `add_notes`
|
|
37
|
+
* between two platform migrations is normal). One that appears *afterwards*
|
|
38
|
+
* with an older timestamp (a branch started before the sync, merged after)
|
|
39
|
+
* would run, on a fresh database, before platform migrations other
|
|
40
|
+
* databases applied first. The lock remembers which app directories existed
|
|
41
|
+
* at the last sync (`appMigrations`); a directory outside that list that
|
|
42
|
+
* sorts before the last installed platform directory is the failure. A lock
|
|
43
|
+
* without the field skips this rule until its next sync.
|
|
44
|
+
*
|
|
45
|
+
* @param manifest - The package history.
|
|
46
|
+
* @param lock - The app's `platform.lock`.
|
|
47
|
+
* @param localDirs - Every directory name under the app's `prisma/migrations`.
|
|
48
|
+
* @returns Every problem found, in directory order; empty when none.
|
|
49
|
+
* @stability experimental
|
|
50
|
+
*/
|
|
51
|
+
export declare function checkAppMigrations(manifest: readonly Pick<ManifestEntry, 'id' | 'dir'>[], lock: Pick<PlatformLock, 'migrations' | 'appMigrations'>, localDirs: readonly string[]): AppMigrationProblem[];
|
|
52
|
+
//# sourceMappingURL=app-migrations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-migrations.d.ts","sourceRoot":"","sources":["../../src/sync/app-migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEpE;;;;;;;GAOG;AACH,MAAM,MAAM,uBAAuB,GAAG,4BAA4B,GAAG,4BAA4B,CAAC;AAElG;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,4BAA4B;IAC5B,IAAI,EAAE,uBAAuB,CAAC;IAC9B,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,SAAS,IAAI,CAAC,aAAa,EAAE,IAAI,GAAG,KAAK,CAAC,EAAE,EACtD,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,GAAG,eAAe,CAAC,EACxD,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,mBAAmB,EAAE,CA4BvB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkAppMigrations = checkAppMigrations;
|
|
4
|
+
/**
|
|
5
|
+
* Finds the app-authored migrations that collide with, or would reorder, the
|
|
6
|
+
* installed platform history. An app-authored directory is one under
|
|
7
|
+
* `prisma/migrations` that no `platform.lock` entry names.
|
|
8
|
+
*
|
|
9
|
+
* Two rules, both offline:
|
|
10
|
+
*
|
|
11
|
+
* 1. **Id collision.** An app-authored directory must not be named like a
|
|
12
|
+
* package migration (`0036_add_app_metadata`): the history would hold two
|
|
13
|
+
* migrations the tooling cannot tell apart.
|
|
14
|
+
* 2. **Order.** `platform db sync` always installs a platform migration under
|
|
15
|
+
* a timestamp later than everything in the history, so an app migration that
|
|
16
|
+
* existed at that moment sorts before it by design (an app's own `add_notes`
|
|
17
|
+
* between two platform migrations is normal). One that appears *afterwards*
|
|
18
|
+
* with an older timestamp (a branch started before the sync, merged after)
|
|
19
|
+
* would run, on a fresh database, before platform migrations other
|
|
20
|
+
* databases applied first. The lock remembers which app directories existed
|
|
21
|
+
* at the last sync (`appMigrations`); a directory outside that list that
|
|
22
|
+
* sorts before the last installed platform directory is the failure. A lock
|
|
23
|
+
* without the field skips this rule until its next sync.
|
|
24
|
+
*
|
|
25
|
+
* @param manifest - The package history.
|
|
26
|
+
* @param lock - The app's `platform.lock`.
|
|
27
|
+
* @param localDirs - Every directory name under the app's `prisma/migrations`.
|
|
28
|
+
* @returns Every problem found, in directory order; empty when none.
|
|
29
|
+
* @stability experimental
|
|
30
|
+
*/
|
|
31
|
+
function checkAppMigrations(manifest, lock, localDirs) {
|
|
32
|
+
const problems = [];
|
|
33
|
+
const locked = new Set(lock.migrations.map((entry) => entry.localDir));
|
|
34
|
+
const packageNames = new Set(manifest.flatMap((entry) => [entry.id, entry.dir]));
|
|
35
|
+
const known = lock.appMigrations ? new Set(lock.appMigrations) : undefined;
|
|
36
|
+
let lastInstalled;
|
|
37
|
+
for (const entry of lock.migrations) {
|
|
38
|
+
if (lastInstalled === undefined || entry.localDir > lastInstalled)
|
|
39
|
+
lastInstalled = entry.localDir;
|
|
40
|
+
}
|
|
41
|
+
for (const dir of [...localDirs].sort()) {
|
|
42
|
+
if (locked.has(dir))
|
|
43
|
+
continue;
|
|
44
|
+
if (packageNames.has(dir)) {
|
|
45
|
+
problems.push({
|
|
46
|
+
code: 'APP_MIGRATION_ID_COLLISION',
|
|
47
|
+
localDir: dir,
|
|
48
|
+
message: `prisma/migrations/${dir} is named like the package migration ${dir}; an app migration keeps Prisma's timestamped name (nothing applied may be renamed: if it was never applied, rename it now)`,
|
|
49
|
+
});
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (known && lastInstalled !== undefined && dir < lastInstalled && !known.has(dir)) {
|
|
53
|
+
problems.push({
|
|
54
|
+
code: 'APP_MIGRATION_OUT_OF_ORDER',
|
|
55
|
+
localDir: dir,
|
|
56
|
+
message: `prisma/migrations/${dir} sorts before the installed platform migration ${lastInstalled} but was added after the last \`platform db sync\`; a fresh database would apply it before platform migrations other databases already ran. If it was never applied, give it a timestamp after ${lastInstalled}; if it was applied, record it by running \`platform db sync\``,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return problems;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=app-migrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-migrations.js","sourceRoot":"","sources":["../../src/sync/app-migrations.ts"],"names":[],"mappings":";;AAqDA,gDAgCC;AA3DD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,kBAAkB,CAChC,QAAsD,EACtD,IAAwD,EACxD,SAA4B;IAE5B,MAAM,QAAQ,GAA0B,EAAE,CAAC;IAC3C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvE,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACjF,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3E,IAAI,aAAiC,CAAC;IACtC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QACpC,IAAI,aAAa,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,GAAG,aAAa;YAAE,aAAa,GAAG,KAAK,CAAC,QAAQ,CAAC;IACpG,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QACxC,IAAI,MAAM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apply.d.ts","sourceRoot":"","sources":["../../src/sync/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,MAAM;IACrB,+DAA+D;IAC/D,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAAC;IAChD,mIAAmI;IACnI,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CAChE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,GAAG,YAAY,CAmBlE"}
|
package/dist/sync/apply.js
CHANGED
|
@@ -32,6 +32,7 @@ function applySync(plan, io) {
|
|
|
32
32
|
...plan.baseLock,
|
|
33
33
|
platformVersion: plan.installs.length ? plan.platformVersion : plan.baseLock.platformVersion,
|
|
34
34
|
migrations: [...plan.baseLock.migrations, ...plan.installs.map(plan_js_1.lockEntryOf)],
|
|
35
|
+
...(plan.installs.length ? { appMigrations: plan.appMigrations } : {}),
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
//# sourceMappingURL=apply.js.map
|
package/dist/sync/apply.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../src/sync/apply.ts"],"names":[],"mappings":";;AA8BA,
|
|
1
|
+
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../src/sync/apply.ts"],"names":[],"mappings":";;AA8BA,8BAmBC;AAjDD,+CAAgE;AAChE,2CAAwC;AACxC,uCAAuD;AAcvD;;;;;;;;;;;;;GAaG;AACH,SAAgB,SAAS,CAAC,IAAc,EAAE,EAAU;IAClD,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAG,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACrD,MAAM,MAAM,GAAG,IAAA,oBAAS,EAAC,KAAK,CAAC,CAAC;QAChC,IAAI,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC;YAC9B,MAAM,IAAI,qBAAS,CACjB,uBAAuB,EACvB,GAAG,OAAO,CAAC,QAAQ,4BAA4B,MAAM,uBAAuB,OAAO,CAAC,MAAM,6DAA6D,CACxJ,CAAC;QACJ,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,mBAAmB,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC;IAC3F,OAAO;QACL,GAAG,IAAI,CAAC,QAAQ;QAChB,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe;QAC5F,UAAU,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,qBAAW,CAAC,CAAC;QAC5E,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvE,CAAC;AACJ,CAAC"}
|
package/dist/sync/check.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ManifestEntry, type PlatformLock } from '../lock/index.js';
|
|
2
|
+
import { type AppMigrationProblemCode } from './app-migrations.js';
|
|
2
3
|
/**
|
|
3
4
|
* The class of a lock failure; each is named in the command's output.
|
|
4
5
|
*
|
|
@@ -9,10 +10,11 @@ import { type ManifestEntry, type PlatformLock } from '../lock/index.js';
|
|
|
9
10
|
* - `LOCAL_DIR_MISSING`: a locked `localDir` does not exist.
|
|
10
11
|
* - `NOT_IN_PACKAGE`: the lock names a migration the manifest does not have.
|
|
11
12
|
* - `LOCAL_OUT_OF_ORDER`: installed directories do not sort in package order.
|
|
13
|
+
* - `APP_MIGRATION_ID_COLLISION` / `APP_MIGRATION_OUT_OF_ORDER`: an app-authored migration directory is named like a package migration, or would reorder the installed history (see {@link checkAppMigrations}); reported only when the caller passes `localDirs`.
|
|
12
14
|
*
|
|
13
15
|
* @stability experimental
|
|
14
16
|
*/
|
|
15
|
-
export type CheckProblemCode = 'LOCAL_MODIFIED' | 'PACKAGE_MODIFIED' | 'PACKAGE_FILE_MODIFIED' | 'NOT_INSTALLED' | 'LOCAL_DIR_MISSING' | 'NOT_IN_PACKAGE' | 'LOCAL_OUT_OF_ORDER';
|
|
17
|
+
export type CheckProblemCode = 'LOCAL_MODIFIED' | 'PACKAGE_MODIFIED' | 'PACKAGE_FILE_MODIFIED' | 'NOT_INSTALLED' | 'LOCAL_DIR_MISSING' | 'NOT_IN_PACKAGE' | 'LOCAL_OUT_OF_ORDER' | AppMigrationProblemCode;
|
|
16
18
|
/**
|
|
17
19
|
* One offending migration.
|
|
18
20
|
*
|
|
@@ -49,8 +51,9 @@ export interface CheckResult {
|
|
|
49
51
|
* @param lock - The app's `platform.lock`.
|
|
50
52
|
* @param readLocal - Reads `prisma/migrations/<localDir>/migration.sql`; returns `undefined` when the directory or file does not exist.
|
|
51
53
|
* @param readPackage - Optional: reads the package's actual `migration.sql` so a file edited without its manifest hash is also caught; `undefined` means missing.
|
|
54
|
+
* @param localDirs - Optional: every directory name under the app's `prisma/migrations`; when given, app-authored directories that collide with or reorder the installed history are reported too (see {@link checkAppMigrations}).
|
|
52
55
|
* @returns Every problem found; `ok` when there is none.
|
|
53
56
|
* @stability experimental
|
|
54
57
|
*/
|
|
55
|
-
export declare function checkLock(manifest: readonly ManifestEntry[], lock: PlatformLock, readLocal: (localDir: string) => Uint8Array | undefined, readPackage?: (packageDir: string) => Uint8Array | undefined): CheckResult;
|
|
58
|
+
export declare function checkLock(manifest: readonly ManifestEntry[], lock: PlatformLock, readLocal: (localDir: string) => Uint8Array | undefined, readPackage?: (packageDir: string) => Uint8Array | undefined, localDirs?: readonly string[]): CheckResult;
|
|
56
59
|
//# sourceMappingURL=check.d.ts.map
|
package/dist/sync/check.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/sync/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/sync/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChG,OAAO,EAAsB,KAAK,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAEvF;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,gBAAgB,GACxB,gBAAgB,GAChB,kBAAkB,GAClB,uBAAuB,GACvB,eAAe,GACf,mBAAmB,GACnB,gBAAgB,GAChB,oBAAoB,GACpB,uBAAuB,CAAC;AAE5B;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,4BAA4B;IAC5B,IAAI,EAAE,gBAAgB,CAAC;IACvB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,qCAAqC;IACrC,EAAE,EAAE,OAAO,CAAC;IACZ,wFAAwF;IACxF,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CACvB,QAAQ,EAAE,SAAS,aAAa,EAAE,EAClC,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,EACvD,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,EAC5D,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,GAC5B,WAAW,CAgGb"}
|
package/dist/sync/check.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkLock = checkLock;
|
|
4
4
|
const index_js_1 = require("../lock/index.js");
|
|
5
|
+
const app_migrations_js_1 = require("./app-migrations.js");
|
|
5
6
|
const short = (hash) => hash.slice(0, 12);
|
|
6
7
|
/**
|
|
7
8
|
* `platform db check`, offline half. Read-only and pure apart from the two
|
|
@@ -13,10 +14,11 @@ const short = (hash) => hash.slice(0, 12);
|
|
|
13
14
|
* @param lock - The app's `platform.lock`.
|
|
14
15
|
* @param readLocal - Reads `prisma/migrations/<localDir>/migration.sql`; returns `undefined` when the directory or file does not exist.
|
|
15
16
|
* @param readPackage - Optional: reads the package's actual `migration.sql` so a file edited without its manifest hash is also caught; `undefined` means missing.
|
|
17
|
+
* @param localDirs - Optional: every directory name under the app's `prisma/migrations`; when given, app-authored directories that collide with or reorder the installed history are reported too (see {@link checkAppMigrations}).
|
|
16
18
|
* @returns Every problem found; `ok` when there is none.
|
|
17
19
|
* @stability experimental
|
|
18
20
|
*/
|
|
19
|
-
function checkLock(manifest, lock, readLocal, readPackage) {
|
|
21
|
+
function checkLock(manifest, lock, readLocal, readPackage, localDirs) {
|
|
20
22
|
const problems = [];
|
|
21
23
|
const byOrigin = new Map(manifest.map((entry) => [(0, index_js_1.originIdOf)(entry), entry]));
|
|
22
24
|
const locked = new Set(lock.migrations.map((entry) => entry.originId));
|
|
@@ -103,6 +105,11 @@ function checkLock(manifest, lock, readLocal, readPackage) {
|
|
|
103
105
|
});
|
|
104
106
|
}
|
|
105
107
|
}
|
|
108
|
+
if (localDirs) {
|
|
109
|
+
for (const problem of (0, app_migrations_js_1.checkAppMigrations)(manifest, lock, localDirs)) {
|
|
110
|
+
problems.push({ code: problem.code, originId: `app:${problem.localDir}`, localDir: problem.localDir, message: problem.message });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
106
113
|
return { ok: problems.length === 0, problems };
|
|
107
114
|
}
|
|
108
115
|
//# sourceMappingURL=check.js.map
|
package/dist/sync/check.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/sync/check.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/sync/check.ts"],"names":[],"mappings":";;AAuEA,8BAsGC;AA7KD,+CAAgG;AAChG,2DAAuF;AAsDvF,MAAM,KAAK,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAE1D;;;;;;;;;;;;;GAaG;AACH,SAAgB,SAAS,CACvB,QAAkC,EAClC,IAAkB,EAClB,SAAuD,EACvD,WAA4D,EAC5D,SAA6B;IAE7B,MAAM,QAAQ,GAAmB,EAAE,CAAC;IACpC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,IAAA,qBAAU,EAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9E,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,C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EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,OAAO,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QACnI,CAAC;IACH,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;AACjD,CAAC"}
|
package/dist/sync/errors.d.ts
CHANGED
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
* - `PROMOTE_CONFLICT`: the slug or directory is already recorded with different bytes or origin.
|
|
11
11
|
* - `PROMOTE_NOT_SYNCED`: the app lock does not yet hold every package migration.
|
|
12
12
|
* - `PROMOTE_ORDER`: the directory sorts before the last installed platform migration.
|
|
13
|
+
* - `APP_MIGRATION_COLLISION`: an app-authored migration directory is named like a package migration or would reorder the installed history (see `checkAppMigrations`); sync installs nothing until it is fixed.
|
|
13
14
|
*
|
|
14
15
|
* @stability experimental
|
|
15
16
|
*/
|
|
16
|
-
export type SyncErrorCode = 'NOT_IN_PACKAGE' | 'LOCK_GAP' | 'REQUIRES_VIOLATION' | 'PACKAGE_FILE_MISMATCH' | 'LOCAL_DIR_EXISTS' | 'PROMOTE_INVALID' | 'PROMOTE_CONFLICT' | 'PROMOTE_NOT_SYNCED' | 'PROMOTE_ORDER';
|
|
17
|
+
export type SyncErrorCode = 'NOT_IN_PACKAGE' | 'LOCK_GAP' | 'REQUIRES_VIOLATION' | 'PACKAGE_FILE_MISMATCH' | 'LOCAL_DIR_EXISTS' | 'PROMOTE_INVALID' | 'PROMOTE_CONFLICT' | 'PROMOTE_NOT_SYNCED' | 'PROMOTE_ORDER' | 'APP_MIGRATION_COLLISION';
|
|
17
18
|
/**
|
|
18
19
|
* A refusal of `platform db sync` or `platform db promote`, with a stable code.
|
|
19
20
|
*
|