fix(migrations): emit Meta.constraints in CREATE TABLE (#2272) - #2275
Open
jagadeepmamidi wants to merge 1 commit into
Open
fix(migrations): emit Meta.constraints in CREATE TABLE (#2272)#2275jagadeepmamidi wants to merge 1 commit into
jagadeepmamidi wants to merge 1 commit into
Conversation
Named UniqueConstraint and CheckConstraint were stored on CreateModel but never applied when creating tables, and MySQL add_constraint ignored custom names.
|
Great efficient work 🏅 |
Author
|
@seejah please let me know if I can check any other issues too (happy to help) |
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.
Named UniqueConstraint and CheckConstraint were stored on CreateModel but never applied when creating tables, and MySQL add_constraint ignored custom names.
Description
Meta.constraints(UniqueConstraint/CheckConstraint) are now emitted inCREATE TABLEfor bothtortoise migrateandgenerate_schemas.Previously
makemigrationsstored them onCreateModel, but table creation only appliedunique_together, so a new model never gotAddConstraintand named uniques likeunique_likenever appeared. MySQLadd_constraintalso ignorednameand generateduidx_*instead.CREATE TABLEcondition) becomeCREATE UNIQUE INDEX ... WHEREon PostgreSQLUniqueConstraintwhose resolved columns already matchunique_togetheris skippedadd_constrainthonorsconstraint.namewhen setMotivation and Context
Fixes #2272
Reporter used
tortoise makemigrations/tortoise migrateon MySQL 8.4 with:Expected a unique index named
unique_like; nothing was created, with no error.How Has This Been Tested?
Added regression tests in
tests/migrations/test_schema_editor_sql.pyandtests/migrations/test_schema_editor_constraints.pycovering:CreateModelSQL for named unique + check constraints (ANSI and MySQL)UniqueConstraintduplicatesunique_together(including FK field vsorganization_idcolumns)generate_schemasincludingMeta.constraintsadd_constraintusing the custom nameRan:
(52 passed)
Checklist: