@marinoscar/platform-db 0.0.0-stage → 0.1.0-next.11
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 +88 -0
- package/LICENSE +21 -0
- package/README.md +525 -2
- package/bin/platform.js +28 -0
- package/dist/baseline/deps.d.ts +32 -0
- package/dist/baseline/deps.d.ts.map +1 -0
- package/dist/baseline/deps.js +66 -0
- package/dist/baseline/deps.js.map +1 -0
- package/dist/baseline/errors.d.ts +36 -0
- package/dist/baseline/errors.d.ts.map +1 -0
- package/dist/baseline/errors.js +23 -0
- package/dist/baseline/errors.js.map +1 -0
- package/dist/baseline/fs.d.ts +9 -0
- package/dist/baseline/fs.d.ts.map +1 -0
- package/dist/baseline/fs.js +39 -0
- package/dist/baseline/fs.js.map +1 -0
- package/dist/baseline/index.d.ts +8 -0
- package/dist/baseline/index.d.ts.map +1 -0
- package/dist/baseline/index.js +24 -0
- package/dist/baseline/index.js.map +1 -0
- package/dist/baseline/mapping.d.ts +43 -0
- package/dist/baseline/mapping.d.ts.map +1 -0
- package/dist/baseline/mapping.js +80 -0
- package/dist/baseline/mapping.js.map +1 -0
- package/dist/baseline/normalise.d.ts +42 -0
- package/dist/baseline/normalise.d.ts.map +1 -0
- package/dist/baseline/normalise.js +133 -0
- package/dist/baseline/normalise.js.map +1 -0
- package/dist/baseline/plan.d.ts +66 -0
- package/dist/baseline/plan.d.ts.map +1 -0
- package/dist/baseline/plan.js +105 -0
- package/dist/baseline/plan.js.map +1 -0
- package/dist/baseline/report.d.ts +127 -0
- package/dist/baseline/report.d.ts.map +1 -0
- package/dist/baseline/report.js +89 -0
- package/dist/baseline/report.js.map +1 -0
- package/dist/baseline/run.d.ts +117 -0
- package/dist/baseline/run.d.ts.map +1 -0
- package/dist/baseline/run.js +358 -0
- package/dist/baseline/run.js.map +1 -0
- package/dist/bin/db-commands.d.ts +31 -0
- package/dist/bin/db-commands.d.ts.map +1 -0
- package/dist/bin/db-commands.js +311 -0
- package/dist/bin/db-commands.js.map +1 -0
- package/dist/bin/fs-io.d.ts +7 -0
- package/dist/bin/fs-io.d.ts.map +1 -0
- package/dist/bin/fs-io.js +45 -0
- package/dist/bin/fs-io.js.map +1 -0
- package/dist/bin/platform.d.ts +21 -0
- package/dist/bin/platform.d.ts.map +1 -0
- package/dist/bin/platform.js +99 -0
- package/dist/bin/platform.js.map +1 -0
- package/dist/compose/api.d.ts +84 -0
- package/dist/compose/api.d.ts.map +1 -0
- package/dist/compose/api.js +101 -0
- package/dist/compose/api.js.map +1 -0
- package/dist/compose/compose.d.ts +51 -0
- package/dist/compose/compose.d.ts.map +1 -0
- package/dist/compose/compose.js +177 -0
- package/dist/compose/compose.js.map +1 -0
- package/dist/compose/diff.d.ts +7 -0
- package/dist/compose/diff.d.ts.map +1 -0
- package/dist/compose/diff.js +68 -0
- package/dist/compose/diff.js.map +1 -0
- package/dist/compose/errors.d.ts +31 -0
- package/dist/compose/errors.d.ts.map +1 -0
- package/dist/compose/errors.js +35 -0
- package/dist/compose/errors.js.map +1 -0
- package/dist/compose/index.d.ts +3 -0
- package/dist/compose/index.d.ts.map +1 -0
- package/dist/compose/index.js +11 -0
- package/dist/compose/index.js.map +1 -0
- package/dist/compose/parse.d.ts +65 -0
- package/dist/compose/parse.d.ts.map +1 -0
- package/dist/compose/parse.js +122 -0
- package/dist/compose/parse.js.map +1 -0
- 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 +52 -0
- package/dist/drift/db-conformance.d.ts.map +1 -0
- package/dist/drift/db-conformance.js +89 -0
- package/dist/drift/db-conformance.js.map +1 -0
- package/dist/drift/index.d.ts +8 -0
- package/dist/drift/index.d.ts.map +1 -0
- package/dist/drift/index.js +43 -0
- package/dist/drift/index.js.map +1 -0
- package/dist/drift/raw-sql-indexes.d.ts +106 -0
- package/dist/drift/raw-sql-indexes.d.ts.map +1 -0
- package/dist/drift/raw-sql-indexes.js +113 -0
- package/dist/drift/raw-sql-indexes.js.map +1 -0
- package/dist/drift/raw-sql-tripwire.d.ts +191 -0
- package/dist/drift/raw-sql-tripwire.d.ts.map +1 -0
- package/dist/drift/raw-sql-tripwire.js +422 -0
- package/dist/drift/raw-sql-tripwire.js.map +1 -0
- 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 +152 -0
- package/dist/drift/run.d.ts.map +1 -0
- package/dist/drift/run.js +252 -0
- package/dist/drift/run.js.map +1 -0
- 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/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/lock/hash.d.ts +13 -0
- package/dist/lock/hash.d.ts.map +1 -0
- package/dist/lock/hash.js +19 -0
- package/dist/lock/hash.js.map +1 -0
- package/dist/lock/index.d.ts +5 -0
- package/dist/lock/index.d.ts.map +1 -0
- package/dist/lock/index.js +20 -0
- package/dist/lock/index.js.map +1 -0
- package/dist/lock/lock.d.ts +154 -0
- package/dist/lock/lock.d.ts.map +1 -0
- package/dist/lock/lock.js +151 -0
- package/dist/lock/lock.js.map +1 -0
- package/dist/lock/manifest.d.ts +68 -0
- package/dist/lock/manifest.d.ts.map +1 -0
- package/dist/lock/manifest.js +96 -0
- package/dist/lock/manifest.js.map +1 -0
- package/dist/lock/semver.d.ts +10 -0
- package/dist/lock/semver.d.ts.map +1 -0
- package/dist/lock/semver.js +13 -0
- package/dist/lock/semver.js.map +1 -0
- package/dist/seed/index.d.ts +5 -0
- package/dist/seed/index.d.ts.map +1 -0
- package/dist/seed/index.js +16 -0
- package/dist/seed/index.js.map +1 -0
- package/dist/seed/input.d.ts +52 -0
- package/dist/seed/input.d.ts.map +1 -0
- package/dist/seed/input.js +77 -0
- package/dist/seed/input.js.map +1 -0
- package/dist/seed/seed-platform.d.ts +41 -0
- package/dist/seed/seed-platform.d.ts.map +1 -0
- package/dist/seed/seed-platform.js +165 -0
- package/dist/seed/seed-platform.js.map +1 -0
- 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 +287 -0
- package/dist/seed/types.d.ts.map +1 -0
- package/dist/seed/types.js +5 -0
- package/dist/seed/types.js.map +1 -0
- 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 +29 -0
- package/dist/sync/apply.d.ts.map +1 -0
- package/dist/sync/apply.js +38 -0
- package/dist/sync/apply.js.map +1 -0
- package/dist/sync/check.d.ts +59 -0
- package/dist/sync/check.d.ts.map +1 -0
- package/dist/sync/check.js +115 -0
- package/dist/sync/check.js.map +1 -0
- package/dist/sync/errors.d.ts +32 -0
- package/dist/sync/errors.d.ts.map +1 -0
- package/dist/sync/errors.js +23 -0
- package/dist/sync/errors.js.map +1 -0
- package/dist/sync/index.d.ts +10 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +27 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/ledger.d.ts +65 -0
- package/dist/sync/ledger.d.ts.map +1 -0
- package/dist/sync/ledger.js +49 -0
- package/dist/sync/ledger.js.map +1 -0
- package/dist/sync/plan.d.ts +63 -0
- package/dist/sync/plan.d.ts.map +1 -0
- package/dist/sync/plan.js +86 -0
- package/dist/sync/plan.js.map +1 -0
- package/dist/sync/promote.d.ts +62 -0
- package/dist/sync/promote.d.ts.map +1 -0
- package/dist/sync/promote.js +95 -0
- package/dist/sync/promote.js.map +1 -0
- package/dist/sync/timestamps.d.ts +41 -0
- package/dist/sync/timestamps.d.ts.map +1 -0
- package/dist/sync/timestamps.js +68 -0
- package/dist/sync/timestamps.js.map +1 -0
- package/dist/sync/version.d.ts +28 -0
- package/dist/sync/version.d.ts.map +1 -0
- package/dist/sync/version.js +66 -0
- package/dist/sync/version.js.map +1 -0
- package/migrations/0001_initial/migration.sql +297 -0
- package/migrations/0002_add_personal_access_tokens/migration.sql +31 -0
- package/migrations/0003_add_credentials/migration.sql +20 -0
- package/migrations/0004_add_notification_deliveries/migration.sql +27 -0
- package/migrations/0005_drop_stale_uuid_defaults/migration.sql +35 -0
- package/migrations/0006_add_notifications/migration.sql +22 -0
- package/migrations/0007_add_push_subscriptions/migration.sql +25 -0
- package/migrations/0008_add_jobs/migration.sql +110 -0
- package/migrations/0009_add_worker_nodes/migration.sql +90 -0
- package/migrations/0010_add_database_backup_runs/migration.sql +104 -0
- package/migrations/0011_add_notification_broadcasts/migration.sql +57 -0
- package/migrations/0012_add_backup_run_job_link/migration.sql +87 -0
- package/migrations/0013_add_job_node_secrets/migration.sql +61 -0
- package/migrations/0014_add_backup_run_pg_dump_version/migration.sql +26 -0
- package/migrations/0015_add_job_claim_token/migration.sql +92 -0
- package/migrations/0016_add_ai_platform/migration.sql +108 -0
- package/migrations/0017_revoke_viewer_ai_use/migration.sql +32 -0
- package/migrations/0018_add_user_credentials/migration.sql +29 -0
- package/migrations/0019_add_device_session_credential_link/migration.sql +52 -0
- package/migrations/0020_add_worker_node_vitals/migration.sql +3 -0
- package/migrations/0021_add_job_trace_context/migration.sql +6 -0
- package/migrations/0022_add_retention_created_at_indexes/migration.sql +13 -0
- package/migrations/0023_add_organizations/migration.sql +142 -0
- package/migrations/0024_split_system_org_roles/migration.sql +131 -0
- 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/manifest.json +379 -0
- package/package.json +78 -4
- package/raw-sql-indexes.json +94 -0
- package/rls-policies.json +74 -0
- package/schema/ai.prisma +444 -0
- package/schema/android-app.prisma +47 -0
- package/schema/base.prisma +11 -0
- package/schema/credentials.prisma +170 -0
- package/schema/db-backup.prisma +376 -0
- package/schema/identity.prisma +439 -0
- package/schema/jobs.prisma +760 -0
- package/schema/notifications.prisma +649 -0
- package/schema/settings.prisma +60 -0
- package/schema/sharing.prisma +223 -0
- package/schema/storage.prisma +84 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkLock = checkLock;
|
|
4
|
+
const index_js_1 = require("../lock/index.js");
|
|
5
|
+
const app_migrations_js_1 = require("./app-migrations.js");
|
|
6
|
+
const short = (hash) => hash.slice(0, 12);
|
|
7
|
+
/**
|
|
8
|
+
* `platform db check`, offline half. Read-only and pure apart from the two
|
|
9
|
+
* readers. Fails when a locked migration's local bytes differ from the lock,
|
|
10
|
+
* the lock differs from the manifest, a package migration is not installed, or
|
|
11
|
+
* a locked directory is missing.
|
|
12
|
+
*
|
|
13
|
+
* @param manifest - The package history.
|
|
14
|
+
* @param lock - The app's `platform.lock`.
|
|
15
|
+
* @param readLocal - Reads `prisma/migrations/<localDir>/migration.sql`; returns `undefined` when the directory or file does not exist.
|
|
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}).
|
|
18
|
+
* @returns Every problem found; `ok` when there is none.
|
|
19
|
+
* @stability experimental
|
|
20
|
+
*/
|
|
21
|
+
function checkLock(manifest, lock, readLocal, readPackage, localDirs) {
|
|
22
|
+
const problems = [];
|
|
23
|
+
const byOrigin = new Map(manifest.map((entry) => [(0, index_js_1.originIdOf)(entry), entry]));
|
|
24
|
+
const locked = new Set(lock.migrations.map((entry) => entry.originId));
|
|
25
|
+
for (const entry of lock.migrations) {
|
|
26
|
+
const origin = byOrigin.get(entry.originId);
|
|
27
|
+
if (!origin) {
|
|
28
|
+
problems.push({
|
|
29
|
+
code: 'NOT_IN_PACKAGE',
|
|
30
|
+
originId: entry.originId,
|
|
31
|
+
localDir: entry.localDir,
|
|
32
|
+
message: `${entry.originId}: locked as ${entry.localDir} but the package manifest no longer has it`,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
if (origin.sha256 !== entry.sha256) {
|
|
37
|
+
problems.push({
|
|
38
|
+
code: 'PACKAGE_MODIFIED',
|
|
39
|
+
originId: entry.originId,
|
|
40
|
+
localDir: entry.localDir,
|
|
41
|
+
message: `${entry.originId}: the package hash ${short(origin.sha256)} differs from the lock ${short(entry.sha256)}; a released migration was rewritten (restore the package file)`,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (readPackage) {
|
|
45
|
+
const bytes = readPackage(origin.dir);
|
|
46
|
+
if (!bytes) {
|
|
47
|
+
problems.push({
|
|
48
|
+
code: 'PACKAGE_FILE_MODIFIED',
|
|
49
|
+
originId: entry.originId,
|
|
50
|
+
localDir: entry.localDir,
|
|
51
|
+
message: `${entry.originId}: package file migrations/${origin.dir}/migration.sql is missing`,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else if ((0, index_js_1.sha256Hex)(bytes) !== origin.sha256) {
|
|
55
|
+
problems.push({
|
|
56
|
+
code: 'PACKAGE_FILE_MODIFIED',
|
|
57
|
+
originId: entry.originId,
|
|
58
|
+
localDir: entry.localDir,
|
|
59
|
+
message: `${entry.originId}: package file migrations/${origin.dir}/migration.sql hashes to ${short((0, index_js_1.sha256Hex)(bytes))}, the manifest says ${short(origin.sha256)}`,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const bytes = readLocal(entry.localDir);
|
|
65
|
+
if (!bytes) {
|
|
66
|
+
problems.push({
|
|
67
|
+
code: 'LOCAL_DIR_MISSING',
|
|
68
|
+
originId: entry.originId,
|
|
69
|
+
localDir: entry.localDir,
|
|
70
|
+
message: `${entry.originId}: prisma/migrations/${entry.localDir}/migration.sql does not exist`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const want = entry.localSha256 ?? entry.sha256;
|
|
75
|
+
const got = (0, index_js_1.sha256Hex)(bytes);
|
|
76
|
+
if (got !== want) {
|
|
77
|
+
problems.push({
|
|
78
|
+
code: 'LOCAL_MODIFIED',
|
|
79
|
+
originId: entry.originId,
|
|
80
|
+
localDir: entry.localDir,
|
|
81
|
+
message: `${entry.originId}: prisma/migrations/${entry.localDir}/migration.sql hashes to ${short(got)}, the lock says ${short(want)}; an installed migration is never edited`,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Installed directories must sort in package order, or a fresh database applies them in another order.
|
|
87
|
+
for (let i = 1; i < lock.migrations.length; i += 1) {
|
|
88
|
+
const previous = lock.migrations[i - 1];
|
|
89
|
+
const current = lock.migrations[i];
|
|
90
|
+
if (current.localDir <= previous.localDir) {
|
|
91
|
+
problems.push({
|
|
92
|
+
code: 'LOCAL_OUT_OF_ORDER',
|
|
93
|
+
originId: current.originId,
|
|
94
|
+
localDir: current.localDir,
|
|
95
|
+
message: `${current.originId}: ${current.localDir} does not sort after ${previous.localDir}, its predecessor in the package`,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
for (const entry of manifest) {
|
|
100
|
+
if (!locked.has((0, index_js_1.originIdOf)(entry))) {
|
|
101
|
+
problems.push({
|
|
102
|
+
code: 'NOT_INSTALLED',
|
|
103
|
+
originId: (0, index_js_1.originIdOf)(entry),
|
|
104
|
+
message: `${(0, index_js_1.originIdOf)(entry)}: in the package but not installed; run \`platform db sync\``,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
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
|
+
}
|
|
113
|
+
return { ok: problems.length === 0, problems };
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,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C5F,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,KAAK,MAAM,OAAO,IAAI,IAAA,sCAAkB,EAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,CAAC;YACpE,QAAQ,CAAC,IAAI,CAAC,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"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why `platform db sync` or `platform db promote` refused to proceed.
|
|
3
|
+
*
|
|
4
|
+
* - `NOT_IN_PACKAGE`: the lock names a migration the package no longer has.
|
|
5
|
+
* - `LOCK_GAP`: the lock does not hold a prefix of the package history.
|
|
6
|
+
* - `REQUIRES_VIOLATION`: an entry requires a slice no earlier entry provides.
|
|
7
|
+
* - `PACKAGE_FILE_MISMATCH`: a package `migration.sql` differs from its manifest sha256.
|
|
8
|
+
* - `LOCAL_DIR_EXISTS`: the directory sync would create already exists.
|
|
9
|
+
* - `PROMOTE_INVALID`: the arguments of `promote` are not valid.
|
|
10
|
+
* - `PROMOTE_CONFLICT`: the slug or directory is already recorded with different bytes or origin.
|
|
11
|
+
* - `PROMOTE_NOT_SYNCED`: the app lock does not yet hold every package migration.
|
|
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.
|
|
14
|
+
*
|
|
15
|
+
* @stability experimental
|
|
16
|
+
*/
|
|
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';
|
|
18
|
+
/**
|
|
19
|
+
* A refusal of `platform db sync` or `platform db promote`, with a stable code.
|
|
20
|
+
*
|
|
21
|
+
* @stability experimental
|
|
22
|
+
*/
|
|
23
|
+
export declare class SyncError extends Error {
|
|
24
|
+
/** The class of refusal. */
|
|
25
|
+
readonly code: SyncErrorCode;
|
|
26
|
+
/**
|
|
27
|
+
* @param code - The class of refusal.
|
|
28
|
+
* @param message - What is wrong and how to fix it.
|
|
29
|
+
*/
|
|
30
|
+
constructor(code: SyncErrorCode, message: string);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/sync/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,aAAa,GACrB,gBAAgB,GAChB,UAAU,GACV,oBAAoB,GACpB,uBAAuB,GACvB,kBAAkB,GAClB,iBAAiB,GACjB,kBAAkB,GAClB,oBAAoB,GACpB,eAAe,GACf,yBAAyB,CAAC;AAE9B;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,4BAA4B;IAC5B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAE7B;;;OAGG;gBACS,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM;CAKjD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SyncError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A refusal of `platform db sync` or `platform db promote`, with a stable code.
|
|
6
|
+
*
|
|
7
|
+
* @stability experimental
|
|
8
|
+
*/
|
|
9
|
+
class SyncError extends Error {
|
|
10
|
+
/** The class of refusal. */
|
|
11
|
+
code;
|
|
12
|
+
/**
|
|
13
|
+
* @param code - The class of refusal.
|
|
14
|
+
* @param message - What is wrong and how to fix it.
|
|
15
|
+
*/
|
|
16
|
+
constructor(code, message) {
|
|
17
|
+
super(`${code}: ${message}`);
|
|
18
|
+
this.name = 'SyncError';
|
|
19
|
+
this.code = code;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.SyncError = SyncError;
|
|
23
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/sync/errors.ts"],"names":[],"mappings":";;;AA4BA;;;;GAIG;AACH,MAAa,SAAU,SAAQ,KAAK;IAClC,4BAA4B;IACnB,IAAI,CAAgB;IAE7B;;;OAGG;IACH,YAAY,IAAmB,EAAE,OAAe;QAC9C,KAAK,CAAC,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAbD,8BAaC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { applySync, type SyncIo } from './apply.js';
|
|
2
|
+
export { checkAppMigrations, type AppMigrationProblem, type AppMigrationProblemCode } from './app-migrations.js';
|
|
3
|
+
export { checkLock, type CheckProblem, type CheckProblemCode, type CheckResult, } from './check.js';
|
|
4
|
+
export { SyncError, type SyncErrorCode } from './errors.js';
|
|
5
|
+
export { checkLedger, type LedgerProblem, type LedgerProblemCode, type LedgerResult, type LedgerRow, } from './ledger.js';
|
|
6
|
+
export { assertRequiresSatisfied, planSync, type PlannedInstall, type SyncPlan } from './plan.js';
|
|
7
|
+
export { promote, type PromoteIo, type PromoteResult } from './promote.js';
|
|
8
|
+
export { formatTimestamp, latestLocalTimestamp, nextTimestamps, parseTimestamp } from './timestamps.js';
|
|
9
|
+
export { compareVersions, nextPlatformVersion } from './version.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sync/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,KAAK,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACjH,OAAO,EACL,SAAS,EACT,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,WAAW,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,SAAS,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAClG,OAAO,EAAE,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACxG,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nextPlatformVersion = exports.compareVersions = exports.parseTimestamp = exports.nextTimestamps = exports.latestLocalTimestamp = exports.formatTimestamp = exports.promote = exports.planSync = exports.assertRequiresSatisfied = exports.checkLedger = exports.SyncError = exports.checkLock = exports.checkAppMigrations = exports.applySync = void 0;
|
|
4
|
+
var apply_js_1 = require("./apply.js");
|
|
5
|
+
Object.defineProperty(exports, "applySync", { enumerable: true, get: function () { return apply_js_1.applySync; } });
|
|
6
|
+
var app_migrations_js_1 = require("./app-migrations.js");
|
|
7
|
+
Object.defineProperty(exports, "checkAppMigrations", { enumerable: true, get: function () { return app_migrations_js_1.checkAppMigrations; } });
|
|
8
|
+
var check_js_1 = require("./check.js");
|
|
9
|
+
Object.defineProperty(exports, "checkLock", { enumerable: true, get: function () { return check_js_1.checkLock; } });
|
|
10
|
+
var errors_js_1 = require("./errors.js");
|
|
11
|
+
Object.defineProperty(exports, "SyncError", { enumerable: true, get: function () { return errors_js_1.SyncError; } });
|
|
12
|
+
var ledger_js_1 = require("./ledger.js");
|
|
13
|
+
Object.defineProperty(exports, "checkLedger", { enumerable: true, get: function () { return ledger_js_1.checkLedger; } });
|
|
14
|
+
var plan_js_1 = require("./plan.js");
|
|
15
|
+
Object.defineProperty(exports, "assertRequiresSatisfied", { enumerable: true, get: function () { return plan_js_1.assertRequiresSatisfied; } });
|
|
16
|
+
Object.defineProperty(exports, "planSync", { enumerable: true, get: function () { return plan_js_1.planSync; } });
|
|
17
|
+
var promote_js_1 = require("./promote.js");
|
|
18
|
+
Object.defineProperty(exports, "promote", { enumerable: true, get: function () { return promote_js_1.promote; } });
|
|
19
|
+
var timestamps_js_1 = require("./timestamps.js");
|
|
20
|
+
Object.defineProperty(exports, "formatTimestamp", { enumerable: true, get: function () { return timestamps_js_1.formatTimestamp; } });
|
|
21
|
+
Object.defineProperty(exports, "latestLocalTimestamp", { enumerable: true, get: function () { return timestamps_js_1.latestLocalTimestamp; } });
|
|
22
|
+
Object.defineProperty(exports, "nextTimestamps", { enumerable: true, get: function () { return timestamps_js_1.nextTimestamps; } });
|
|
23
|
+
Object.defineProperty(exports, "parseTimestamp", { enumerable: true, get: function () { return timestamps_js_1.parseTimestamp; } });
|
|
24
|
+
var version_js_1 = require("./version.js");
|
|
25
|
+
Object.defineProperty(exports, "compareVersions", { enumerable: true, get: function () { return version_js_1.compareVersions; } });
|
|
26
|
+
Object.defineProperty(exports, "nextPlatformVersion", { enumerable: true, get: function () { return version_js_1.nextPlatformVersion; } });
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sync/index.ts"],"names":[],"mappings":";;;AAAA,uCAAoD;AAA3C,qGAAA,SAAS,OAAA;AAClB,yDAAiH;AAAxG,uHAAA,kBAAkB,OAAA;AAC3B,uCAKoB;AAJlB,qGAAA,SAAS,OAAA;AAKX,yCAA4D;AAAnD,sGAAA,SAAS,OAAA;AAClB,yCAMqB;AALnB,wGAAA,WAAW,OAAA;AAMb,qCAAkG;AAAzF,kHAAA,uBAAuB,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAC1C,2CAA2E;AAAlE,qGAAA,OAAO,OAAA;AAChB,iDAAwG;AAA/F,gHAAA,eAAe,OAAA;AAAE,qHAAA,oBAAoB,OAAA;AAAE,+GAAA,cAAc,OAAA;AAAE,+GAAA,cAAc,OAAA;AAC9E,2CAAoE;AAA3D,6GAAA,eAAe,OAAA;AAAE,iHAAA,mBAAmB,OAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A row of Prisma's `_prisma_migrations` ledger, as far as the check needs it.
|
|
3
|
+
*
|
|
4
|
+
* @stability experimental
|
|
5
|
+
*/
|
|
6
|
+
export interface LedgerRow {
|
|
7
|
+
/** The applied directory name. */
|
|
8
|
+
migrationName: string;
|
|
9
|
+
/** The checksum Prisma recorded (SHA-256 of the file's raw bytes). */
|
|
10
|
+
checksum: string;
|
|
11
|
+
/** When the migration finished, `null` while it is running or failed. */
|
|
12
|
+
finishedAt: Date | null;
|
|
13
|
+
/** When the migration was marked rolled back, otherwise `null`. */
|
|
14
|
+
rolledBackAt: Date | null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The class of a ledger failure.
|
|
18
|
+
*
|
|
19
|
+
* - `LEDGER_CHECKSUM_MISMATCH`: the file on disk no longer matches what the database applied.
|
|
20
|
+
* - `LEDGER_UNFINISHED`: a row has no `finished_at` (a failed or running migration).
|
|
21
|
+
*
|
|
22
|
+
* @stability experimental
|
|
23
|
+
*/
|
|
24
|
+
export type LedgerProblemCode = 'LEDGER_CHECKSUM_MISMATCH' | 'LEDGER_UNFINISHED';
|
|
25
|
+
/**
|
|
26
|
+
* One offending ledger row.
|
|
27
|
+
*
|
|
28
|
+
* @stability experimental
|
|
29
|
+
*/
|
|
30
|
+
export interface LedgerProblem {
|
|
31
|
+
/** The class of failure. */
|
|
32
|
+
code: LedgerProblemCode;
|
|
33
|
+
/** The directory name. */
|
|
34
|
+
localDir: string;
|
|
35
|
+
/** A one-line explanation. */
|
|
36
|
+
message: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The outcome of {@link checkLedger}.
|
|
40
|
+
*
|
|
41
|
+
* @stability experimental
|
|
42
|
+
*/
|
|
43
|
+
export interface LedgerResult {
|
|
44
|
+
/** True when `problems` is empty. Pending directories do not fail the check. */
|
|
45
|
+
ok: boolean;
|
|
46
|
+
/** Every offending row. */
|
|
47
|
+
problems: LedgerProblem[];
|
|
48
|
+
/** Local directories with no ledger row yet (a `prisma migrate deploy` is pending). */
|
|
49
|
+
pending: string[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* `platform db check --database`: compares `_prisma_migrations` with the
|
|
53
|
+
* local files. Not redundant with Prisma: `migrate deploy` and `migrate status`
|
|
54
|
+
* do not complain about an edited, already-applied migration file.
|
|
55
|
+
*
|
|
56
|
+
* Covers every local directory, installed or app-authored.
|
|
57
|
+
*
|
|
58
|
+
* @param localDirs - Every migration directory name in the app's history.
|
|
59
|
+
* @param readLocal - Reads `migration.sql` of a directory; `undefined` when missing.
|
|
60
|
+
* @param rows - The ledger rows.
|
|
61
|
+
* @returns Problems and the pending (not yet applied) directories.
|
|
62
|
+
* @stability experimental
|
|
63
|
+
*/
|
|
64
|
+
export declare function checkLedger(localDirs: readonly string[], readLocal: (localDir: string) => Uint8Array | undefined, rows: readonly LedgerRow[]): LedgerResult;
|
|
65
|
+
//# sourceMappingURL=ledger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../../src/sync/ledger.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,kCAAkC;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,QAAQ,EAAE,MAAM,CAAC;IACjB,yEAAyE;IACzE,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;IACxB,mEAAmE;IACnE,YAAY,EAAE,IAAI,GAAG,IAAI,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG,0BAA0B,GAAG,mBAAmB,CAAC;AAEjF;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,4BAA4B;IAC5B,IAAI,EAAE,iBAAiB,CAAC;IACxB,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,gFAAgF;IAChF,EAAE,EAAE,OAAO,CAAC;IACZ,2BAA2B;IAC3B,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,uFAAuF;IACvF,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,EACvD,IAAI,EAAE,SAAS,SAAS,EAAE,GACzB,YAAY,CA2Bd"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkLedger = checkLedger;
|
|
4
|
+
const index_js_1 = require("../lock/index.js");
|
|
5
|
+
/**
|
|
6
|
+
* `platform db check --database`: compares `_prisma_migrations` with the
|
|
7
|
+
* local files. Not redundant with Prisma: `migrate deploy` and `migrate status`
|
|
8
|
+
* do not complain about an edited, already-applied migration file.
|
|
9
|
+
*
|
|
10
|
+
* Covers every local directory, installed or app-authored.
|
|
11
|
+
*
|
|
12
|
+
* @param localDirs - Every migration directory name in the app's history.
|
|
13
|
+
* @param readLocal - Reads `migration.sql` of a directory; `undefined` when missing.
|
|
14
|
+
* @param rows - The ledger rows.
|
|
15
|
+
* @returns Problems and the pending (not yet applied) directories.
|
|
16
|
+
* @stability experimental
|
|
17
|
+
*/
|
|
18
|
+
function checkLedger(localDirs, readLocal, rows) {
|
|
19
|
+
// A rolled-back row is history: Prisma applies the directory again and writes a new row.
|
|
20
|
+
const byName = new Map();
|
|
21
|
+
for (const row of rows)
|
|
22
|
+
if (!row.rolledBackAt)
|
|
23
|
+
byName.set(row.migrationName, row);
|
|
24
|
+
const problems = [];
|
|
25
|
+
const pending = [];
|
|
26
|
+
for (const dir of localDirs) {
|
|
27
|
+
const row = byName.get(dir);
|
|
28
|
+
const bytes = readLocal(dir);
|
|
29
|
+
if (!bytes)
|
|
30
|
+
continue; // not a migration directory
|
|
31
|
+
if (!row) {
|
|
32
|
+
pending.push(dir);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (!row.finishedAt) {
|
|
36
|
+
problems.push({ code: 'LEDGER_UNFINISHED', localDir: dir, message: `${dir}: _prisma_migrations has no finished_at (a failed migration; resolve it)` });
|
|
37
|
+
}
|
|
38
|
+
const actual = (0, index_js_1.sha256Hex)(bytes);
|
|
39
|
+
if (actual !== row.checksum) {
|
|
40
|
+
problems.push({
|
|
41
|
+
code: 'LEDGER_CHECKSUM_MISMATCH',
|
|
42
|
+
localDir: dir,
|
|
43
|
+
message: `${dir}: the file hashes to ${actual.slice(0, 12)} but the database applied ${row.checksum.slice(0, 12)}; an applied migration was edited`,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return { ok: problems.length === 0, problems, pending };
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=ledger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../src/sync/ledger.ts"],"names":[],"mappings":";;AAqEA,kCA+BC;AApGD,+CAA6C;AAwD7C;;;;;;;;;;;;GAYG;AACH,SAAgB,WAAW,CACzB,SAA4B,EAC5B,SAAuD,EACvD,IAA0B;IAE1B,yFAAyF;IACzF,MAAM,MAAM,GAAG,IAAI,GAAG,EAAqB,CAAC;IAC5C,KAAK,MAAM,GAAG,IAAI,IAAI;QAAE,IAAI,CAAC,GAAG,CAAC,YAAY;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;IAClF,MAAM,QAAQ,GAAoB,EAAE,CAAC;IACrC,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;QAC5B,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,KAAK;YAAE,SAAS,CAAC,4BAA4B;QAClD,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClB,SAAS;QACX,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC;YACpB,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,GAAG,0EAA0E,EAAE,CAAC,CAAC;QACzJ,CAAC;QACD,MAAM,MAAM,GAAG,IAAA,oBAAS,EAAC,KAAK,CAAC,CAAC;QAChC,IAAI,MAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,CAAC;YAC5B,QAAQ,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,0BAA0B;gBAChC,QAAQ,EAAE,GAAG;gBACb,OAAO,EAAE,GAAG,GAAG,wBAAwB,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,6BAA6B,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,mCAAmC;aACpJ,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type LockEntry, type ManifestEntry, type PlatformLock } from '../lock/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* One package migration `sync` is about to install.
|
|
4
|
+
*
|
|
5
|
+
* @stability experimental
|
|
6
|
+
*/
|
|
7
|
+
export interface PlannedInstall {
|
|
8
|
+
/** `platform:NNNN_slug`. */
|
|
9
|
+
originId: string;
|
|
10
|
+
/** The directory under the package's `migrations/` folder. */
|
|
11
|
+
packageDir: string;
|
|
12
|
+
/** The app-local directory to create under `prisma/migrations`. */
|
|
13
|
+
localDir: string;
|
|
14
|
+
/** SHA-256 the package file must have (from the manifest). */
|
|
15
|
+
sha256: string;
|
|
16
|
+
/** The version recorded as `since` in the lock entry. */
|
|
17
|
+
since: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* What `sync` would do; produced by {@link planSync}, consumed by {@link applySync}.
|
|
21
|
+
*
|
|
22
|
+
* @stability experimental
|
|
23
|
+
*/
|
|
24
|
+
export interface SyncPlan {
|
|
25
|
+
/** The migrations to install, in install order (empty when the app is up to date). */
|
|
26
|
+
installs: PlannedInstall[];
|
|
27
|
+
/** The version the lock will record after the sync. */
|
|
28
|
+
platformVersion: string;
|
|
29
|
+
/** The lock the plan was derived from. */
|
|
30
|
+
baseLock: PlatformLock;
|
|
31
|
+
/** The app-authored migration directories that exist now; `applySync` records them in the lock as `appMigrations` (see {@link checkAppMigrations}). */
|
|
32
|
+
appMigrations: string[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Checks the manifest's internal order: every `requires` slice must be
|
|
36
|
+
* provided by an earlier entry.
|
|
37
|
+
*
|
|
38
|
+
* @param manifest - The package history, in order.
|
|
39
|
+
* @throws SyncError `REQUIRES_VIOLATION` naming the entry and the missing slice.
|
|
40
|
+
* @stability experimental
|
|
41
|
+
*/
|
|
42
|
+
export declare function assertRequiresSatisfied(manifest: readonly ManifestEntry[]): void;
|
|
43
|
+
/**
|
|
44
|
+
* Plans an install. Pure: no file system, no clock beyond `now`.
|
|
45
|
+
*
|
|
46
|
+
* Every package migration missing from the lock is installed, in manifest
|
|
47
|
+
* order, under an app-local timestamp that sorts after everything already in
|
|
48
|
+
* the history (see {@link nextTimestamps}). Nothing existing is renamed or
|
|
49
|
+
* rewritten.
|
|
50
|
+
*
|
|
51
|
+
* @param manifest - The package history, in order.
|
|
52
|
+
* @param lock - The app's current `platform.lock`.
|
|
53
|
+
* @param localDirs - Every directory name under the app's `prisma/migrations`.
|
|
54
|
+
* @param now - The clock; the `--timestamp` override of the command.
|
|
55
|
+
* @param platformVersion - The version to record in the lock (default: the lock's current one).
|
|
56
|
+
* @returns The plan; `installs` is empty when nothing is missing.
|
|
57
|
+
* @throws SyncError `REQUIRES_VIOLATION`, `NOT_IN_PACKAGE`, `LOCK_GAP` or `APP_MIGRATION_COLLISION` (an app-authored directory named like a package migration, or one that would reorder the installed history).
|
|
58
|
+
* @stability experimental
|
|
59
|
+
*/
|
|
60
|
+
export declare function planSync(manifest: readonly ManifestEntry[], lock: PlatformLock, localDirs: readonly string[], now: Date, platformVersion?: string): SyncPlan;
|
|
61
|
+
/** The lock entry an install records. */
|
|
62
|
+
export declare function lockEntryOf(install: PlannedInstall): LockEntry;
|
|
63
|
+
//# sourceMappingURL=plan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../src/sync/plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAKrG;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,4BAA4B;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,UAAU,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,sFAAsF;IACtF,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,uDAAuD;IACvD,eAAe,EAAE,MAAM,CAAC;IACxB,0CAA0C;IAC1C,QAAQ,EAAE,YAAY,CAAC;IACvB,uJAAuJ;IACvJ,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAOD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,GAAG,IAAI,CAahF;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,SAAS,aAAa,EAAE,EAClC,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,GAAG,EAAE,IAAI,EACT,eAAe,GAAE,MAA6B,GAC7C,QAAQ,CA6CV;AAED,yCAAyC;AACzC,wBAAgB,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,CAE9D"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertRequiresSatisfied = assertRequiresSatisfied;
|
|
4
|
+
exports.planSync = planSync;
|
|
5
|
+
exports.lockEntryOf = lockEntryOf;
|
|
6
|
+
const index_js_1 = require("../lock/index.js");
|
|
7
|
+
const app_migrations_js_1 = require("./app-migrations.js");
|
|
8
|
+
const errors_js_1 = require("./errors.js");
|
|
9
|
+
const timestamps_js_1 = require("./timestamps.js");
|
|
10
|
+
/** The directory slug of a package migration id: the id without its numeric prefix, kebab to snake. */
|
|
11
|
+
function slugOf(id) {
|
|
12
|
+
return id.replace(/^\d{4}_/, '').replace(/-/g, '_');
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Checks the manifest's internal order: every `requires` slice must be
|
|
16
|
+
* provided by an earlier entry.
|
|
17
|
+
*
|
|
18
|
+
* @param manifest - The package history, in order.
|
|
19
|
+
* @throws SyncError `REQUIRES_VIOLATION` naming the entry and the missing slice.
|
|
20
|
+
* @stability experimental
|
|
21
|
+
*/
|
|
22
|
+
function assertRequiresSatisfied(manifest) {
|
|
23
|
+
const provided = new Set();
|
|
24
|
+
for (const entry of manifest) {
|
|
25
|
+
for (const slice of entry.requires) {
|
|
26
|
+
if (!provided.has(slice)) {
|
|
27
|
+
throw new errors_js_1.SyncError('REQUIRES_VIOLATION', `${entry.id} requires slice "${slice}", which no earlier migration provides; reorder the manifest or fix "requires"`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
provided.add(entry.slice);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Plans an install. Pure: no file system, no clock beyond `now`.
|
|
35
|
+
*
|
|
36
|
+
* Every package migration missing from the lock is installed, in manifest
|
|
37
|
+
* order, under an app-local timestamp that sorts after everything already in
|
|
38
|
+
* the history (see {@link nextTimestamps}). Nothing existing is renamed or
|
|
39
|
+
* rewritten.
|
|
40
|
+
*
|
|
41
|
+
* @param manifest - The package history, in order.
|
|
42
|
+
* @param lock - The app's current `platform.lock`.
|
|
43
|
+
* @param localDirs - Every directory name under the app's `prisma/migrations`.
|
|
44
|
+
* @param now - The clock; the `--timestamp` override of the command.
|
|
45
|
+
* @param platformVersion - The version to record in the lock (default: the lock's current one).
|
|
46
|
+
* @returns The plan; `installs` is empty when nothing is missing.
|
|
47
|
+
* @throws SyncError `REQUIRES_VIOLATION`, `NOT_IN_PACKAGE`, `LOCK_GAP` or `APP_MIGRATION_COLLISION` (an app-authored directory named like a package migration, or one that would reorder the installed history).
|
|
48
|
+
* @stability experimental
|
|
49
|
+
*/
|
|
50
|
+
function planSync(manifest, lock, localDirs, now, platformVersion = lock.platformVersion) {
|
|
51
|
+
assertRequiresSatisfied(manifest);
|
|
52
|
+
const byOrigin = new Map(manifest.map((entry, index) => [(0, index_js_1.originIdOf)(entry), index]));
|
|
53
|
+
for (const locked of lock.migrations) {
|
|
54
|
+
if (!byOrigin.has(locked.originId)) {
|
|
55
|
+
throw new errors_js_1.SyncError('NOT_IN_PACKAGE', `${locked.originId} is in platform.lock but not in the package manifest; the package must never drop a released migration`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// The lock must hold an in-order prefix of the package history.
|
|
59
|
+
lock.migrations.forEach((locked, i) => {
|
|
60
|
+
const expected = manifest[i];
|
|
61
|
+
if (!expected || (0, index_js_1.originIdOf)(expected) !== locked.originId) {
|
|
62
|
+
throw new errors_js_1.SyncError('LOCK_GAP', `platform.lock entry ${i + 1} is ${locked.originId} but the package history has ${expected ? (0, index_js_1.originIdOf)(expected) : 'nothing'} there; the package history has a gap relative to the lock`);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
const collisions = (0, app_migrations_js_1.checkAppMigrations)(manifest, lock, localDirs);
|
|
66
|
+
if (collisions.length > 0) {
|
|
67
|
+
throw new errors_js_1.SyncError('APP_MIGRATION_COLLISION', `${collisions.length} app migration(s) collide with the platform history, nothing was installed:\n${collisions.map((c) => ` ${c.code} ${c.message}`).join('\n')}`);
|
|
68
|
+
}
|
|
69
|
+
const pending = manifest.slice(lock.migrations.length);
|
|
70
|
+
const stamps = (0, timestamps_js_1.nextTimestamps)(localDirs, pending.length, now);
|
|
71
|
+
const installs = pending.map((entry, i) => ({
|
|
72
|
+
originId: (0, index_js_1.originIdOf)(entry),
|
|
73
|
+
packageDir: entry.dir,
|
|
74
|
+
localDir: `${stamps[i]}_${slugOf(entry.id)}`,
|
|
75
|
+
sha256: entry.sha256,
|
|
76
|
+
since: entry.since,
|
|
77
|
+
}));
|
|
78
|
+
const locked = new Set(lock.migrations.map((entry) => entry.localDir));
|
|
79
|
+
const appMigrations = [...localDirs].filter((dir) => !locked.has(dir)).sort();
|
|
80
|
+
return { installs, platformVersion, baseLock: lock, appMigrations };
|
|
81
|
+
}
|
|
82
|
+
/** The lock entry an install records. */
|
|
83
|
+
function lockEntryOf(install) {
|
|
84
|
+
return { originId: install.originId, localDir: install.localDir, sha256: install.sha256, since: install.since };
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=plan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.js","sourceRoot":"","sources":["../../src/sync/plan.ts"],"names":[],"mappings":";;AAoDA,0DAaC;AAmBD,4BAmDC;AAGD,kCAEC;AA5ID,+CAAqG;AACrG,2DAAyD;AACzD,2CAAwC;AACxC,mDAAiD;AAoCjD,uGAAuG;AACvG,SAAS,MAAM,CAAC,EAAU;IACxB,OAAO,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;;GA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MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC,CACH,CAAC;IACF,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,aAAa,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9E,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;AACtE,CAAC;AAED,yCAAyC;AACzC,SAAgB,WAAW,CAAC,OAAuB;IACjD,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;AAClH,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type ManifestEntry, type PlatformLock } from '../lock/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Everything {@link promote} reads and writes, injectable so the logic is testable.
|
|
4
|
+
*
|
|
5
|
+
* @stability experimental
|
|
6
|
+
*/
|
|
7
|
+
export interface PromoteIo {
|
|
8
|
+
/** The package manifest as it is now. */
|
|
9
|
+
manifest: readonly ManifestEntry[];
|
|
10
|
+
/** The app's lock as it is now. */
|
|
11
|
+
lock: PlatformLock;
|
|
12
|
+
/** Reads `prisma/migrations/<localDir>/migration.sql`; `undefined` when missing. */
|
|
13
|
+
readLocal(localDir: string): Uint8Array | undefined;
|
|
14
|
+
/** Writes `<package>/migrations/<dir>/migration.sql`; only called for a new entry. */
|
|
15
|
+
writePackageFile(dir: string, bytes: Uint8Array): void;
|
|
16
|
+
/** The next platform version: recorded as `since` in the manifest and the lock. */
|
|
17
|
+
since: string;
|
|
18
|
+
/** The slice that owns the migration. */
|
|
19
|
+
slice: string;
|
|
20
|
+
/** Slice ids that must appear in earlier entries. */
|
|
21
|
+
requires: readonly string[];
|
|
22
|
+
/** Other slices whose tables the migration also changes. */
|
|
23
|
+
touches?: readonly string[];
|
|
24
|
+
/** Whether the migration enables row-level security on a table. */
|
|
25
|
+
rls?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The outcome of {@link promote}.
|
|
29
|
+
*
|
|
30
|
+
* @stability experimental
|
|
31
|
+
*/
|
|
32
|
+
export interface PromoteResult {
|
|
33
|
+
/** The manifest to write. */
|
|
34
|
+
manifest: ManifestEntry[];
|
|
35
|
+
/** The lock to write. */
|
|
36
|
+
lock: PlatformLock;
|
|
37
|
+
/** The manifest entry of the promoted migration. */
|
|
38
|
+
entry: ManifestEntry;
|
|
39
|
+
/** False when the call was a no-op because the migration was already promoted. */
|
|
40
|
+
changed: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* `platform db promote <localDir> --id <slug>`: the authoring workflow for a
|
|
44
|
+
* platform migration. Takes a migration generated in the app by
|
|
45
|
+
* `prisma migrate dev --create-only`, copies its bytes into the package, adds
|
|
46
|
+
* it to the manifest and records it in the app lock against the **same**
|
|
47
|
+
* `localDir`, so the app keeps the directory Prisma created and never
|
|
48
|
+
* re-applies it.
|
|
49
|
+
*
|
|
50
|
+
* Idempotent: promoting the same directory with the same bytes again changes
|
|
51
|
+
* nothing. A released migration is immutable, so the same slug with different
|
|
52
|
+
* bytes is refused.
|
|
53
|
+
*
|
|
54
|
+
* @param localDir - The app's migration directory name.
|
|
55
|
+
* @param id - The slug of the new package migration (`add_orgs`); the sequence number is assigned.
|
|
56
|
+
* @param io - Reads and writes.
|
|
57
|
+
* @returns The manifest and lock to write, and whether anything changed.
|
|
58
|
+
* @throws SyncError `PROMOTE_INVALID`, `PROMOTE_CONFLICT`, `PROMOTE_NOT_SYNCED` or `PROMOTE_ORDER`.
|
|
59
|
+
* @stability experimental
|
|
60
|
+
*/
|
|
61
|
+
export declare function promote(localDir: string, id: string, io: PromoteIo): PromoteResult;
|
|
62
|
+
//# sourceMappingURL=promote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../src/sync/promote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhH;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,yCAAyC;IACzC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAC;IACnC,mCAAmC;IACnC,IAAI,EAAE,YAAY,CAAC;IACnB,oFAAoF;IACpF,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;IACpD,sFAAsF;IACtF,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IACvD,mFAAmF;IACnF,KAAK,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,4DAA4D;IAC5D,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,mEAAmE;IACnE,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,6BAA6B;IAC7B,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,yBAAyB;IACzB,IAAI,EAAE,YAAY,CAAC;IACnB,oDAAoD;IACpD,KAAK,EAAE,aAAa,CAAC;IACrB,kFAAkF;IAClF,OAAO,EAAE,OAAO,CAAC;CAClB;AAOD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,GAAG,aAAa,CAmElF"}
|