Skip to content

Maintain index options during change_column operations#1345

Merged
aidanharan merged 4 commits into
rails-sqlserver:mainfrom
b-nik:main
Jun 23, 2025
Merged

Maintain index options during change_column operations#1345
aidanharan merged 4 commits into
rails-sqlserver:mainfrom
b-nik:main

Conversation

@b-nik

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

Copy link
Copy Markdown
Contributor

Maintain index options during change_column operations.

Fixes #1344

@aidanharan

Copy link
Copy Markdown
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

b-nik commented Jun 20, 2025

Copy link
Copy Markdown
Contributor Author

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

b-nik commented Jun 22, 2025

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
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
Copy Markdown
Contributor

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

@b-nik

b-nik commented Jun 23, 2025

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
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