-
Notifications
You must be signed in to change notification settings - Fork 70
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
Migrate down from CLI #8
Comments
Now, it's mentioned in the rollback documentation: https://github.com/emirotin/mongodb-migrations#migratorrollback The reason is the rollback is intended for undoing recent migrations set, and it's only known after applying the set of migrations and storing them in the Migrator object. Though I may allow running individual migrations from the CLI some day. |
If there's a "down" definition defined, then why can't the CLI run that part only? The down definition should have all that a migration needs to apply for a rollback... IMHO |
The library as it is doesn't support running individual migrations from the CLI. With the CLI usage you run everything that wasn't ran before. WIth the Migrator object (programmatic usage) you can add migrations by hand. The rollback procedure is meant to undo everything from the current attempt. With the programmatic usage the list of the current attempt is available and hence the rollback is possible (as I explained in the previous answer). The CLI is stateless - it doesn't know what have just happened on the previous run. Again as already mentioned I may add the ability to manually run individual transactions from the CLI with optional up/down parameter. Can you elaborate on your use-case? Do you run your migrations by hand and then want to rollback them by hand as well? Do you need this functionality for the development error/trial, like write the migration, run, check, rollback, iterate? |
For the last couple of questions, yes and yes. But not only for dev, if this functionality (manual rollback) exists for dev, I imagine it should work for any environment. Have you looked at how migrations work in other frameworks like Rails/Django/etc? This is quite a common/standard way to handle migrations. Rolling back the latest migration, which would simply be the same as migrating up, but using the 'down' definition in the migration script. More complex systems allow for providing a number of migrations to rollback, or the ID of the migration to rollback up-to, if that makes sense... |
So as I explained above this tool while used from the CLI is "run everything that's missing" Instead I will simply add an ability to run individual migrations (or multiple in order) up and down. Not sure how fast this can be down given I'm slightly off from Mongo development recently. |
I second @victorbstan's request. Not being able to rollback from the command-line is a deal-breaker to me. Here's a use case for using down migrations by hand. I create a feature branch that renames a collection. Later I need to switch back to master branch and hot fix something. In this case, I would want to rollback the migration made on the feature branch so that I can even run the code on master branch again (which is necessary because both branches ultimately would be used with the same dev database). Of course, some migrations can't be rolled back and other migration frameworks have a way of specifying this in the migration file. Otherwise nice library though. |
Fair enough. I have this feature planned, just didn't have time to implement it yet. But plan to find some soon. |
Great project. I particularly like being able to set config in js/coffeescript instead of json, since this leads to duplicated config for me. +1 on being able to manually undo migrations. |
Thanks On Wed, Mar 23, 2016 at 7:35 PM Tjaart van der Walt <
|
+1. Your project is great and easy to configure, but a "rollback" function to a specific migration is really needed :) |
+1 |
1 similar comment
+1 |
Also experiencing this problem. We have QA environments that might need the database to be rolled backwards and forwards depending on what is deployed there at any given time. I think that both the CLI and the programmatic methods should allow a forced 'down', which doesn't concern itself with what ran previously, etc. |
I agree it makes total sense. On Thu, Jul 7, 2016 at 2:11 PM Antony Jones notifications@github.com
|
Yeah, absolutely! On Thu, 7 Jul 2016, 12:20 Eugene Mirotin, notifications@github.com wrote:
|
Thanks, I'll try to make some time for that, maybe early next week. On Thu, Jul 7, 2016 at 3:28 PM Antony Jones notifications@github.com
|
Hey. Any update on this? Thx. |
Hey @emirotin ok - excellent. Sadly one of my developers took it upon themselves to migrate our project away from this module, so I won't have a real use case any more. Nevertheless, ping me if you need some help testing and I'll be happy to do so. |
Well, that's understandable, I didn't pay attention to a couple of issue for quite some time. |
Anybody interested can try the run-custom-sets branch and report any problems with it. |
Hey @emirotin have you made any progress on this issue? |
The feature is implemented in a branch (see the previous comment in this thread), so you can use it by switching your npm dependency to The automated tests for it are not yet done — busy doing other things currently. |
I use this And my code:
But I get error
How use rollback? |
Rollback is still not intended to be used this way. It looks like I forgot to expose the two new methods to the public API (they're implemented in the runner but not made available through the public migrator interface). |
@balkarov can you try now using a method called |
Hey @emirotin I am interested in this capability so I was checking it out. I found a couple of things that I hope might be useful feedback. Using a single migration:
When I run
Clearly Similar results for
|
@emirotin |
For those who are struggling with rollback of specific migrations from CLI, which is not working as intended, I submitted a pull request (#51) to fix the bug. |
Can I do it?
The text was updated successfully, but these errors were encountered: