Add feature to undo "grouped" migrations (applied with the same command) with only one command

Open
#1,264 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, node.js
Domain
cli, database

Research direction

Start by tracing the Sequelize CLI migrate and undo commands and how the sequelizemeta table records applied migrations. Define the behavior for grouping migrations from one command, including rollback order and metadata handling; done means a command can undo exactly the latest migration group. No files or tests are named, so repository exploration is required.

Written by the indexing model from the issue text.

Description

Hello,
I am self-taught in DataBase management and usage. First I was using no tools to interface my program to the DB. I was writing all manualy. Next I have used the interface of Laravel in PHP ("Eloquent"). Now, I use Sequelize in my NodeJS project.

I have not found any information about my followinf suggestion but if it's already addressed, please just tell me.

I suggest to add a feature for migration to the sequelize CLI and maybe also to ohter sequelize parts (I don't knw how you are managing migration).
I suggest to add the possibility to undo all migration that are apply by the same command (like in Laravel Eloquent).

For exemple, If there are 5 migration applied and 3 pending migration. When you execute the migrate command, Sequelize will migrate the 3 pending migration. If you want to revert it, you have to undo 3 time or precize the migration name. I propose to add a command (maybe "db:migrate:undo:group") to automaticaly revert migrations that was applied by the same migrate command.

This is very usefull for production usage. When customer deploy an application, he as to migrate a first time, OK all migrations are applied. Next, I send an application update, the customer migrate simply migrate again and all new migration are applied. Now if the customer need to comeback to the previous version, he as to undo migration so, actually, he need to check name of last migration of the previous version. With my proposition, customer simply undo the last "group" (same time migration) and the app revert the the previous version because all migrations of the new version was applied by the same command.

To do it, I suggest to add a boolean column to the "sequelizemeta" table named "grouped". Migration row is set to false for first applied migration done by a migrate command and all next migrations applied by this same command is set to true because they are "grouped" with precedent. So at eatch execution of the migration command, a row and only one is set to false. The "undo:group" command has just to undo last migration and check if this unded migration was set to true. If yes, automatically undo the previous migration and so one while "grouped" field is true.

I can develop more or explain differently but I realy think that it can be a very good addition for production and most generaly to don't care of migration name while migrate or revert between program version.

Best Regards,

Dominant language
JavaScript
Stars
2.6k
Forks
524
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sequelize/cli

All issues in sequelize/cli

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.