mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 13:33:50 +12:00
fix: use attribute source for identity fields
This commit is contained in:
parent
b2e3c3ff32
commit
94edf64322
2 changed files with 16 additions and 0 deletions
|
@ -2145,6 +2145,16 @@ defmodule AshPostgres.MigrationGenerator do
|
|||
end)
|
||||
|> Enum.sort_by(& &1.name)
|
||||
|> Enum.map(&Map.take(&1, [:name, :keys]))
|
||||
|> Enum.map(fn %{keys: keys} = identity ->
|
||||
%{
|
||||
identity
|
||||
| keys:
|
||||
Enum.map(keys, fn key ->
|
||||
attribute = Ash.Resource.Info.attribute(resource, key)
|
||||
attribute.source || attribute.name
|
||||
end)
|
||||
}
|
||||
end)
|
||||
|> Enum.map(fn identity ->
|
||||
Map.put(
|
||||
identity,
|
||||
|
|
|
@ -75,12 +75,14 @@ defmodule AshPostgres.MigrationGeneratorTest do
|
|||
identities do
|
||||
identity(:title, [:title])
|
||||
identity(:thing, [:title, :second_title])
|
||||
identity(:thing_with_source, [:title, :title_with_source])
|
||||
end
|
||||
|
||||
attributes do
|
||||
uuid_primary_key(:id)
|
||||
attribute(:title, :string)
|
||||
attribute(:second_title, :string)
|
||||
attribute(:title_with_source, :string, source: :t_w_s)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -132,6 +134,10 @@ defmodule AshPostgres.MigrationGeneratorTest do
|
|||
# the migration creates unique_indexes based on the identities of the resource
|
||||
assert file_contents =~
|
||||
~S{create unique_index(:posts, [:title, :second_title], name: "posts_thing_index")}
|
||||
|
||||
# the migration creates unique_indexes using the `source` on the attributes of the identity on the resource
|
||||
assert file_contents =~
|
||||
~S{create unique_index(:posts, [:title, :t_w_s], name: "posts_thing_with_source_index")}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue