@marinoscar/platform-db 0.0.0-stage → 0.1.0-next.3

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.
Files changed (208) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/LICENSE +21 -0
  3. package/README.md +382 -2
  4. package/bin/platform.js +28 -0
  5. package/dist/baseline/deps.d.ts +32 -0
  6. package/dist/baseline/deps.d.ts.map +1 -0
  7. package/dist/baseline/deps.js +64 -0
  8. package/dist/baseline/deps.js.map +1 -0
  9. package/dist/baseline/errors.d.ts +34 -0
  10. package/dist/baseline/errors.d.ts.map +1 -0
  11. package/dist/baseline/errors.js +23 -0
  12. package/dist/baseline/errors.js.map +1 -0
  13. package/dist/baseline/fs.d.ts +9 -0
  14. package/dist/baseline/fs.d.ts.map +1 -0
  15. package/dist/baseline/fs.js +39 -0
  16. package/dist/baseline/fs.js.map +1 -0
  17. package/dist/baseline/index.d.ts +8 -0
  18. package/dist/baseline/index.d.ts.map +1 -0
  19. package/dist/baseline/index.js +24 -0
  20. package/dist/baseline/index.js.map +1 -0
  21. package/dist/baseline/mapping.d.ts +43 -0
  22. package/dist/baseline/mapping.d.ts.map +1 -0
  23. package/dist/baseline/mapping.js +80 -0
  24. package/dist/baseline/mapping.js.map +1 -0
  25. package/dist/baseline/normalise.d.ts +42 -0
  26. package/dist/baseline/normalise.d.ts.map +1 -0
  27. package/dist/baseline/normalise.js +133 -0
  28. package/dist/baseline/normalise.js.map +1 -0
  29. package/dist/baseline/plan.d.ts +66 -0
  30. package/dist/baseline/plan.d.ts.map +1 -0
  31. package/dist/baseline/plan.js +105 -0
  32. package/dist/baseline/plan.js.map +1 -0
  33. package/dist/baseline/report.d.ts +125 -0
  34. package/dist/baseline/report.d.ts.map +1 -0
  35. package/dist/baseline/report.js +85 -0
  36. package/dist/baseline/report.js.map +1 -0
  37. package/dist/baseline/run.d.ts +106 -0
  38. package/dist/baseline/run.d.ts.map +1 -0
  39. package/dist/baseline/run.js +339 -0
  40. package/dist/baseline/run.js.map +1 -0
  41. package/dist/bin/db-commands.d.ts +31 -0
  42. package/dist/bin/db-commands.d.ts.map +1 -0
  43. package/dist/bin/db-commands.js +276 -0
  44. package/dist/bin/db-commands.js.map +1 -0
  45. package/dist/bin/fs-io.d.ts +7 -0
  46. package/dist/bin/fs-io.d.ts.map +1 -0
  47. package/dist/bin/fs-io.js +45 -0
  48. package/dist/bin/fs-io.js.map +1 -0
  49. package/dist/bin/platform.d.ts +21 -0
  50. package/dist/bin/platform.d.ts.map +1 -0
  51. package/dist/bin/platform.js +99 -0
  52. package/dist/bin/platform.js.map +1 -0
  53. package/dist/compose/api.d.ts +84 -0
  54. package/dist/compose/api.d.ts.map +1 -0
  55. package/dist/compose/api.js +101 -0
  56. package/dist/compose/api.js.map +1 -0
  57. package/dist/compose/compose.d.ts +51 -0
  58. package/dist/compose/compose.d.ts.map +1 -0
  59. package/dist/compose/compose.js +177 -0
  60. package/dist/compose/compose.js.map +1 -0
  61. package/dist/compose/diff.d.ts +7 -0
  62. package/dist/compose/diff.d.ts.map +1 -0
  63. package/dist/compose/diff.js +68 -0
  64. package/dist/compose/diff.js.map +1 -0
  65. package/dist/compose/errors.d.ts +31 -0
  66. package/dist/compose/errors.d.ts.map +1 -0
  67. package/dist/compose/errors.js +35 -0
  68. package/dist/compose/errors.js.map +1 -0
  69. package/dist/compose/index.d.ts +3 -0
  70. package/dist/compose/index.d.ts.map +1 -0
  71. package/dist/compose/index.js +11 -0
  72. package/dist/compose/index.js.map +1 -0
  73. package/dist/compose/parse.d.ts +65 -0
  74. package/dist/compose/parse.d.ts.map +1 -0
  75. package/dist/compose/parse.js +122 -0
  76. package/dist/compose/parse.js.map +1 -0
  77. package/dist/drift/db-conformance.d.ts +49 -0
  78. package/dist/drift/db-conformance.d.ts.map +1 -0
  79. package/dist/drift/db-conformance.js +65 -0
  80. package/dist/drift/db-conformance.js.map +1 -0
  81. package/dist/drift/index.d.ts +5 -0
  82. package/dist/drift/index.d.ts.map +1 -0
  83. package/dist/drift/index.js +26 -0
  84. package/dist/drift/index.js.map +1 -0
  85. package/dist/drift/raw-sql-indexes.d.ts +106 -0
  86. package/dist/drift/raw-sql-indexes.d.ts.map +1 -0
  87. package/dist/drift/raw-sql-indexes.js +113 -0
  88. package/dist/drift/raw-sql-indexes.js.map +1 -0
  89. package/dist/drift/raw-sql-tripwire.d.ts +150 -0
  90. package/dist/drift/raw-sql-tripwire.d.ts.map +1 -0
  91. package/dist/drift/raw-sql-tripwire.js +394 -0
  92. package/dist/drift/raw-sql-tripwire.js.map +1 -0
  93. package/dist/drift/run.d.ts +128 -0
  94. package/dist/drift/run.d.ts.map +1 -0
  95. package/dist/drift/run.js +201 -0
  96. package/dist/drift/run.js.map +1 -0
  97. package/dist/index.d.ts +16 -0
  98. package/dist/index.d.ts.map +1 -0
  99. package/dist/index.js +33 -0
  100. package/dist/index.js.map +1 -0
  101. package/dist/lock/hash.d.ts +13 -0
  102. package/dist/lock/hash.d.ts.map +1 -0
  103. package/dist/lock/hash.js +19 -0
  104. package/dist/lock/hash.js.map +1 -0
  105. package/dist/lock/index.d.ts +5 -0
  106. package/dist/lock/index.d.ts.map +1 -0
  107. package/dist/lock/index.js +20 -0
  108. package/dist/lock/index.js.map +1 -0
  109. package/dist/lock/lock.d.ts +117 -0
  110. package/dist/lock/lock.d.ts.map +1 -0
  111. package/dist/lock/lock.js +140 -0
  112. package/dist/lock/lock.js.map +1 -0
  113. package/dist/lock/manifest.d.ts +60 -0
  114. package/dist/lock/manifest.d.ts.map +1 -0
  115. package/dist/lock/manifest.js +95 -0
  116. package/dist/lock/manifest.js.map +1 -0
  117. package/dist/lock/semver.d.ts +10 -0
  118. package/dist/lock/semver.d.ts.map +1 -0
  119. package/dist/lock/semver.js +13 -0
  120. package/dist/lock/semver.js.map +1 -0
  121. package/dist/seed/index.d.ts +4 -0
  122. package/dist/seed/index.d.ts.map +1 -0
  123. package/dist/seed/index.js +10 -0
  124. package/dist/seed/index.js.map +1 -0
  125. package/dist/seed/input.d.ts +52 -0
  126. package/dist/seed/input.d.ts.map +1 -0
  127. package/dist/seed/input.js +77 -0
  128. package/dist/seed/input.js.map +1 -0
  129. package/dist/seed/seed-platform.d.ts +28 -0
  130. package/dist/seed/seed-platform.d.ts.map +1 -0
  131. package/dist/seed/seed-platform.js +133 -0
  132. package/dist/seed/seed-platform.js.map +1 -0
  133. package/dist/seed/types.d.ts +277 -0
  134. package/dist/seed/types.d.ts.map +1 -0
  135. package/dist/seed/types.js +5 -0
  136. package/dist/seed/types.js.map +1 -0
  137. package/dist/sync/apply.d.ts +29 -0
  138. package/dist/sync/apply.d.ts.map +1 -0
  139. package/dist/sync/apply.js +37 -0
  140. package/dist/sync/apply.js.map +1 -0
  141. package/dist/sync/check.d.ts +56 -0
  142. package/dist/sync/check.d.ts.map +1 -0
  143. package/dist/sync/check.js +108 -0
  144. package/dist/sync/check.js.map +1 -0
  145. package/dist/sync/errors.d.ts +31 -0
  146. package/dist/sync/errors.d.ts.map +1 -0
  147. package/dist/sync/errors.js +23 -0
  148. package/dist/sync/errors.js.map +1 -0
  149. package/dist/sync/index.d.ts +9 -0
  150. package/dist/sync/index.d.ts.map +1 -0
  151. package/dist/sync/index.js +25 -0
  152. package/dist/sync/index.js.map +1 -0
  153. package/dist/sync/ledger.d.ts +65 -0
  154. package/dist/sync/ledger.d.ts.map +1 -0
  155. package/dist/sync/ledger.js +49 -0
  156. package/dist/sync/ledger.js.map +1 -0
  157. package/dist/sync/plan.d.ts +61 -0
  158. package/dist/sync/plan.d.ts.map +1 -0
  159. package/dist/sync/plan.js +79 -0
  160. package/dist/sync/plan.js.map +1 -0
  161. package/dist/sync/promote.d.ts +58 -0
  162. package/dist/sync/promote.d.ts.map +1 -0
  163. package/dist/sync/promote.js +93 -0
  164. package/dist/sync/promote.js.map +1 -0
  165. package/dist/sync/timestamps.d.ts +41 -0
  166. package/dist/sync/timestamps.d.ts.map +1 -0
  167. package/dist/sync/timestamps.js +68 -0
  168. package/dist/sync/timestamps.js.map +1 -0
  169. package/dist/sync/version.d.ts +28 -0
  170. package/dist/sync/version.d.ts.map +1 -0
  171. package/dist/sync/version.js +66 -0
  172. package/dist/sync/version.js.map +1 -0
  173. package/migrations/0001_initial/migration.sql +297 -0
  174. package/migrations/0002_add_personal_access_tokens/migration.sql +31 -0
  175. package/migrations/0003_add_credentials/migration.sql +20 -0
  176. package/migrations/0004_add_notification_deliveries/migration.sql +27 -0
  177. package/migrations/0005_drop_stale_uuid_defaults/migration.sql +35 -0
  178. package/migrations/0006_add_notifications/migration.sql +22 -0
  179. package/migrations/0007_add_push_subscriptions/migration.sql +25 -0
  180. package/migrations/0008_add_jobs/migration.sql +110 -0
  181. package/migrations/0009_add_worker_nodes/migration.sql +90 -0
  182. package/migrations/0010_add_database_backup_runs/migration.sql +104 -0
  183. package/migrations/0011_add_notification_broadcasts/migration.sql +57 -0
  184. package/migrations/0012_add_backup_run_job_link/migration.sql +87 -0
  185. package/migrations/0013_add_job_node_secrets/migration.sql +61 -0
  186. package/migrations/0014_add_backup_run_pg_dump_version/migration.sql +26 -0
  187. package/migrations/0015_add_job_claim_token/migration.sql +92 -0
  188. package/migrations/0016_add_ai_platform/migration.sql +108 -0
  189. package/migrations/0017_revoke_viewer_ai_use/migration.sql +32 -0
  190. package/migrations/0018_add_user_credentials/migration.sql +29 -0
  191. package/migrations/0019_add_device_session_credential_link/migration.sql +52 -0
  192. package/migrations/0020_add_worker_node_vitals/migration.sql +3 -0
  193. package/migrations/0021_add_job_trace_context/migration.sql +6 -0
  194. package/migrations/0022_add_retention_created_at_indexes/migration.sql +13 -0
  195. package/migrations/0023_add_organizations/migration.sql +142 -0
  196. package/migrations/0024_split_system_org_roles/migration.sql +131 -0
  197. package/migrations/manifest.json +240 -0
  198. package/package.json +75 -4
  199. package/raw-sql-indexes.json +49 -0
  200. package/schema/ai.prisma +387 -0
  201. package/schema/base.prisma +11 -0
  202. package/schema/credentials.prisma +108 -0
  203. package/schema/db-backup.prisma +376 -0
  204. package/schema/identity.prisma +407 -0
  205. package/schema/jobs.prisma +731 -0
  206. package/schema/notifications.prisma +610 -0
  207. package/schema/settings.prisma +35 -0
  208. package/schema/storage.prisma +57 -0
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.slugOf = slugOf;
4
+ exports.sequenceOf = sequenceOf;
5
+ exports.planBaseline = planBaseline;
6
+ const index_js_1 = require("../lock/index.js");
7
+ const index_js_2 = require("../sync/index.js");
8
+ const errors_js_1 = require("./errors.js");
9
+ /** The directory slug of a package migration id (the rule `platform db sync` uses). */
10
+ function slugOf(id) {
11
+ return id.replace(/^\d{4}_/, '').replace(/-/g, '_');
12
+ }
13
+ /** The sequence number of a manifest id (`0007_x` is 7). */
14
+ function sequenceOf(id) {
15
+ return Number(id.slice(0, 4));
16
+ }
17
+ const STAMP = /^(\d{14})_/;
18
+ function noteFor(kind) {
19
+ return kind === 'normalised'
20
+ ? 'differs from the package file only in comments or whitespace (recorded by platform db baseline)'
21
+ : 'mapped by the operator with --map; the baseline diff showed the live schema equals the package history (recorded by platform db baseline)';
22
+ }
23
+ /**
24
+ * Plans the baseline: one entry per package migration, in order, with the
25
+ * directory name every installed one will get. Pure.
26
+ *
27
+ * Placement (ADR 0002 D4): a migration that is installed **and** resolved goes
28
+ * immediately after its package predecessor (predecessor timestamp plus one
29
+ * second, or the next free second), or before everything when it has no
30
+ * predecessor, so a fresh database built from the adopted history applies it
31
+ * in package order and the app's own equivalent migration then no-ops. A
32
+ * migration above `--through` goes to the end by the sync naming rule.
33
+ *
34
+ * @param manifest - The package history.
35
+ * @param matched - The result of `proposeMapping`.
36
+ * @param localDirs - Every directory name under the app's `prisma/migrations`.
37
+ * @param through - The sequence number of the migration the database claims to equal.
38
+ * @param recorded - Directory names with a finished `_prisma_migrations` row; empty for a database Prisma never managed.
39
+ * @param now - The clock for migrations above `--through`.
40
+ * @returns The plan.
41
+ * @throws BaselineError `PLACEMENT_IMPOSSIBLE` when the directories cannot be made to sort in package order.
42
+ * @stability experimental
43
+ */
44
+ function planBaseline(manifest, matched, localDirs, through, recorded, now) {
45
+ const byOrigin = new Map(matched.map((m) => [m.originId, m]));
46
+ const taken = new Set(localDirs.flatMap((d) => STAMP.exec(d)?.[1] ?? []));
47
+ const earliest = [...taken].sort()[0];
48
+ const plan = [];
49
+ for (const entry of manifest) {
50
+ const originId = (0, index_js_1.originIdOf)(entry);
51
+ const base = { originId, packageDir: entry.dir, sha256: entry.sha256, since: entry.since };
52
+ const hit = byOrigin.get(originId);
53
+ const belowThrough = sequenceOf(entry.id) <= through;
54
+ if (hit) {
55
+ plan.push({
56
+ ...base,
57
+ localDir: hit.localDir,
58
+ action: 'mapped',
59
+ kind: hit.kind,
60
+ ...(hit.localSha256 ? { localSha256: hit.localSha256, note: noteFor(hit.kind) } : {}),
61
+ resolve: belowThrough && !recorded.has(hit.localDir),
62
+ });
63
+ continue;
64
+ }
65
+ if (!belowThrough) {
66
+ plan.push({ ...base, localDir: '', action: 'install', resolve: false });
67
+ continue;
68
+ }
69
+ const previous = plan[plan.length - 1];
70
+ let stamp;
71
+ if (previous) {
72
+ const predecessor = STAMP.exec(previous.localDir)?.[1];
73
+ if (!predecessor) {
74
+ throw new errors_js_1.BaselineError('PLACEMENT_IMPOSSIBLE', `${previous.localDir} (${previous.originId}) has no 14-digit timestamp, so ${originId} cannot be placed after it`);
75
+ }
76
+ let ms = (0, index_js_2.parseTimestamp)(predecessor) + 1000;
77
+ while (taken.has((0, index_js_2.formatTimestamp)(ms)))
78
+ ms += 1000;
79
+ stamp = (0, index_js_2.formatTimestamp)(ms);
80
+ }
81
+ else {
82
+ let ms = (earliest ? (0, index_js_2.parseTimestamp)(earliest) : now.getTime()) - 1000;
83
+ while (taken.has((0, index_js_2.formatTimestamp)(ms)))
84
+ ms -= 1000;
85
+ stamp = (0, index_js_2.formatTimestamp)(ms);
86
+ }
87
+ taken.add(stamp);
88
+ plan.push({ ...base, localDir: `${stamp}_${slugOf(entry.id)}`, action: 'install-resolve', resolve: true });
89
+ }
90
+ // Migrations above --through are named last, after everything already in the history (the sync rule).
91
+ const tail = plan.filter((p) => p.action === 'install');
92
+ if (tail.length > 0) {
93
+ const stamps = (0, index_js_2.nextTimestamps)([...localDirs, ...plan.filter((p) => p.localDir).map((p) => p.localDir)], tail.length, now);
94
+ tail.forEach((p, i) => {
95
+ p.localDir = `${stamps[i]}_${slugOf(p.originId.slice('platform:'.length))}`;
96
+ });
97
+ }
98
+ for (let i = 1; i < plan.length; i += 1) {
99
+ if (plan[i].localDir <= plan[i - 1].localDir) {
100
+ throw new errors_js_1.BaselineError('PLACEMENT_IMPOSSIBLE', `${plan[i].originId} would be ${plan[i].localDir}, which does not sort after ${plan[i - 1].localDir} (${plan[i - 1].originId}); a fresh database would apply the history in another order. Rename or re-map the directories so they sort in package order`);
101
+ }
102
+ }
103
+ return plan;
104
+ }
105
+ //# sourceMappingURL=plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan.js","sourceRoot":"","sources":["../../src/baseline/plan.ts"],"names":[],"mappings":";;AA6CA,wBAEC;AAGD,gCAEC;AA+BD,oCA0EC;AA7JD,+CAAkE;AAClE,+CAAmF;AACnF,2CAA4C;AA0C5C,uFAAuF;AACvF,SAAgB,MAAM,CAAC,EAAU;IAC/B,OAAO,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACtD,CAAC;AAED,4DAA4D;AAC5D,SAAgB,UAAU,CAAC,EAAU;IACnC,OAAO,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,KAAK,GAAG,YAAY,CAAC;AAE3B,SAAS,OAAO,CAAC,IAAe;IAC9B,OAAO,IAAI,KAAK,YAAY;QAC1B,CAAC,CAAC,iGAAiG;QACnG,CA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,CAAC;QAC9E,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,IAAI,IAAI,CAAC,CAAC,CAAE,CAAC,QAAQ,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC,QAAQ,EAAE,CAAC;YAC/C,MAAM,IAAI,yBAAa,CACrB,sBAAsB,EACtB,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC,QAAQ,aAAa,IAAI,CAAC,CAAC,CAAE,CAAC,QAAQ,+BAA+B,IAAI,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC,QAAQ,8HAA8H,CAC/P,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,125 @@
1
+ import type { RawIndexProblem } from '../drift/index.js';
2
+ import type { BaselineErrorCode } from './errors.js';
3
+ import type { MatchedMigration } from './mapping.js';
4
+ /**
5
+ * One reason the baseline will not write anything.
6
+ *
7
+ * @stability experimental
8
+ */
9
+ export interface BaselineRefusal {
10
+ /** The class of refusal. */
11
+ code: BaselineErrorCode;
12
+ /** What is wrong and how to fix it. */
13
+ message: string;
14
+ }
15
+ /**
16
+ * A migration `prisma migrate resolve --applied` runs for.
17
+ *
18
+ * @stability experimental
19
+ */
20
+ export interface BaselineResolveItem {
21
+ /** `platform:NNNN_slug`. */
22
+ originId: string;
23
+ /** The directory that is marked applied. */
24
+ localDir: string;
25
+ /** Whether the directory is created first (a migration with no directory), or already exists (a mapped one the ledger lacks). */
26
+ install: boolean;
27
+ }
28
+ /**
29
+ * A migration above `--through`: installed only.
30
+ *
31
+ * @stability experimental
32
+ */
33
+ export interface BaselineInstallItem {
34
+ /** `platform:NNNN_slug`. */
35
+ originId: string;
36
+ /** The directory that is created. */
37
+ localDir: string;
38
+ }
39
+ /**
40
+ * The statements of `prisma migrate diff` from the replayed package history to the live database.
41
+ *
42
+ * @stability experimental
43
+ */
44
+ export interface BaselineDiff {
45
+ /** Statements a declared deviation (`platform.lock` `deviations[].expectDiff`) expects, normalised. */
46
+ allowed: string[];
47
+ /** Every other statement, normalised; each one blocks the baseline. */
48
+ blocking: string[];
49
+ }
50
+ /**
51
+ * What the baseline found in `_prisma_migrations`.
52
+ *
53
+ * @stability experimental
54
+ */
55
+ export interface BaselineLedgerState {
56
+ /** False when the table does not exist (a database Prisma never managed). */
57
+ managed: boolean;
58
+ /** One line per failed, rolled-back, missing or mismatching row. */
59
+ problems: string[];
60
+ }
61
+ /**
62
+ * The result of step B6.
63
+ *
64
+ * @stability experimental
65
+ */
66
+ export interface BaselineVerification {
67
+ /** True when status, the offline check and the ledger comparison all passed. */
68
+ ok: boolean;
69
+ /** One line per failure. */
70
+ problems: string[];
71
+ }
72
+ /**
73
+ * What `platform db baseline` found and did.
74
+ *
75
+ * @stability experimental
76
+ */
77
+ export interface BaselineReport {
78
+ /** The origin id the database is claimed to equal (`--through`). */
79
+ through: string;
80
+ /** Package migrations matched to an existing directory (step B1). */
81
+ matched: MatchedMigration[];
82
+ /** Migrations `prisma migrate resolve --applied` runs for; `install` says whether the directory is created first. */
83
+ toResolve: BaselineResolveItem[];
84
+ /** Migrations above `--through`: installed only, `prisma migrate deploy` applies them. */
85
+ toInstall: BaselineInstallItem[];
86
+ /** Local directories no package migration matched; they are app history and left alone. */
87
+ appOnly: string[];
88
+ /** Package origin ids with no local directory. */
89
+ unmatched: string[];
90
+ /** `prisma migrate diff` from the package history (to `--through`) to the live database. `allowed` are statements a declared deviation expects; `blocking` is everything else. */
91
+ diff: BaselineDiff;
92
+ /** Raw-SQL indexes that are missing or whose definition differs (step B4). */
93
+ indexProblems: RawIndexProblem[];
94
+ /** The `_prisma_migrations` ledger: whether Prisma manages the database, and the problems found. */
95
+ ledger: BaselineLedgerState;
96
+ /** Everything that blocks `--apply`; empty when the baseline can proceed. */
97
+ refusals: BaselineRefusal[];
98
+ /** Warnings that do not block. */
99
+ notes: string[];
100
+ /** What `--apply` did, in order (empty on a dry run). */
101
+ actions: string[];
102
+ /** The result of step B6 (only after `--apply`). */
103
+ verify?: BaselineVerification;
104
+ /** True when `platform.lock` already holds exactly what the plan would write. */
105
+ lockUpToDate: boolean;
106
+ /** True when files were written and migrations resolved. */
107
+ applied: boolean;
108
+ }
109
+ /**
110
+ * Whether a baseline run succeeded: nothing refused it and, when it applied, the verification passed.
111
+ *
112
+ * @param report - The result of `runBaseline`.
113
+ * @returns True when the command should exit 0.
114
+ * @stability experimental
115
+ */
116
+ export declare function isBaselineClean(report: BaselineReport): boolean;
117
+ /**
118
+ * Renders the report as plain text lines (also a block to paste into an issue).
119
+ *
120
+ * @param report - The result of `runBaseline`.
121
+ * @returns The lines.
122
+ * @stability experimental
123
+ */
124
+ export declare function renderReport(report: BaselineReport): string[];
125
+ //# sourceMappingURL=report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../src/baseline/report.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,4BAA4B;IAC5B,IAAI,EAAE,iBAAiB,CAAC;IACxB,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,4BAA4B;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;IACjB,iIAAiI;IACjI,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;GAIG;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AC,EAAE,oBAAoB,CAAC;IAC9B,iFAAiF;IACjF,YAAY,EAAE,OAAO,CAAC;IACtB,4DAA4D;IAC5D,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAE/D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,EAAE,CAgD7D"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isBaselineClean = isBaselineClean;
4
+ exports.renderReport = renderReport;
5
+ /**
6
+ * Whether a baseline run succeeded: nothing refused it and, when it applied, the verification passed.
7
+ *
8
+ * @param report - The result of `runBaseline`.
9
+ * @returns True when the command should exit 0.
10
+ * @stability experimental
11
+ */
12
+ function isBaselineClean(report) {
13
+ return report.refusals.length === 0 && (report.verify?.ok ?? true);
14
+ }
15
+ /**
16
+ * Renders the report as plain text lines (also a block to paste into an issue).
17
+ *
18
+ * @param report - The result of `runBaseline`.
19
+ * @returns The lines.
20
+ * @stability experimental
21
+ */
22
+ function renderReport(report) {
23
+ const lines = [];
24
+ const mode = report.applied ? 'APPLIED' : 'DRY RUN (nothing was written)';
25
+ lines.push(`platform db baseline: ${mode}, through ${report.through}`);
26
+ lines.push('');
27
+ lines.push(`B1 map: ${report.matched.length} matched, ${report.unmatched.length} unmatched, ${report.appOnly.length} app-only`);
28
+ for (const m of report.matched) {
29
+ lines.push(` ${m.originId} -> ${m.localDir} [${m.kind}${m.localSha256 ? ', localSha256 recorded' : ''}]`);
30
+ }
31
+ for (const id of report.unmatched)
32
+ lines.push(` ${id} -> (no local directory)`);
33
+ for (const dir of report.appOnly)
34
+ lines.push(` app-only: ${dir}`);
35
+ lines.push('');
36
+ lines.push(`B2 ledger: ${report.ledger.managed ? 'managed by Prisma Migrate' : 'no _prisma_migrations table (a database Prisma never managed)'}; ${report.ledger.problems.length} problem(s)`);
37
+ for (const p of report.ledger.problems)
38
+ lines.push(` ${p}`);
39
+ lines.push('');
40
+ lines.push(`B3 diff (package history to ${report.through} -> live database): ${report.diff.blocking.length} blocking, ${report.diff.allowed.length} declared`);
41
+ for (const s of report.diff.allowed)
42
+ lines.push(` declared deviation: ${s}`);
43
+ for (const s of report.diff.blocking)
44
+ lines.push(` BLOCKING: ${s}`);
45
+ lines.push('');
46
+ lines.push(`B4 raw-SQL indexes: ${report.indexProblems.length} problem(s)`);
47
+ for (const p of report.indexProblems)
48
+ lines.push(` ${p.code} ${p.message}`);
49
+ lines.push('');
50
+ lines.push(`B5 act: ${report.toResolve.length} to resolve, ${report.toInstall.length} to install only`);
51
+ for (const r of report.toResolve)
52
+ lines.push(` ${report.applied ? 'resolved' : 'would resolve'} --applied ${r.localDir}${r.install ? ' (installed first)' : ''} <- ${r.originId}`);
53
+ for (const r of report.toInstall)
54
+ lines.push(` ${report.applied ? 'installed' : 'would install'} ${r.localDir} <- ${r.originId} (prisma migrate deploy applies it)`);
55
+ for (const a of report.actions)
56
+ lines.push(` action: ${a}`);
57
+ if (report.verify) {
58
+ lines.push('');
59
+ lines.push(`B6 verify: ${report.verify.ok ? 'ok' : `${report.verify.problems.length} problem(s)`}`);
60
+ for (const p of report.verify.problems)
61
+ lines.push(` ${p}`);
62
+ }
63
+ for (const n of report.notes)
64
+ lines.push(`note: ${n}`);
65
+ lines.push('');
66
+ if (report.refusals.length) {
67
+ lines.push(`REFUSED: ${report.refusals.length} reason(s); nothing was written`);
68
+ for (const r of report.refusals)
69
+ lines.push(` ${r.code} ${r.message}`);
70
+ }
71
+ else if (report.applied) {
72
+ lines.push(report.verify?.ok === false ? 'baseline applied, but verification FAILED (see above)' : 'baseline applied and verified');
73
+ }
74
+ else if (report.unmatched.length === 0 && report.toResolve.length === 0 && report.lockUpToDate) {
75
+ lines.push('nothing to do: platform.lock maps every package migration and the database records them');
76
+ }
77
+ else if (report.unmatched.length === 0 && report.toResolve.length === 0) {
78
+ lines.push('dry run clean: every package migration is mapped and recorded; --apply writes platform.lock only (nothing is resolved)');
79
+ }
80
+ else {
81
+ lines.push('dry run clean: re-run with --apply to write the lock and resolve');
82
+ }
83
+ return lines;
84
+ }
85
+ //# sourceMappingURL=report.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report.js","sourceRoot":"","sources":["../../src/baseline/report.ts"],"names":[],"mappings":";;AA2HA,0CAEC;AASD,oCAgDC;AAlED;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,MAAsB;IACpD,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,IAAI,IAAI,CAAC,CAAC;AACrE,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,MAAsB;IACjD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,+BAA+B,CAAC;IAC1E,KAAK,CAAC,IAAI,CAAC,yBAAyB,IAAI,aAAa,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IACvE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,WAAW,MAAM,CAAC,OAAO,CAAC,MAAM,aAAa,MAAM,CAAC,SAAS,CAAC,MAAM,eAAe,MAAM,CAAC,OAAO,CAAC,MAAM,WAAW,CAAC,CAAC;IAChI,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,OAAO,CAAC,CAAC,QAAQ,MAAM,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC9G,CAAC;IACD,KAAK,MAAM,EA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import { type ManifestEntry } from '../lock/index.js';
3
+ import { type LedgerRow } from '../sync/index.js';
4
+ import type { BaselineReport } from './report.js';
5
+ /**
6
+ * The runbook the refusals point to.
7
+ *
8
+ * @internal
9
+ */
10
+ export declare const BASELINE_RUNBOOK = "docs/runbooks/database-baseline.md";
11
+ /**
12
+ * The result of a Prisma CLI call.
13
+ *
14
+ * @stability experimental
15
+ */
16
+ export interface PrismaResult {
17
+ /** The exit status. */
18
+ status: number;
19
+ /** Standard output. */
20
+ stdout: string;
21
+ /** Standard error. */
22
+ stderr: string;
23
+ }
24
+ /**
25
+ * The effects of the baseline, injected so tests run it without a database or the Prisma CLI.
26
+ *
27
+ * Every database access is a read; the only database write is the
28
+ * `prisma migrate resolve --applied` call, which goes through `prisma`.
29
+ *
30
+ * @stability experimental
31
+ */
32
+ export interface BaselineDeps {
33
+ /** Logs one action or finding (every action is logged). */
34
+ log(line: string): void;
35
+ /** The clock for the names of migrations installed above `--through`. */
36
+ now(): Date;
37
+ /** Reads `_prisma_migrations`; `undefined` when the table does not exist (a database Prisma never managed). */
38
+ readLedger(): Promise<LedgerRow[] | undefined>;
39
+ /** Reads `name` and `indexdef` of the `public` indexes. */
40
+ readIndexes(): Promise<IndexRow[]>;
41
+ /** `prisma migrate diff --from-migrations <dir> --to-config-datasource --script`: the SQL that turns the replayed history into the live database; `''` when they are equal. */
42
+ diffReplayToLive(replayMigrationsDir: string): Promise<string>;
43
+ /** Runs a Prisma CLI command (`migrate resolve --applied <dir>`, `migrate status`) through the app's `scripts/prisma-env.js`. */
44
+ prisma(args: readonly string[]): Promise<PrismaResult>;
45
+ }
46
+ /**
47
+ * Options of {@link runBaseline}.
48
+ *
49
+ * @stability experimental
50
+ */
51
+ export interface BaselineOptions {
52
+ /** The app's `prisma/` directory (holds `migrations/` and `platform.lock`). */
53
+ appPrismaDir: string;
54
+ /** The platform-db package directory (holds `migrations/manifest.json`, `raw-sql-indexes.json` and `package.json`). */
55
+ packageDir: string;
56
+ /** A JSON file mapping `platform:NNNN_slug` to a local directory, for migrations the automatic passes cannot match. */
57
+ mapFile?: string;
58
+ /** Write the lock and resolve. Without it nothing is written and nothing is resolved. */
59
+ apply: boolean;
60
+ /** Allow `--apply` when `platform.lock` already has entries (they are replaced; deviations and raw-SQL indexes are kept). */
61
+ forceRemap?: boolean;
62
+ /** The package migration the database claims to equal: `22`, `0022` or `platform:0022_slug`. Default: the newest. Below the newest is partial adoption: the rest is installed and `migrate deploy` applies it. */
63
+ through?: string;
64
+ }
65
+ /**
66
+ * Reads an operator `--map` file.
67
+ *
68
+ * @param file - Path of a JSON object mapping `platform:NNNN_slug` to a directory name.
69
+ * @returns The mapping.
70
+ * @throws BaselineError `MAP_INVALID` when the file is not a JSON object of strings.
71
+ * @stability experimental
72
+ */
73
+ export declare function readOperatorMap(file: string): Record<string, string>;
74
+ /**
75
+ * Finds the `--through` entry.
76
+ *
77
+ * @param manifest - The package history.
78
+ * @param through - `22`, `0022`, `0022_slug` or `platform:0022_slug`; omitted means the newest.
79
+ * @returns The entry.
80
+ * @throws BaselineError `THROUGH_UNKNOWN`.
81
+ * @stability experimental
82
+ */
83
+ export declare function resolveThrough(manifest: readonly ManifestEntry[], through?: string): ManifestEntry;
84
+ /**
85
+ * `platform db baseline`: adopts the package history in a database that
86
+ * already has its schema, without re-running a migration (ADR 0002 D4).
87
+ *
88
+ * B1 maps the package migrations to the app's directories; B2 checks the
89
+ * `_prisma_migrations` ledger; B3 diffs the package history replayed to
90
+ * `--through` against the live database; B4 asserts the raw-SQL indexes in
91
+ * `pg_indexes`; B5 writes `platform.lock`, installs the migrations that have
92
+ * no directory and marks the ones at or below `--through` applied with
93
+ * `prisma migrate resolve --applied`; B6 verifies.
94
+ *
95
+ * Without `apply` nothing is written and `prisma` is never called. It never
96
+ * creates, drops or alters a database object, and there is no `--force`: any
97
+ * live difference no deviation declares refuses the baseline.
98
+ *
99
+ * @param opts - See {@link BaselineOptions}.
100
+ * @param deps - The injected effects.
101
+ * @returns The report; check `refusals` and `verify` (see `isBaselineClean`).
102
+ * @throws BaselineError for a bad `--through`, a bad `--map`, a failed `migrate resolve` or a corrupt package file; refusals found by the checks are returned in the report instead.
103
+ * @stability experimental
104
+ */
105
+ export declare function runBaseline(opts: BaselineOptions, deps: BaselineDeps): Promise<BaselineReport>;
106
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/baseline/run.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgD,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAChG,OAAO,EAQL,KAAK,aAAa,EAEnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAA2C,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAM3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,uCAAuC,CAAC;AAErE;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,yEAAyE;IACzE,GAAG,IAAI,IAAI,CAAC;IACZ,+GAA+G;IAC/G,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,GAAG,SAAS,CAAC,CAAC;IAC/C,2DAA2D;IAC3D,WAAW,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IACnC,+KAA+K;IAC/K,gBAAgB,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/D,iIAAiI;IACjI,MAAM,CAAC,IAAI,EAAE,SAAS,MAAM,EA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