Repository navigation
feat: fix multiple bugs related to sync() and indexes. Add Model.getIndexes() - #14619
Conversation
sync() and indexes in db2sync() and indexes in db2, mssql, sqlite
This comment was marked as outdated.
This comment was marked as outdated.
sync() and indexes in db2, mssql, sqlitesync() and indexes
sync() and indexessync() and indexes. Add Model.getIndexes()
|
You're going to laugh. I've deadlocked my PRs. One of the tests is failing because DB2 is recreating the table instead of altering it. This isn't a regression, so I'm requesting to force-merge this PR, and continue over at #14572 |
|
Can we temporarily disable the failing unit tests so only DB2 checks fail for this PR and re-enable them in the other PR? Not a fan of force merging Will review tomorrow |
I fixed them, these weren't supposed to fail. Edit: looks like all remaining tests are flaky. I guess we're good to go |
sdepold
left a comment
There was a problem hiding this comment.
I'm always surprised by how much you know about the library and in which corners you can stir :)
|
Let me handle the merging of this PR, I'll add a detailed message for the changelog |
|
🎉 This PR is included in version 7.0.0-alpha.14 🎉 The release is available on: Your semantic-release bot 📦🚀 |
…dexes Db2 makes the columns of single-column indexes unique when creating a table, so it skips the named indexes of those columns as duplicates of its own unique indexes. Changing that in v6 would be a breaking change (v7 did it in #14619), so assert the current behaviour instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pull Request Checklist
yarn testoryarn test-DIALECTpass with this change (including linting)?Description Of Change
Closes #12889
This PR fixes the following bugs:
indexesoption on a model, then callingsync(), the dialect would modify the model to mark all attributes that are part of the index as unique. (DB2 only)sync({ alter: true })with an attribute that hasunique: trueset would generate a query such asALTER TABLE users ALTER COLUMN emails SET VARCHAR UNIQUE. DB2 and MSSQL do not allowUNIQUEto be specified there. This has been changed to use a separateCREATE INDEXquery.CREATE TABLE, but that name is ignored by sqlite. Causing subsequentsync()to try to recreate the index. The firstsyncdoes not try to create the index as part ofCREATE TABLEanymore, but executesCREATE INDEXafterwards to create them (sqlite only, other dialects still do it duringCREATE TABLE).Model.getIndexes()which lists all indexes defined on the model (it regroups all indexes, the ones defined throughModelOptions.indexes, as well as the ones coming fromModelAttributeColumnOptions.unique)This PR blocks #14572 (comment)
TODO
sync(alter)tests for adding unique constraints after the firstsync()