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: Improvements to the migrations CLI and workflow #8060

Merged
merged 14 commits into from
Jul 11, 2024

Conversation

thetutlage
Copy link
Contributor

@thetutlage thetutlage commented Jul 10, 2024

FIXES: CORE-2495
FIXES: CORE-2482

Breaking change

This PR revamps the migration commands to work as per the new setup. Here's how the migrations will run and revert moving forward.

  • The run command will continue to work as it is. I have to redo the CLI UI for it, but the behavior will remain the same.
  • The revert command can only be used for specific modules. You can no longer revert migrations without specifying the module name. Here's the reasoning for that.

The goal of the revert command is to undo mistakes during development. We should not confuse revert with rollback, where the later one is used to rollback the database state to a previous version.

Since, the revert command intent is highly tied to development and that too within a specific module, you will have to run it against a module as well. There is no global revert anymore.

Changelog

This PR revamps the migrations workflow and the CLI output entirely. Here's a summary of the changes.

  • The commands remains the same as npx medusa migrations run and npx medusa migrations revert
  • The CLI output has been changed to be more visually appealing and add separate migrations logs for each module with a line break.

Breaking changes

The revert command has a breaking change that it requires one or more module names to perform the revert. It means, the action revert is not valid at the global/app level. It must be executed on a specific module.

If you are developing a custom module, you can run the revert command for it as follows.

# helloWorld is the moduleName
npx medusa migrations revert helloWorld

Copy link

vercel bot commented Jul 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 11, 2024 11:04am
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Jul 11, 2024 11:04am
api-reference-v2 ⬜️ Ignored (Inspect) Visit Preview Jul 11, 2024 11:04am
docs-ui ⬜️ Ignored (Inspect) Visit Preview Jul 11, 2024 11:04am
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Jul 11, 2024 11:04am
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Jul 11, 2024 11:04am
resources-docs ⬜️ Ignored (Inspect) Visit Preview Jul 11, 2024 11:04am

Copy link

changeset-bot bot commented Jul 10, 2024

⚠️ No Changeset found

Latest commit: 30d4e47

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@thetutlage
Copy link
Contributor Author

Amazed that tests are passing already 🙄

@thetutlage
Copy link
Contributor Author

/snapshot-this

@thetutlage thetutlage marked this pull request as ready for review July 11, 2024 05:26
@thetutlage thetutlage requested a review from a team as a code owner July 11, 2024 05:26
@thetutlage
Copy link
Contributor Author

THE PR IS AVAILABLE FOR REVIEW. BUT, DO NOT MERGE.

@thetutlage
Copy link
Contributor Author

/snapshot-this

@thetutlage
Copy link
Contributor Author

/snapshot-this

Copy link
Contributor

🚀 A snapshot release has been made for this PR

Test the snapshots by updating your package.json with the newly published versions:

yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]

Latest commit: f460348

Copy link
Member

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

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

💪

const applyMigration = async (linkModuleOptions, revert = false) => {
for (const moduleName of Object.keys(allModules)) {
const moduleResolution = MedusaModule.getModuleResolutions(moduleName)
const applyMigration = async ({
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: As we discussed, we can probably move this one outside the main function wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uses sharedContainer and sharedConfig from the upper scope. Should we pass them down as parameters?

Copy link
Member

Choose a reason for hiding this comment

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

I think so, just to lighten this function a bit to simplify reading and understanding

packages/core/modules-sdk/src/medusa-app.ts Show resolved Hide resolved
packages/core/modules-sdk/src/medusa-module.ts Outdated Show resolved Hide resolved
packages/core/modules-sdk/src/medusa-module.ts Outdated Show resolved Hide resolved
packages/medusa/src/commands/migrate.ts Outdated Show resolved Hide resolved
packages/medusa/src/commands/migrate.ts Outdated Show resolved Hide resolved
packages/medusa/src/commands/migrate.ts Outdated Show resolved Hide resolved
@thetutlage
Copy link
Contributor Author

Screenshot 2024-07-11 at 1 02 21 PM

This is how the output looks like. I wish we could use a better logger for the CLI commands. Winston feels more like an app logger than a visually appealing logger

@adrien2p
Copy link
Member

adrien2p commented Jul 11, 2024

Screenshot 2024-07-11 at 1 02 21 PM This is how the output looks like. I wish we could use a better logger for the CLI commands. Winston feels more like an app logger than a visually appealing logger

Lovely :)

we might need to remove service from all the modules key cc @olivermrbl :)

@thetutlage
Copy link
Contributor Author

@olivermrbl Can be improved a lot, we need a visual logger for CLI commands and ditch Winston. Will get onto refactoring CLI output someday 💪

@srindom
Copy link
Collaborator

srindom commented Jul 11, 2024

@thetutlage - in production envs the logger uses a json format. Maybe we want to test that the output isn't filled with these types of outputs:

{ "level": "info", "message": "-------------------...." }

@adrien2p
Copy link
Member

@thetutlage - in production envs the logger uses a json format. Maybe we want to test that the output isn't filled with these types of outputs:

{ "level": "info", "message": "-------------------...." }

Do you think it would be problematic to have few spaces at the beginning of the message?

@thetutlage
Copy link
Contributor Author

@srindom Yes, it will be filled with that.

The ideal solution is to have helpers for these sort of outputs that has different behavior when the output is JSON.

But for now, either we have to remove these lines or apply a filter when these logs are consumed by a logging service.

@adrien2p
Copy link
Member

Yes and I believe our logger can have a custom handler for message and strip the space on front of it

@thetutlage
Copy link
Contributor Author

revert_error_invalid_module revert_error_without_module

@srindom
Copy link
Collaborator

srindom commented Jul 11, 2024

It shouldn't block this PR, but think it would be good for us to look into a way to specify that a log message is just for aesthetic purposes - we could maybe just use the silly log level for it, but let's leave that for another time :)

@thetutlage
Copy link
Contributor Author

Alright. We are ready to merge this PR. I have updated the description explaining the breaking change.

@thetutlage
Copy link
Contributor Author

CC @olivermrbl @adrien2p Ready to be re-reviewed and merged

@olivermrbl
Copy link
Contributor

olivermrbl commented Jul 11, 2024

@thetutlage, upon merging a PR, can I get you to prefix the commit message (and ideally the PR title) with a tag indicating the PR type feat, fix, chore, or docs? 💪

@thetutlage
Copy link
Contributor Author

thetutlage commented Jul 11, 2024

@olivermrbl Sure. Should this one be refactor?

@olivermrbl
Copy link
Contributor

olivermrbl commented Jul 11, 2024

@thetutlage, we don't have refactor, so I think we should go with feat for now. It is used to group the changes in the release notes and right now we have the following sections:

  • Features
  • Bugs
  • Chores
  • Documentation

@thetutlage
Copy link
Contributor Author

Cool!

@thetutlage thetutlage changed the title First iteration of commands implementation Feat: First iteration of commands implementation Jul 11, 2024
@thetutlage thetutlage merged commit 45c573b into develop Jul 11, 2024
23 checks passed
@thetutlage thetutlage changed the title Feat: First iteration of commands implementation Feat: Improvements to the migrations CLI and workflow Jul 11, 2024
@thetutlage thetutlage deleted the feat/implement-migration-commands branch July 11, 2024 11:22
@olivermrbl
Copy link
Contributor

Very nit, but can you use the lowercased version hehe. Just for consistency 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants