fix: fix migrator mix tasks w/ only/except tenants

fix: drop foreign keys after table create properly
This commit is contained in:
Zach Daniel 2021-07-08 13:35:16 -04:00
parent 7f5a56d9bd
commit ddbd43b611
3 changed files with 13 additions and 9 deletions

View file

@ -247,6 +247,9 @@ defmodule AshPostgres.MigrationGenerator do
defp comment_out_phases(phases) do
Enum.map(phases, fn
%{operations: []} = phase ->
phase
%{operations: operations} = phase ->
if Enum.all?(operations, &match?(%{commented?: true}, &1)) do
%{phase | commented?: true}
@ -961,15 +964,6 @@ defmodule AshPostgres.MigrationGenerator do
),
do: true
defp after?(
%Operation.CreateTable{table: table},
%Operation.DropForeignKey{
table: table,
direction: :down
}
),
do: true
defp after?(%Operation.AddAttribute{table: table}, %Operation.CreateTable{table: table}) do
true
end
@ -1235,6 +1229,12 @@ defmodule AshPostgres.MigrationGenerator do
old_attribute: Map.delete(attribute, :references),
new_attribute: attribute,
table: snapshot.table
},
%Operation.DropForeignKey{
attribute: attribute,
table: snapshot.table,
multitenancy: Map.get(attribute, :multitenancy),
direction: :down
}
]
else

View file

@ -119,6 +119,8 @@ defmodule Mix.Tasks.AshPostgres.Migrate do
|> AshPostgres.MixHelpers.delete_arg("--apis")
|> AshPostgres.MixHelpers.delete_arg("--migrations-path")
|> AshPostgres.MixHelpers.delete_flag("--tenants")
|> AshPostgres.MixHelpers.delete_flag("--only-tenants")
|> AshPostgres.MixHelpers.delete_flag("--except-tenants")
if opts[:tenants] do
for repo <- repos do

View file

@ -78,6 +78,8 @@ defmodule Mix.Tasks.AshPostgres.Rollback do
|> AshPostgres.MixHelpers.delete_arg("--apis")
|> AshPostgres.MixHelpers.delete_arg("--migrations-path")
|> AshPostgres.MixHelpers.delete_flag("--tenants")
|> AshPostgres.MixHelpers.delete_flag("--only-tenants")
|> AshPostgres.MixHelpers.delete_flag("--except-tenants")
if opts[:tenants] do
for repo <- repos do