Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration errors do not say which migration errored #1047

Open
NullVoxPopuli opened this issue Aug 5, 2024 · 1 comment
Open

Migration errors do not say which migration errored #1047

NullVoxPopuli opened this issue Aug 5, 2024 · 1 comment
Labels
Good First Issue Want to contribute? Just filter by this label Priority: Low Something worth considering, but not a top priority for the team Status: Accepted The proposal or the feature has been accepted for the future versions Type: Enhancement Improving an existing feature

Comments

@NullVoxPopuli
Copy link

NullVoxPopuli commented Aug 5, 2024

Package version

20-21

Describe the bug

Error printed:

❯ Executed 1 migrations, 1 error, 0 skipped

INSERT INTO "_knex_temp_alter362" SELECT * FROM "links"; - FOREIGN KEY constraint failed

Which isn't helpful. Not enough information is provided.

For now, I've patched to provide which file it was stuck on:

diff --git a/build/commands/migration/_base.js b/build/commands/migration/_base.js
index 182975ea330a4c824800870e8a5cabf8ddee7dec..259f1b206cfdb812cc27b599fe30dd04c6967b02 100644
--- a/build/commands/migration/_base.js
+++ b/build/commands/migration/_base.js
@@ -107,10 +107,14 @@ export default class MigrationsBase extends BaseCommand {
                 output = this.colors.grey(message);
                 break;
             case 'error':
-                const skippedMigrations = Object.values(migrator.migratedFiles).filter((file) => file.status === 'pending').length;
-                message = `❯ Executed ${processedFiles.size} migrations, 1 error, ${skippedMigrations} skipped`;
+                const files = Object.values(migrator.migratedFiles);
+                const skippedMigrations = files.filter((file) => file.status === 'pending').length;
+                 message = `❯ Executed ${processedFiles.size} migrations, 1 error, ${skippedMigrations} skipped`;
                 this.logger.log(this.colors.red(message));
+                this.logger.log(JSON.stringify(files, null, 2));
                 this.logger.log('\n' + this.colors.red(migrator.error.message));
+                this.logger.log('\n' + this.colors.red(migrator.error.code));
+                this.logger.log('\n' + this.colors.red(new Error().stack));
                 this.exitCode = 1;
                 break;
         }

which prints this:

image

Much more helpful

@RomainLanz RomainLanz added Good First Issue Want to contribute? Just filter by this label Type: Enhancement Improving an existing feature Status: Accepted The proposal or the feature has been accepted for the future versions Priority: Low Something worth considering, but not a top priority for the team labels Aug 31, 2024
@Barabasbalazs
Copy link

@NullVoxPopuli it seems that you're using the --compact-output set to true flag when running the migrations which will print a shorthand version of the error:

migration_short

But if you set the flag to false (and I think it's false by default) it should show you which migration fails:

migration_long

Obviously if the community would prefer a little more extra information even in the shorthand format, I can make a quick PR to address this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue Want to contribute? Just filter by this label Priority: Low Something worth considering, but not a top priority for the team Status: Accepted The proposal or the feature has been accepted for the future versions Type: Enhancement Improving an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants