Require ChangeMetas for existing models containing unique_together.
Review Request #5109 — Created Dec. 13, 2013 and submitted — Latest diff uploaded
Require
ChangeMetas
for existing models containingunique_together
.Django Evolution previously stored but otherwise ignored
unique_together
entries, meaning that older values could not be trusted to have been
applied to the database It could be wildly inconsistent with what's
actually there.This change considers an older
unique_together
to be invalidated,
requiring aChangeMeta
mutation, if from Django Evolution 0.6.x or
older.There's a new flag stored in the signature for each table called
__unique_together_applied
. This is used to indicate whether the
field has been applied to the database (or, in the case of an empty
unique_together
, at least considered).When diffing, two identical
unique_together
values are considered
to be unequal if the older signature doesn't have this new flag.Projects with existing
unique_together
values will need to provide
a ChangeMeta for each table. Samples are shown when usingevolve --hint
.This also provides some built-in evolutions for the main affected Django
models.
Unit tests pass for SQLite3, MySQL and PostgreSQL for Django 1.3, 1.4 and 1.5.
Tested against Review Board without any
ChangeMeta
evolutions. It told
me I needed an evolution for everyunique_together
we had. Ranevolve --hint
and saw the suggestions for each.I then added evolutions for all of these and ran
evolve
. It said the evolutions
looked good and would apply cleanly.Ran
evolve --execute
and it applied all my evolutions. Checked in the database
to be sure they were there.None of the existing indexes were removed or replaced.
Created a brand new model with a
unique_together
and ransyncdb
, followed by
evolve
andevolve --hint
. It didn't complain about missing evolutions. Verified
the newunique_together
was in the database (that part is Django's job) and
that the correct flag was in the signature.Made a change to that
unique_together
and saw that it properly told me I needed
a mutation, which applied successfully when doingevolve --hint --execute
.