22 lines
689 B
JavaScript
22 lines
689 B
JavaScript
import { createHash } from 'node:crypto';
|
|
|
|
export function migrationChecksum(content) {
|
|
return createHash('sha256').update(content).digest('hex');
|
|
}
|
|
|
|
export function assertMigrationChecksum(version, expected, actual) {
|
|
if (expected !== actual) {
|
|
throw new Error(
|
|
`Applied migration ${version} was modified: expected sha256 ${expected}, got ${actual}`,
|
|
);
|
|
}
|
|
}
|
|
|
|
export function assertAppliedMigrationsPresent(appliedVersions, availableVersions) {
|
|
const available = new Set(availableVersions);
|
|
for (const version of appliedVersions) {
|
|
if (!available.has(version)) {
|
|
throw new Error(`Applied migration ${version} is missing from the repository`);
|
|
}
|
|
}
|
|
}
|