mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 13:33:50 +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)
|
option(:prefix, schema)
|
||||||
])
|
])
|
||||||
|
|
||||||
if opts == "",
|
if opts == "" do
|
||||||
do: "create index(:#{as_atom(table)}, [#{Enum.map_join(keys, ", ", &inspect/1)}])",
|
"create index(:#{as_atom(table)}, [#{Enum.map_join(keys, ", ", &inspect/1)}])"
|
||||||
else:
|
else
|
||||||
"create index(:#{as_atom(table)}, [#{Enum.map_join(keys, ", ", &inspect/1)}], #{opts})"
|
"create index(:#{as_atom(table)}, [#{Enum.map_join(keys, ", ", &inspect/1)}], #{opts})"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def down(%{schema: schema, index: index, table: table, multitenancy: multitenancy}) do
|
def down(%{schema: schema, index: index, table: table, multitenancy: multitenancy}) do
|
||||||
index_name = AshPostgres.CustomIndex.name(table, index)
|
|
||||||
|
|
||||||
keys =
|
keys =
|
||||||
if !index.all_tenants? and multitenancy.strategy == :attribute do
|
if !index.all_tenants? and multitenancy.strategy == :attribute do
|
||||||
[multitenancy.attribute | index.fields]
|
[multitenancy.attribute | index.fields]
|
||||||
|
@ -928,7 +927,17 @@ defmodule AshPostgres.MigrationGenerator.Operation do
|
||||||
index.fields
|
index.fields
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue