feat: add module migration contracts and validation
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import type { ModuleMigrationAggregate } from "../modules/index.js";
|
||||
|
||||
function plural(count: number, singular: string): string {
|
||||
return count === 1 ? singular : `${singular}s`;
|
||||
}
|
||||
|
||||
export function formatMigrationValidationReport(
|
||||
aggregate: ModuleMigrationAggregate,
|
||||
): readonly string[] {
|
||||
const moduleCount = aggregate.modules.length;
|
||||
const migrationCount = aggregate.migrations.length;
|
||||
const header = `Migration validation passed (${moduleCount} ${plural(moduleCount, "module")}, ${migrationCount} ${plural(migrationCount, "migration")})${moduleCount === 0 ? "." : ":"}`;
|
||||
const lines = [header];
|
||||
|
||||
for (const module of aggregate.modules) {
|
||||
if (module.migrations.length === 0) {
|
||||
lines.push(`- ${module.moduleId} (no migrations)`);
|
||||
continue;
|
||||
}
|
||||
for (const migration of module.migrations) {
|
||||
lines.push(
|
||||
`- ${migration.identity} sha256=${migration.checksum} destructive=${migration.destructive.mode}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return Object.freeze(lines);
|
||||
}
|
||||
Reference in New Issue
Block a user