Skip to content

issue #611 solution#692

Open
WillG2001 wants to merge 2 commits intoash-project:mainfrom
WillG2001:main
Open

issue #611 solution#692
WillG2001 wants to merge 2 commits intoash-project:mainfrom
WillG2001:main

Conversation

@WillG2001
Copy link

@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
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.



* fix for atomic create support
* avoid dropping and re-adding foreign key when only reference index changes (#611)
Copy link
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 🥳

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