Require ChangeMetas for existing models containing unique_together.

Review Request #5109 — Created Dec. 13, 2013 and submitted

Information

Django Evolution
master

Reviewers

Require ChangeMetas for existing models containing unique_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 a ChangeMeta 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 using evolve --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 every unique_together we had. Ran evolve --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 ran syncdb, followed by
evolve and evolve --hint. It didn't complain about missing evolutions. Verified
the new unique_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 doing evolve --hint --execute.

david
  1. I understand this least of all your evolution changes so far.

    1. Yeahhh it's fun stuff. I can go over it if you want to learn how all this works better.

    2. AHAHAHAHAHAHAHAHAHAHA that's funny.

    3. :(

  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Loading...