Opened 8 years ago
Closed 2 years ago
#27064 closed New feature (fixed)
Implement RenameIndex in a backwards compatible way
Reported by: | Markus Holtermann | Owned by: | David Wobrock |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Andrew Godwin, Akshesh Doshi, Adam Johnson, Ravi Teja P, David Wobrock | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In order to eventually deprecate index_together
we need a way to deal with old projects that have unnamed indexes. This proves to be a non-trivial problem. Andrew and I came up with these things to consider.
RenameIndex(model, new_name, old_name=None, old_fields=None)
where exactly one ofold_name
andold_field
is given (old_name ^ old_fields
)- If the old_name is given we use
RENAME INDEX
if available - Otherwise look at the state and drop existing indexes and create new the index with new name
- On MySQL (or other DBs) that don't support
RENAME INDEX
, provide SQL query to look up index name from information_schema by field names and pass in toDROP INDEX
. - If more than one index is found while identifying with field names, migrations must error out with an
AmbiguityError
- If the autodetector finds an old, unnamed index and a new, named one matching field signature, issue a
RenameIndex
operation - For backwards operations with unnamed old indexes,
RenameIndex
is a noop.
Change History (24)
comment:1 by , 8 years ago
Type: | Uncategorized → New feature |
---|
comment:2 by , 8 years ago
Cc: | added |
---|
comment:3 by , 8 years ago
Cc: | added; removed |
---|
comment:4 by , 8 years ago
comment:5 by , 8 years ago
I just noticed that I actually never commented here. So, the reason is explained here: https://code.djangoproject.com/ticket/27236#comment:9
comment:6 by , 5 years ago
On MySQL (or other DBs) that don't support RENAME INDEX, provide SQL query to look up index name from information_schema by field names and pass in to DROP INDEX.
RENAME INDEX
is now supported on MySQL 5.7+ and MariaDB 10.5.2+.
comment:7 by , 5 years ago
Cc: | added |
---|
comment:8 by , 4 years ago
Cc: | added |
---|
comment:9 by , 3 years ago
Cc: | added |
---|---|
Has patch: | set |
Needs documentation: | unset |
Needs tests: | unset |
Owner: | changed from | to
Status: | new → assigned |
Hi there,
I tried to tackle this change in this PR.
Feel free to review it!
And maybe we'll be able to deprecate index_together
in a next major release, as we wanted to do here https://code.djangoproject.com/ticket/27236 a few years back :)
comment:10 by , 2 years ago
Patch needs improvement: | set |
---|
comment:11 by , 2 years ago
Patch needs improvement: | unset |
---|
Integrated the review comments and split the PR into 2 parts:
- Adding the RenameIndex operation https://github.com/django/django/pull/15677
- Using the RenameIndex in the autodetector https://github.com/django/django/pull/15651
comment:12 by , 2 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
comment:13 by , 2 years ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
Integrated review changes into the first PR implementing RenameIndex operation.
comment:14 by , 2 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:16 by , 2 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
comment:17 by , 2 years ago
Patch needs improvement: | unset |
---|
Rebased PR, ready for some review again :)
Even if it (most probably) won't be included to the coming 4.1 release.
comment:19 by , 2 years ago
Patch needs improvement: | unset |
---|
comment:21 by , 2 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:24 by , 2 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Triage Stage: | Ready for checkin → Accepted |
Is there a reason why we cannot just simply deprecate
index_together
.My understanding is that the models file of the app will get modified from this
to this
and everything should work fine (or not? Am I missing something?)
I need some help to see where
RenameIndex
comes into picture here.