Opened 4 years ago

Last modified 4 months ago

#27060 assigned New feature

Take indexes into account in inspectdb command

Reported by: Akshesh Doshi Owned by: Drew Winstel
Component: Core (Management commands) Version: master
Severity: Normal Keywords: db-indexes inspectdb
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Currently, inspectdb command takes into account existing tables (via models.Model), columns (via models.Field) and unique constraints (via unique_together) while inspecting the db. It would be helpful to take into account the existing indexes (via models.Index) on the table as well.

Change History (12)

comment:1 Changed 4 years ago by Akshesh Doshi

Owner: changed from nobody to Akshesh Doshi
Status: newassigned

I have an almost ready patch for this feature.

comment:2 Changed 4 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted

comment:3 Changed 4 years ago by Akshesh Doshi

Has patch: set

comment:4 Changed 4 years ago by Tim Graham

Patch needs improvement: set

The complication is that models.Index might not match the type of the index. As noted on the PR, I'd think we'd at least want to add a comment in the output if the type of the introspected index doesn't match.

comment:5 Changed 4 years ago by Akshesh Doshi

Keywords: inspectdb added
Patch needs improvement: unset

comment:6 Changed 4 years ago by Tim Graham

Patch needs improvement: set

comment:7 Changed 4 years ago by Claude Paroz

Another question is about index_together vs models.Index. Are we going to keep both way of defining multicolumn indexes? Should one be privileged over the other? Depending on the answer, the patch might have to be adapted.

comment:8 Changed 4 years ago by Akshesh Doshi

Some steps have been taken to deprecate index_together, see - https://code.djangoproject.com/ticket/27064
I created a ticket to track deprecation of index_together here - https://code.djangoproject.com/ticket/27236

comment:9 Changed 4 years ago by Akshesh Doshi

Owner: Akshesh Doshi deleted
Status: assignednew

comment:10 Changed 10 months ago by Pavel White

Owner: set to Pavel White
Patch needs improvement: unset
Status: newassigned

PR: https://github.com/django/django/pull/11944

This PR:

  • [x] Add db_index field param

Next PR:

  • [ ] Add Meta.indexes support

comment:11 Changed 9 months ago by felixxm

Patch needs improvement: set

This ticket is about adding support for Meta.indexes to the inspectdb not about the db_index option. Mainly because it can be hard to ensure that an inspected index is exactly the same as an index created by Django (type, ordering, operator classes, fillfactor etc.). That's why we accepted a ticket to support Meta.indexes where these options may be included.

comment:12 Changed 4 months ago by felixxm

Owner: changed from Pavel White to Drew Winstel
Note: See TracTickets for help on using tickets.
Back to Top