@prisma-next/migration-tools 0.4.2 → 0.5.0-dev.10
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/README.md +32 -20
- package/dist/{constants-BRi0X7B_.mjs → constants-WVGVMOdu.mjs} +1 -1
- package/dist/{constants-BRi0X7B_.mjs.map → constants-WVGVMOdu.mjs.map} +1 -1
- package/dist/{errors-BmiSgz1j.mjs → errors-CZ9JD4sd.mjs} +45 -16
- package/dist/errors-CZ9JD4sd.mjs.map +1 -0
- package/dist/exports/constants.mjs +1 -1
- package/dist/exports/dag.d.mts +4 -3
- package/dist/exports/dag.d.mts.map +1 -1
- package/dist/exports/dag.mjs +15 -15
- package/dist/exports/dag.mjs.map +1 -1
- package/dist/exports/{types.d.mts → errors.d.mts} +6 -8
- package/dist/exports/errors.d.mts.map +1 -0
- package/dist/exports/errors.mjs +3 -0
- package/dist/exports/graph.d.mts +2 -0
- package/dist/exports/graph.mjs +1 -0
- package/dist/exports/hash.d.mts +52 -0
- package/dist/exports/hash.d.mts.map +1 -0
- package/dist/exports/hash.mjs +3 -0
- package/dist/exports/io.d.mts +7 -6
- package/dist/exports/io.d.mts.map +1 -1
- package/dist/exports/io.mjs +156 -2
- package/dist/exports/io.mjs.map +1 -0
- package/dist/exports/metadata.d.mts +2 -0
- package/dist/exports/metadata.mjs +1 -0
- package/dist/exports/migration-ts.mjs +1 -1
- package/dist/exports/migration.d.mts +13 -10
- package/dist/exports/migration.d.mts.map +1 -1
- package/dist/exports/migration.mjs +20 -21
- package/dist/exports/migration.mjs.map +1 -1
- package/dist/exports/package.d.mts +2 -0
- package/dist/exports/package.mjs +1 -0
- package/dist/exports/refs.mjs +2 -2
- package/dist/graph-HiqjZROg.d.mts +22 -0
- package/dist/graph-HiqjZROg.d.mts.map +1 -0
- package/dist/hash-BNWumjn7.mjs +76 -0
- package/dist/hash-BNWumjn7.mjs.map +1 -0
- package/dist/metadata-DDa5L-uD.d.mts +45 -0
- package/dist/metadata-DDa5L-uD.d.mts.map +1 -0
- package/dist/package-BJ5KAEcD.d.mts +21 -0
- package/dist/package-BJ5KAEcD.d.mts.map +1 -0
- package/package.json +23 -11
- package/src/dag.ts +19 -18
- package/src/errors.ts +57 -15
- package/src/exports/errors.ts +1 -0
- package/src/exports/graph.ts +1 -0
- package/src/exports/hash.ts +2 -0
- package/src/exports/io.ts +1 -1
- package/src/exports/metadata.ts +1 -0
- package/src/exports/package.ts +1 -0
- package/src/graph.ts +19 -0
- package/src/hash.ts +91 -0
- package/src/io.ts +32 -20
- package/src/metadata.ts +36 -0
- package/src/migration-base.ts +32 -28
- package/src/package.ts +18 -0
- package/dist/attestation-BnzTb0Qp.mjs +0 -65
- package/dist/attestation-BnzTb0Qp.mjs.map +0 -1
- package/dist/errors-BmiSgz1j.mjs.map +0 -1
- package/dist/exports/attestation.d.mts +0 -37
- package/dist/exports/attestation.d.mts.map +0 -1
- package/dist/exports/attestation.mjs +0 -4
- package/dist/exports/types.d.mts.map +0 -1
- package/dist/exports/types.mjs +0 -3
- package/dist/io-Cd6GLyjK.mjs +0 -153
- package/dist/io-Cd6GLyjK.mjs.map +0 -1
- package/dist/types-DyGXcWWp.d.mts +0 -71
- package/dist/types-DyGXcWWp.d.mts.map +0 -1
- package/src/attestation.ts +0 -81
- package/src/exports/attestation.ts +0 -2
- package/src/exports/types.ts +0 -10
- package/src/types.ts +0 -66
package/src/attestation.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { canonicalizeJson } from './canonicalize-json';
|
|
3
|
-
import { readMigrationPackage } from './io';
|
|
4
|
-
import type { MigrationBundle, MigrationManifest, MigrationOps } from './types';
|
|
5
|
-
|
|
6
|
-
export interface VerifyResult {
|
|
7
|
-
readonly ok: boolean;
|
|
8
|
-
readonly reason?: 'mismatch';
|
|
9
|
-
readonly storedMigrationId?: string;
|
|
10
|
-
readonly computedMigrationId?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function sha256Hex(input: string): string {
|
|
14
|
-
return createHash('sha256').update(input).digest('hex');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Content-addressed migration identity over (manifest envelope sans
|
|
19
|
-
* contracts/hints, ops). See ADR 199 "Storage-only migration identity"
|
|
20
|
-
* for the rationale: contracts are anchored separately by the
|
|
21
|
-
* storage-hash bookends inside the envelope; planner hints are advisory
|
|
22
|
-
* and must not affect identity.
|
|
23
|
-
*
|
|
24
|
-
* The `migrationId` field on the manifest is stripped before hashing so
|
|
25
|
-
* the function can be used both at write time (when no id exists yet)
|
|
26
|
-
* and at verify time (rehashing an already-attested manifest).
|
|
27
|
-
*/
|
|
28
|
-
export function computeMigrationId(
|
|
29
|
-
manifest: Omit<MigrationManifest, 'migrationId'> & { readonly migrationId?: string },
|
|
30
|
-
ops: MigrationOps,
|
|
31
|
-
): string {
|
|
32
|
-
const {
|
|
33
|
-
migrationId: _migrationId,
|
|
34
|
-
signature: _signature,
|
|
35
|
-
fromContract: _fromContract,
|
|
36
|
-
toContract: _toContract,
|
|
37
|
-
hints: _hints,
|
|
38
|
-
...strippedMeta
|
|
39
|
-
} = manifest;
|
|
40
|
-
|
|
41
|
-
const canonicalManifest = canonicalizeJson(strippedMeta);
|
|
42
|
-
const canonicalOps = canonicalizeJson(ops);
|
|
43
|
-
|
|
44
|
-
const partHashes = [canonicalManifest, canonicalOps].map(sha256Hex);
|
|
45
|
-
const hash = sha256Hex(canonicalizeJson(partHashes));
|
|
46
|
-
|
|
47
|
-
return `sha256:${hash}`;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Re-hash an on-disk migration bundle and compare against the stored
|
|
52
|
-
* `migrationId`. Returns `{ ok: true }` when the package is internally
|
|
53
|
-
* consistent (manifest + ops still produce the recorded id), or
|
|
54
|
-
* `{ ok: false, reason: 'mismatch', stored, computed }` when they do
|
|
55
|
-
* not — typically a sign of FS corruption, partial writes, or a
|
|
56
|
-
* post-emit hand edit.
|
|
57
|
-
*/
|
|
58
|
-
export function verifyMigrationBundle(bundle: MigrationBundle): VerifyResult {
|
|
59
|
-
const computed = computeMigrationId(bundle.manifest, bundle.ops);
|
|
60
|
-
|
|
61
|
-
if (bundle.manifest.migrationId === computed) {
|
|
62
|
-
return {
|
|
63
|
-
ok: true,
|
|
64
|
-
storedMigrationId: bundle.manifest.migrationId,
|
|
65
|
-
computedMigrationId: computed,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
ok: false,
|
|
71
|
-
reason: 'mismatch',
|
|
72
|
-
storedMigrationId: bundle.manifest.migrationId,
|
|
73
|
-
computedMigrationId: computed,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** Convenience wrapper: read the package from disk then verify it. */
|
|
78
|
-
export async function verifyMigration(dir: string): Promise<VerifyResult> {
|
|
79
|
-
const pkg = await readMigrationPackage(dir);
|
|
80
|
-
return verifyMigrationBundle(pkg);
|
|
81
|
-
}
|
package/src/exports/types.ts
DELETED
package/src/types.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { Contract } from '@prisma-next/contract/types';
|
|
2
|
-
import type { MigrationPlanOperation } from '@prisma-next/framework-components/control';
|
|
3
|
-
|
|
4
|
-
export interface MigrationHints {
|
|
5
|
-
readonly used: readonly string[];
|
|
6
|
-
readonly applied: readonly string[];
|
|
7
|
-
readonly plannerVersion: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* On-disk migration manifest. Every migration is content-addressed: the
|
|
12
|
-
* `migrationId` is a hash over the manifest envelope plus the operations
|
|
13
|
-
* list, computed at write time. There is no draft state — a migration
|
|
14
|
-
* directory either exists with a fully attested manifest or it does not.
|
|
15
|
-
*
|
|
16
|
-
* When the planner cannot lower an operation because of an unfilled
|
|
17
|
-
* `placeholder(...)` slot, the migration is still written with
|
|
18
|
-
* `migrationId` hashed over `ops: []`. Re-running self-emit after the
|
|
19
|
-
* user fills the placeholder produces a *different* `migrationId`
|
|
20
|
-
* (committed to the real ops); this is intentional.
|
|
21
|
-
*/
|
|
22
|
-
export interface MigrationManifest {
|
|
23
|
-
readonly migrationId: string;
|
|
24
|
-
readonly from: string;
|
|
25
|
-
readonly to: string;
|
|
26
|
-
readonly kind: 'regular' | 'baseline';
|
|
27
|
-
readonly fromContract: Contract | null;
|
|
28
|
-
readonly toContract: Contract;
|
|
29
|
-
readonly hints: MigrationHints;
|
|
30
|
-
readonly labels: readonly string[];
|
|
31
|
-
readonly authorship?: { readonly author?: string; readonly email?: string };
|
|
32
|
-
readonly signature?: { readonly keyId: string; readonly value: string } | null;
|
|
33
|
-
readonly createdAt: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type MigrationOps = readonly MigrationPlanOperation[];
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* An on-disk migration directory containing a manifest and operations.
|
|
40
|
-
*/
|
|
41
|
-
export interface MigrationBundle {
|
|
42
|
-
readonly dirName: string;
|
|
43
|
-
readonly dirPath: string;
|
|
44
|
-
readonly manifest: MigrationManifest;
|
|
45
|
-
readonly ops: MigrationOps;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* An entry in the migration graph. All on-disk migrations are attested,
|
|
50
|
-
* so `migrationId` is always a string.
|
|
51
|
-
*/
|
|
52
|
-
export interface MigrationChainEntry {
|
|
53
|
-
readonly from: string;
|
|
54
|
-
readonly to: string;
|
|
55
|
-
readonly migrationId: string;
|
|
56
|
-
readonly dirName: string;
|
|
57
|
-
readonly createdAt: string;
|
|
58
|
-
readonly labels: readonly string[];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface MigrationGraph {
|
|
62
|
-
readonly nodes: ReadonlySet<string>;
|
|
63
|
-
readonly forwardChain: ReadonlyMap<string, readonly MigrationChainEntry[]>;
|
|
64
|
-
readonly reverseChain: ReadonlyMap<string, readonly MigrationChainEntry[]>;
|
|
65
|
-
readonly migrationById: ReadonlyMap<string, MigrationChainEntry>;
|
|
66
|
-
}
|