Skip to content
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

polymorphic_on_delete option results in never-ending migration cycle #190

Closed
mindok opened this issue Jan 8, 2024 · 2 comments
Closed
Labels
bug Something isn't working needs review

Comments

@mindok
Copy link

mindok commented Jan 8, 2024

Describe the bug
When using the polymorphic_on_delete option as described in #189, the snapshots are generated with the name of the reference set to :delete (the option set for polymorphic_on_delete). It appears that using an atom for the reference name results in a string <> atom comparison at some point and a new migration is generated for the relationship each time the generate_migrations mix task is run.

Using :delete for the name also has the potential to create multiple constraints with the same name for a single table which is going to cause other dramas...

The up migration drops the constraint named "delete" and creates a new, identical one named :delete.
The down migration does the reverse.

For example:

  def up do
    drop constraint(:event_locations, "delete")

    alter table(:event_locations) do
      modify :resource_id,
             references(:events,
               column: :id,
               name: :delete,
               type: :uuid,
               on_delete: :delete_all
             )
    end
  end

...

  def down do
    drop constraint(:event_locations, :delete)

    alter table(:event_locations) do
      modify :resource_id,
             references(: events,
               column: :id,
               name: "delete",
               type: :uuid,
               on_delete: :delete_all
             )
    end
  end

I suspect AshPostgres.DataLayer.Info.polymorphic_name/1 is at fault - it returns the setting rather than a name. The call to it in AshPostgres.MigrationGenerator.get_snapshots/2 can probably just be removed until #189 is done.

To Reproduce
As per #189, but generate migrations.

Expected behavior
Once the migration has been generated, ash_postgres.generate_migrations --check should give the all clear.

@mindok mindok added bug Something isn't working needs review labels Jan 8, 2024
@mindok
Copy link
Author

mindok commented Jan 8, 2024

I'll have a crack at this to warm up for the other 😄

@zachdaniel
Copy link
Contributor

Fixed in a60dbf1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants