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

Enable rollback of all scripts from same migration #331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ftreguer
Copy link

Hi, here is a possible implementation of migrate-mongo down command to enable rollback of several migration scripts of a same migration. When you process to migration you can rollback all migrations scripts from a same migration.

If you have 3 pending migartions and you run migrate-mongo up, migrate-mongo down --block command will rollback the three migration scripts.

It could be usefull if you want to integrate it.

Thank you :)

Checklist
  • npm test passes and has 100% coverage
  • README.md is updated

@coveralls
Copy link

coveralls commented Mar 24, 2021

Coverage Status

Coverage remained the same at 100.0% when pulling aabc4bf on ftreguer:down_scripts_of_same_migration into 4906ff2 on seppevs:master.

@dlecan
Copy link

dlecan commented Mar 31, 2021

This feature is very interesting!
What is missing to merge this PR?

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

To understand well, you don't use mongo's sessions to rollback but run down scripts ?

Anyway the code looks clear to me :)

const downgraded = [];
const statusItems = await status(db);
const appliedItems = statusItems.filter(item => item.appliedAt !== "PENDING");
const lastAppliedItem = _.last(appliedItems);

let itemsToRollback = [];
Copy link

Choose a reason for hiding this comment

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

To avoid mutability

Suggested change
let itemsToRollback = [];
const itemsToRollback = isBlockRollback && lastAppliedItem.migrationBlock ? appliedItems.filter(item => item.migrationBlock === lastAppliedItem.migrationBlock).reverse() : [lastAppliedItem]

Copy link

Choose a reason for hiding this comment

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

I will take this into account in a next PR if it's ok for you as I will make a proposal of improvement for up & down commands.

Copy link

@ghost ghost May 5, 2021

Choose a reason for hiding this comment

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

Here it is: ftreguer#1
I will modify the base branch once this one will be merged into master.

appliedAt: new Date(),
},
{
fileName: "20160609113224-second_migration.js",
Copy link

@ghost ghost May 5, 2021

Choose a reason for hiding this comment

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

You should change the timestamp of second migration as currently the first ends with ...3224 and the last with ...3225.

The second migration should follow a chronological order as the lib sorts the migration that way. So :

  • ...3224 : 1st migration
  • ...3225 : 2nd migration
  • ...3226 : last migration

Here second is after first in the alphabetical order, so it's it not a problem, but it could be with other namings.

@ghost
Copy link

ghost commented May 5, 2021

We should also update the README with the new -b --block option added to down command.

EDIT : sorry, actually there is no need to do that as there is the --help option

@Nigui
Copy link

Nigui commented Jun 7, 2021

any updates on this feature ?

@PavanKumarNew
Copy link

Hi Team,

Regarding PR, Enable rollback of all scripts from same migration #331 when it can be commited to main branch

Regards
Pavan

@PavanKumarNew
Copy link

Any Update on this, We are looking for this feature

@livacengiz
Copy link

Hi, @seppevs. this PR are so important for all of us. can you merge please?

@jorasmhj
Copy link

Any update on why this PR has not been merged yet?

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

Successfully merging this pull request may close these issues.

None yet

7 participants