Skip to content

Maintain index options during change_column operations #1345

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

Merged
merged 4 commits into from
Jun 23, 2025

Conversation

b-nik
Copy link
Contributor

@b-nik b-nik commented Jun 20, 2025

Maintain index options during change_column operations.

Fixes #1344

@aidanharan
Copy link
Contributor

@b-nik Thanks for the PR. I assume it is to fix #1344 Could you add some tests to confirm it fixes the issue? Thanks

@b-nik
Copy link
Contributor Author

b-nik commented Jun 20, 2025

No problem, I'll have to check how to run tests for this, and how to write appropriate tests to actually test this case (I'm not too well versed in the rails adapter internals) when I have more time, and I'll get back to you.

Btw I manually tested this on a Rails 8.0 app so hopefully this fix can be backported on 8.0 as well and not just for 8.1.

@b-nik
Copy link
Contributor Author

b-nik commented Jun 22, 2025

@aidanharan Trying to run the tests I noticed that the main branch is using an activerecord version ( 8.1.0alpha ) that doesn't seem to exist? Am I missing something?

@aidanharan
Copy link
Contributor

@aidanharan Trying to run the tests I noticed that the main branch is using an activerecord version ( 8.1.0alpha ) that doesn't seem to exist? Am I missing something?

You need to run the tests against the Rails main branch. This can be done using:

RAILS_BRANCH=main bundle install
RAILS_BRANCH=main bundle exec rake test

@aidanharan aidanharan changed the title Fix change_column re-adding indexes without their options (#1344) Maintain index options during change_column operations Jun 23, 2025
@aidanharan
Copy link
Contributor

@b-nik I added a test to the PR. Could you review it please?

@b-nik
Copy link
Contributor Author

b-nik commented Jun 23, 2025

@aidanharan Looks good - I added an extra test case with multiple indexes and index options to check they are all retained.

@aidanharan aidanharan merged commit 6b5ae0f into rails-sqlserver:main Jun 23, 2025
5 checks passed
@aidanharan
Copy link
Contributor

@b-nik I have back-ported the fix to the 8-0-stable branch. Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Indexes lose uniqueness constraint when change_column is executed
3 participants