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

Changing identities leads to generation of erroneous migrations #303

Closed
spacebat opened this issue May 26, 2024 · 1 comment
Closed

Changing identities leads to generation of erroneous migrations #303

spacebat opened this issue May 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@spacebat
Copy link

Describe the bug
Attempting to use the latest Ash 3.0.7 support for where clauses in identities:

# in the identities block
identity :name, [:name] do
  nils_distinct? false
  where expr(is_nil(archived_at))
end

# and in the postgres block
identity_wheres_to_sql name: "archived_at is null"

The migration generated for this, when run throws this error:

** (Postgrex.Error) ERROR 42601 (syntax_error) syntax error at or near "NULLS"
    query: CREATE UNIQUE INDEX "pipeline_defns_name_index" ON "pipeline_defns" (name) NULLS NOT DISTINCT WHERE archived_at is null

Upon removing the nils_distinct? false line and regenerating the migration then running it gives:

** (Postgrex.Error) ERROR 42P07 (duplicate_table) relation "pipeline_defns_name_index" already exists

Indeed, the migration up function just does a create unique_index(...) and does not attempt to alter the index or delete and recreate it.

To Reproduce
See above for reproduction.

Expected behavior
The SQL for NULLS NOT DISTINCT should be correct, but postgresql doesn't like it.
The migration generated should alter or recreate the index, not attempt to create an already-extant index.

Runtime

  • Elixir version 1.16.2
  • Erlang version 26
  • OS Ubuntu 22.04
  • Ash version 3.0.7
  • any related extension versions
    Postgresql is version 14.11
@zachdaniel
Copy link
Contributor

Fixed in 9f1936a

@zachdaniel zachdaniel moved this from In Progress to Done in Ash Framework Roadmap May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

2 participants