-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Feature request: migrate:reset #783
Comments
Hey there, I'm working on the rewrite of migrations (https://github.com/knex/arctic) I'm willing to consider this but I'm not sure about it quite yet. Are you primarily using this locally? If so wouldn't a script to drop the DB, create it, and then migrate to the latest be a better solution? |
It would certainly work. I'll throw one together. I was just thinking that it's probably a common enough use case to get put in the lib, but I defer to your judgement. Maybe a |
Totally with you on an |
@bendrucker What's the status of arctic? |
@bendrucker Is Arctic going to happen soon? |
I ran into multiple issues doing this locally with Postgres such as the difficulty of running commands via the CLI, system permissions, db permissions, etc. I did manage to get it to work, but then realized I wanted to run the script both from the CLI and before tests, including re-running migrations and eventually seeds, so I examined the source of Migrate and camp up with this simple routine: var migrate = knex.migrate;
// Force unlock in case of bad state
migrate.forceFreeMigrationsLock()
// Get completed migrations
.then(function(){
return migrate._listCompleted();
})
// Rollback migrations
.then(function(completedMigrations){
return migrate._waterfallBatch(0, completedMigrations.reverse(), 'down');
})
// Migrate to latest
.then(function(){
return migrate.latest();
}); It should be fairly simple to turn that into a |
That's an improvement over what I do to clean before my tests, which is just knex.migrate.rollback(dbConf).then ->
console.log('rolled back database')
knex.migrate.latest(dbConf).then ->
console.log('migrated database')
done() @bendrucker would justincy's code be accepted in a pull request? |
I updated the code example to add |
I wrote knex-migrate that has this feature (named |
I used this code to solve this problem:
It doesn't use internal methods and allows you to pass in config. |
It looks like this got added and the issue can be closed: #3187 Pinging @kibertoad, since you merged that PR and probably have the permissions to do this |
@mmarvick Thanks for the heads-up! |
I frequently change my migrations in my application since it has no production data to maintain yet. I'd like to be able to quickly reset it(rollback all and then migrate latest) instead of running rollback until all of the migrations have rolled back to the base migration, then running migrate latest.
The text was updated successfully, but these errors were encountered: