fix: 统一迁移校验换行符

This commit is contained in:
chenpei 2026-08-15 18:47:42 +08:00
parent 47f3b7e067
commit b470d356c6
2 changed files with 12 additions and 3 deletions

View File

@ -583,6 +583,7 @@ ${helper}`
expect(script).toContain('token.data_type === "text" && token.is_nullable === "YES"')
expect(script).toContain('expires.data_type === "timestamp without time zone" && expires.is_nullable === "YES"')
expect(script).toContain('String(migrations[0].checksum || "") === sourceChecksum')
expect(script).toContain('readFileSync(migrationPath, "utf8").replace(/\\r\\n/g, "\\n")')
expect(script).toContain('!/\\bUNIQUE\\b|\\bWHERE\\b\/i.test(indexDefinition)')
expect(script).toContain('!columnsOk || !indexOk || !migrationOk')
expect(script).toContain('traffic was not switched')

View File

@ -2674,7 +2674,11 @@ const p = new PrismaClient();
const migrationName = "20260812_add_product_package_upload_job_lease";
const migrationPath = `/app/prisma/migrations/${migrationName}/migration.sql`;
let sourceChecksum = "";
try { sourceChecksum = createHash("sha256").update(readFileSync(migrationPath)).digest("hex"); }
try {
sourceChecksum = createHash("sha256")
.update(readFileSync(migrationPath, "utf8").replace(/\r\n/g, "\n"), "utf8")
.digest("hex");
}
catch (error) { process.stderr.write(String(error && error.message || error)); process.exit(1); }
Promise.all([
p.$queryRawUnsafe("SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_schema = current_schema() AND table_name = $1 AND column_name IN ($2, $3, $4)", "product_package_upload_jobs", "worker_id", "lease_token", "lease_expires_at"),
@ -2718,7 +2722,11 @@ const p = new PrismaClient();
const migrationName = "20260811_add_video_transcode_lease";
const migrationPath = `/app/prisma/migrations/${migrationName}/migration.sql`;
let sourceChecksum = "";
try { sourceChecksum = createHash("sha256").update(readFileSync(migrationPath)).digest("hex"); }
try {
sourceChecksum = createHash("sha256")
.update(readFileSync(migrationPath, "utf8").replace(/\r\n/g, "\n"), "utf8")
.digest("hex");
}
catch (error) { process.stderr.write(String(error && error.message || error)); process.exit(1); }
Promise.all([
p.$queryRawUnsafe("SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_schema = current_schema() AND table_name = $1 AND column_name IN ($2, $3)", "materials", "transcode_lease_token", "transcode_lease_expires_at"),
@ -2818,7 +2826,7 @@ const p = new PrismaClient();
const historicalMigrationName = "20251118000000_add_upload_id_to_materials";
const normalizationMigrationName = "20260812_align_material_upload_idempotency_index";
const migrationChecksum = (name) => createHash("sha256")
.update(readFileSync(`/app/prisma/migrations/${name}/migration.sql`))
.update(readFileSync(`/app/prisma/migrations/${name}/migration.sql`, "utf8").replace(/\r\n/g, "\n"), "utf8")
.digest("hex");
let historicalSourceChecksum = "";
let normalizationSourceChecksum = "";