Repository navigation
Conversation
…rerun migrations With paranoid set through the Sequelize define defaults, destroy only set deletedAt, so a reverted migration could not be logged again because of the primary key on its name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #706
I started from #706 and checked it against the code.
SequelizeStorage.getModel()defines the meta model withsequelize.define(...), so it picks up the Sequelize instance'sdefinedefaults. When those includeparanoid: trueand the storage hastimestamps: true, as in the report, the meta model is paranoid.unlogMigrationthen callsmodel.destroy({where: ...}), which only setsdeletedAt.executed()no longer lists the migration, so umzug treats it as pending, but its row is still in the table. Running it up again inserts the same name, and the primary key on the name column rejects it withSequelizeUniqueConstraintError: Validation error.The change passes
force: truetodestroyinunlogMigration, so the row is always removed. For a model that isn't paranoid,forcechanges nothing. It also covers a paranoid model passed in through themodeloption.Rows that were soft-deleted before this change stay in the table, so a migration that was already reverted this way still needs its row removed by hand before it can run again.
How I found it: I followed
unlogMigrationandexecutedinsrc/storage/sequelize.tsand checked which optionsgetModel()passes todefine. It setstimestampsbut notparanoid, so the instance default decides it.Where this can show up in practice: projects that turn on
paranoidfor all their models through the Sequelizedefineoption and enabletimestampson the umzug storage. Every migration they revert then can't be run again, which breaks the usual edit, revert and rerun loop while writing a migration, and also runningupagain after a rollback in a deployment. This is my estimate beyond the report in #706.Testing:
test/storage/sequelize.test.ts: withdefine: {paranoid: true}andtimestamps: true, it logs a migration, unlogs it, checks that no row is left (counting soft-deleted rows too), logs it again and checksexecuted(). Without the change it fails on the row count, and without that assertion it fails withSequelizeUniqueConstraintError: Validation error, as in the issue.pnpm test(107 tests) andpnpm lintpass on macOS arm64 with Node 24.14.1 and SQLite.