sequelize-mig icon indicating copy to clipboard operation
sequelize-mig copied to clipboard

Migration Reversion Breaks with Foreign Keys

Open dakotacookenmaster opened this issue 3 years ago • 0 comments

Creating and running the migrations from models works like a charm (thank you!), but the migration reversion is broken when foreign key constraints apply. The generated actions summary shows that the first tables created are ones with no dependencies, and the ones created following that use those as dependencies (this makes sense).

Here's an example structure:

image

However, it appears that the order in which tables are dropped does not match this. Instead, it goes alphabetically (either implicitly, because of how files are sorted in the file system, or explicitly).

Here's a small example of the rollbackCommands applied to:

image

For migration reversion to work appropriately, first the tables with dependencies must be dropped. If reversion happens in the reverse order they were created, this problem would be solved.

dakotacookenmaster avatar Jun 24 '21 14:06 dakotacookenmaster