Skip to content

Instantly share code, notes, and snippets.

@ola-dola
Last active July 2, 2020 21:42
Show Gist options
  • Save ola-dola/32bc82f591cf49acbb866d2ed2e077cc to your computer and use it in GitHub Desktop.
Save ola-dola/32bc82f591cf49acbb866d2ed2e077cc to your computer and use it in GitHub Desktop.

What is the difference between knex migrate:rollback and knex migrate:down?

When you run knex migrations to add/modify table(s) with knex(using knex migrate:latest), it runs as a batch if there's more than one file in the migrations directory, and more than one uncompleted migration files.

migrate:rollback rollback(undo) the last batch job(--all flag to rollback all batches)

migrate:down rollback the last migration(a single file) in the last batch.

For example, if we have abc.js, def.js and ghi.js uncompleted migration files in the migrations directory. knex migrate:latest runs all 3 in a single batch. migrate:rollback undo the last batch job(all 3 files) while knex migrate:down undo ghi.js as the last file in the batch. Another knex migrate:down undo def.js and so on.

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