Skip to content

Commit ec79880

Browse files
author
“Will
committed
Compute AddUniqueIndex order from identity keys
1 parent 48c2be5 commit ec79880

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/migration_generator/migration_generator.ex

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2333,11 +2333,22 @@ defmodule AshPostgres.MigrationGenerator do
23332333
end)
23342334
end
23352335
|> Enum.map(fn identity ->
2336+
orders =
2337+
identity.keys
2338+
|> Enum.map(&Enum.find_index(snapshot.attributes, fn attr -> attr.source == &1 end))
2339+
|> Enum.reject(&is_nil/1)
2340+
2341+
insert_after_attribute_order =
2342+
case orders do
2343+
[] -> nil
2344+
_ -> Enum.max(orders)
2345+
end
2346+
23362347
%Operation.AddUniqueIndex{
23372348
identity: identity,
23382349
schema: snapshot.schema,
23392350
table: snapshot.table,
2340-
insert_after_attribute_order: max(0, length(snapshot.attributes) - 1),
2351+
insert_after_attribute_order: insert_after_attribute_order,
23412352
concurrently: opts.concurrent_indexes
23422353
}
23432354
end)

0 commit comments

Comments
 (0)