Skip to content

issue #611 solution#692

Merged
zachdaniel merged 7 commits intoash-project:mainfrom
WillG2001:main
Feb 20, 2026
Merged

issue #611 solution#692
zachdaniel merged 7 commits intoash-project:mainfrom
WillG2001:main

Conversation

@WillG2001
Copy link
Copy Markdown
Contributor

@WillG2001 WillG2001 commented Feb 11, 2026

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

@WillG2001
Copy link
Copy Markdown
Contributor Author

Description

Fixes #611

When changing only the index? setting on a reference (e.g., from index?: true to index?: false), the migration generator was emitting unnecessary operations that dropped and re-added the same foreign key. The migration should only create or drop the index, not touch the foreign key.

Changes

  • Added references_differ_beyond_index?/2 helper to detect when reference configurations differ only in the index? setting
  • Updated alter_attribute_events to skip FK drop/alter operations when only index? differs
  • Fixed RemoveReferenceIndex to properly pass old_multitenancy for correct index generation
  • Added test case to verify index-only changes don't emit FK operations

How to test

  1. Create a resource with a reference that has index?: true:
   postgres do
     references do
       reference(:post, index?: true)
     end
   end
  1. Run mix ash_postgres.generate_migrations to create the initial migration (should include FK and index creation)

  2. Change the reference to index?: false:

   postgres do
     references do
       reference(:post, index?: false)
     end
   end
  1. Run mix ash_postgres.generate_migrations again

  2. Verify the new migration:

  • Contains drop_if_exists index(:table_name, [:reference_column])
  • Does NOT contain drop constraint(:table_name, "..._fkey")
  • Does NOT contain modify :reference_column, references(...)

The test case "changing only reference index? does not drop and re-add foreign key (issue #611)" in test/migration_generator_test.exs verifies this behavior.

CHANGELOG.md Outdated


* fix for atomic create support
* avoid dropping and re-adding foreign key when only reference index changes (#611)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog is automatically managed. Please remove this and I'll merge 🥳

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sounds good! I wasn't sure about the changelog anyway, but that's good to know going forward. I will fix that!

@zachdaniel
Copy link
Copy Markdown
Contributor

@WillG2001 we've updated the way we test the migration generator, mind updating your tests to match and handling the merge conflicts?

🙇

@WillG2001
Copy link
Copy Markdown
Contributor Author

Sorry for the extra PR earlier. I'm new to this process and wasn't sure how to update my existing PR. I think I've made the changes needed for the updated tests, but please let me know if I missed something!

@zachdaniel
Copy link
Copy Markdown
Contributor

No problem at all ❤️

@zachdaniel zachdaniel merged commit a36561a into ash-project:main Feb 20, 2026
64 of 67 checks passed
@zachdaniel
Copy link
Copy Markdown
Contributor

🚀 Thank you for your contribution! 🚀

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants