New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some indexes dropped in migration are not recreated #14
Comments
Issue acknowledged. We will review it and propose a better solution in the future. |
Issue #14 This change cause 'migrations.test_operations.OperationTests.test_rename_model_with_m2m' to fail, so skipped for now, it'll be fixed in the future.
The issue has been fixed in the latest release. Feel free to reopen if there is any other concern. |
Many thanks @absci It's a slight tangent from the original issue here, so if it's valid perhaps deserves a new issue, but I'm slightly confused by this change which adds an index creation to
|
|
Awesome, thank you! The tests for the original problem in this issue are now rebased and ✔ and ready to merge if you're happy: #49 |
TDD: tests for index reinstatement issue #14
Merged, thanks for your contribution. |
Problem
In the following cases (possibly more) any indexes on the column are dropped, but aren't recreated afterwards:
(a) when a column is made null-able (i.e. adding
null=True
)(b) when a column is renamed
(c) when a table is renamed
This is quite a major issue because it is silently leaving the database in the wrong state - the migration doesn't fail, but now certain columns with
db_index=True
won't actually have an index which could cause very slow queries.Cause
As far as I can see this is a triple-regression introduced (before this fork was created) by 2e60754 (ESSolutions/django-mssql-backend#24).
That commit added new calls to
_delete_indexes
in 2 places within_alter_field
causing the first two cases listed above:and added an explicit index deletion here in
alter_db_table
before renaming a table causing the third case:but in none of those cases is the index re-instated afterwards, even if the field still has
db_index=True
. Index restoration only happens in certain specific cases (e.g. type change / removal of nullability) which doesn't include the above 3 cases.Reproduction
I've added 3 tests in #49 which fail due to the bugs described above, but pass if run on older versions like
django-mssql-backend
v2.4.2 (before ESSolutions/django-mssql-backend#24 was merged).History
I previously filed this on the project from which this was forked ESSolutions/django-mssql-backend#58 - given there was no feedback to my proposed solution there, I hope it's ok to file an equivalent issue here. Hopefully this more official project might be able to provide some insight. This was my comment (the only one on that issue) re possible fixes:
The text was updated successfully, but these errors were encountered: