From a6fea61570116e5d1cef4be8bfba5b22ed5989d2 Mon Sep 17 00:00:00 2001 From: Riuen Date: Mon, 14 Aug 2023 08:36:02 -0500 Subject: [PATCH 1/2] Include actual and expected hash in migration validation error message --- src/validation.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/validation.ts b/src/validation.ts index e088ada..8154102 100644 --- a/src/validation.ts +++ b/src/validation.ts @@ -27,8 +27,9 @@ export function validateMigrationHashes( const invalidHashes = migrations.filter(invalidHash) if (invalidHashes.length > 0) { // Someone has altered one or more migrations which has already run - gasp! - const invalidFiles = invalidHashes.map(({fileName}) => fileName) - throw new Error(`Hashes don't match for migrations '${invalidFiles}'. -This means that the scripts have changed since it was applied.`) + const errors = invalidHashes + .map(migration => `Migration failed for File: ${migration.fileName}. This means that this script has changed since it was applied.\n\tExpected Hash: ${appliedMigrations[migration.id].hash}\n\tActual Hash: ${migration.hash}`) + .join('\n'); + throw new Error(errors); } } From b26cf73569116b3c887966805f25fb4f3410485a Mon Sep 17 00:00:00 2001 From: Riuen Date: Mon, 14 Aug 2023 08:45:17 -0500 Subject: [PATCH 2/2] reduce line character count for migration validation error message creation --- src/validation.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/validation.ts b/src/validation.ts index 8154102..15afbc9 100644 --- a/src/validation.ts +++ b/src/validation.ts @@ -28,7 +28,9 @@ export function validateMigrationHashes( if (invalidHashes.length > 0) { // Someone has altered one or more migrations which has already run - gasp! const errors = invalidHashes - .map(migration => `Migration failed for File: ${migration.fileName}. This means that this script has changed since it was applied.\n\tExpected Hash: ${appliedMigrations[migration.id].hash}\n\tActual Hash: ${migration.hash}`) + .map(migration => `Migration failed for File: ${migration.fileName}.` + + 'This means that this script has changed since it was applied.\n\t' + + `Expected Hash: ${appliedMigrations[migration.id].hash}\n\tActual Hash: ${migration.hash}`) .join('\n'); throw new Error(errors); }