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

feat(core): Print the name of the migration that cannot be reverted when using n8n db:revert #9473

Merged
merged 4 commits into from
May 23, 2024

Conversation

despairblue
Copy link
Contributor

@despairblue despairblue commented May 21, 2024

Summary

Print the name of the migration that cannot be reverted. This should make it easier to figure out which migration was found to be the last one that was applied.

Also now completely refactor the revert command and the tests.

Related tickets and issues

https://n8nio.slack.com/archives/C062YRE7EG4/p1716199306266429?thread_ts=1716198135.426559&cid=C062YRE7EG4

Review / Merge checklist

  • PR title and summary are descriptive. Remember, the title automatically goes into the changelog. Use (no-changelog) otherwise. (conventions)
  • Tests included.

    A bug is not considered fixed, unless a test is added to prevent it from happening again.
    A feature is not complete without tests.

@despairblue despairblue marked this pull request as ready for review May 21, 2024 07:10
@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels May 21, 2024
packages/cli/src/commands/db/revert.ts Outdated Show resolved Hide resolved
packages/cli/src/commands/db/revert.ts Outdated Show resolved Hide resolved
packages/cli/test/unit/commands/db/revert.test.ts Outdated Show resolved Hide resolved
Comment on lines 109 to 111
expect(logger.error).toHaveBeenCalledWith(
'The last migration "Test Migration" was irreversible and cannot be reverted.',
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as with error messages, should we avoid asserting on specific strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you ask me I'd say it depends.

If we just want to make sure that some error is thrown then we can apply DRY here similar to how it already is done with UM_FIX_INSTRUCTION.
On the other hand, matching against a literal makes sense if the error became part of the external contract and we want to have an extra assertion making sure it's not changed without acknowledging that the contract changed. E.g. if I change a constant and all tests pass I don't expect the FE to break. In that case asserting against a literal creates value because every time I change a test I have to assume that the FE could break.

In this case I can create a constant for the constant error message, for the dynamic one I will have to continue to construct it in the tests.

packages/cli/test/unit/commands/db/revert.test.ts Outdated Show resolved Hide resolved
@despairblue
Copy link
Contributor Author

@ivov @krynble I refactored the command and the tests. Let me know what you think.

The error messages should be better, more descriptive and actionable and the tests use less ts-expect-error.

@despairblue despairblue requested review from krynble and ivov May 23, 2024 10:01
ivov
ivov previously approved these changes May 23, 2024
packages/cli/test/unit/commands/db/revert.test.ts Outdated Show resolved Hide resolved
Copy link

cypress bot commented May 23, 2024

1 flaky test on run #5115 ↗︎

0 361 12 0 Flakiness 1

Details:

🌳 🖥️ browsers:node18.12.0-chrome107 🤖 despairblue 🗃️ e2e/*
Project: n8n Commit: 41a4701d59
Status: Passed Duration: 04:33 💡
Started: May 23, 2024 2:29 PM Ended: May 23, 2024 2:33 PM
Flakiness  cypress/e2e/5-ndv.cy.ts • 1 flaky test

View Output Video

Test Artifacts
NDV > should not retrieve remote options when required params throw errors Screenshots Video

Review all test suite changes for PR #9473 ↗︎

Copy link
Contributor

✅ All Cypress E2E specs passed

Copy link
Contributor

✅ All Cypress E2E specs passed

@despairblue despairblue merged commit 3b93aae into master May 23, 2024
33 checks passed
@despairblue despairblue deleted the improve-logging branch May 23, 2024 16:16
MiloradFilipovic added a commit that referenced this pull request May 24, 2024
* master:
  refactor(core): Use consistent CSRF state validation across oAuth controllers (#9104)
  feat(core): Print the name of the migration that cannot be reverted when using `n8n db:revert` (#9473)
  fix(editor): Hard load after logout to reset stores (no-changelog) (#9500)
  refactor(core): Stop reporting `EAUTH` error codes to Sentry (no-changelog) (#9496)
  fix(core): Upgrade sheetjs to address CVE-2024-22363 (#9498)
  refactor: Remove skipped tests (no-changelog) (#9497)
  feat(editor): Add initial code for NodeView and Canvas rewrite (no-changelog) (#9135)
  fix(editor): Show input panel with not connected message (#9495)
  fix(editor): Prevent XSS in node-issues tooltip (#9490)

# Conflicts:
#	pnpm-lock.yaml
@github-actions github-actions bot mentioned this pull request May 30, 2024
@janober
Copy link
Member

janober commented May 30, 2024

Got released with n8n@1.44.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants