mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +12:00
fix: generate correct custom index name in down migration function (#222)
This commit is contained in:
parent
313937db57
commit
0c3b4e5425
1 changed files with 16 additions and 7 deletions
|
@ -912,15 +912,14 @@ defmodule AshPostgres.MigrationGenerator.Operation do
|
|||
option(:prefix, schema)
|
||||
])
|
||||
|
||||
if opts == "",
|
||||
do: "create index(:#{as_atom(table)}, [#{Enum.map_join(keys, ", ", &inspect/1)}])",
|
||||
else:
|
||||
if opts == "" do
|
||||
"create index(:#{as_atom(table)}, [#{Enum.map_join(keys, ", ", &inspect/1)}])"
|
||||
else
|
||||
"create index(:#{as_atom(table)}, [#{Enum.map_join(keys, ", ", &inspect/1)}], #{opts})"
|
||||
end
|
||||
end
|
||||
|
||||
def down(%{schema: schema, index: index, table: table, multitenancy: multitenancy}) do
|
||||
index_name = AshPostgres.CustomIndex.name(table, index)
|
||||
|
||||
keys =
|
||||
if !index.all_tenants? and multitenancy.strategy == :attribute do
|
||||
[multitenancy.attribute | index.fields]
|
||||
|
@ -928,7 +927,17 @@ defmodule AshPostgres.MigrationGenerator.Operation do
|
|||
index.fields
|
||||
end
|
||||
|
||||
"drop_if_exists index(:#{as_atom(table)}, [#{Enum.map_join(keys, ", ", &inspect/1)}], #{join(["name: \"#{index_name}\"", option(:prefix, schema)])})"
|
||||
opts =
|
||||
join([
|
||||
option(:name, index.name),
|
||||
option(:prefix, schema)
|
||||
])
|
||||
|
||||
if opts == "" do
|
||||
"drop_if_exists index(:#{as_atom(table)}, [#{Enum.map_join(keys, ", ", &inspect/1)}])"
|
||||
else
|
||||
"drop_if_exists index(:#{as_atom(table)}, [#{Enum.map_join(keys, ", ", &inspect/1)}], #{opts})"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue