2
votes

I re-created my database on one of my dev environment and now when I run the migration via sequelize db:migrate, it tries to run the migrations from the first.

I don't want to re-sync/re-create the database since running migrations on the dev environment ensures that the migrations are correctly written.

Is there a way to force-mark some migrations as 'done'?

2

2 Answers

8
votes

Sequelize-cli stores the migration data on a table called SequelizeMeta.

You can copy the migration filename from your existing DB and insert into the above mentioned table in new environment's DB. All the migrations recorded would be considered as they have already ran.

Though this would stop selected migrations from running, it's not the best approach to be taken.

This metadata could also be stored in a json, though I am not very aware of the structure for it.

You can dig through the docs here

1
votes

The actual way of doing is as follow,

There are two tables sequelizemeta and SequelizeMeta(Hidden)

And for skip or say migration already ran is enter value in both table like

INSERT INTO sequelizemeta (name) VALUES 
('20181019072815-roles.js'),
('20181019093229-users.js')

INSERT INTO SequelizeMeta (name) VALUES 
('20181019072815-roles.js'),
('20181019093229-users.js')

Note- SequelizeMeta is hidden table but we can query it.

SELECT * from seerportal.SequelizeMeta