So one option as you suggest Carl, is to pass a hard coded string into the 
Operation when it's instantiated in the user's migration file. I've taken a 
similar approach, starting one level lower, injecting the migration name 
into database_forwards methods. 
https://github.com/tomviner/django/compare/ticket_23577_with_poc_migration_name_fix

This then passing into schema_editor public method calls (create_model, 
add_field and alter_field, which all need their signatures changed over 
BaseDatabaseSchemaEditor and all the database specific schema editor 
backends). Then the migration name is passed through internal schema editor 
methods like _alter_field, _create_unique_sql, _create_index_sql, 
_create_fk_sql and finally on to _create_index_name.

See how the tests have to pass in extra_index_suffix='schema_test.000x' as 
they don't go through an actual migration file.

To sum up this solution: it's not localised and it's not pretty. I'm sure 
it could be tidied up a little, but unless it can be collapsed to a much 
smaller patch, I'd say having deterministic index names isn't worth the 
impact.


Instead, I propose the following solution: a random string injected into 
the formation of all index names. A much more localised patch: 
https://github.com/tomviner/django/compare/ticket_23577_with_poc_random_string_fix

So final call for examples where having predictable index names matter!

One thing I'm still looking at, regardless of the solution chosen, is 
whether we need to include spatial indexes too.

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/96b5254c-ce27-481e-9087-d655cedf3a02%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to