Skip to content

Commit

Permalink
fix: typo of biging -> bigint
Browse files Browse the repository at this point in the history
fix: altering attributes not properly generating foreign keys in some cases
  • Loading branch information
zachdaniel committed Sep 24, 2024
1 parent a87d9b4 commit 10c9508
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
52 changes: 32 additions & 20 deletions lib/migration_generator/migration_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2199,12 +2199,10 @@ defmodule AshPostgres.MigrationGenerator do
[]
end

if has_reference?(old_snapshot.multitenancy, old_attribute) and
Map.get(old_attribute, :references) != Map.get(new_attribute, :references) do
if Map.get(old_attribute, :references) != Map.get(new_attribute, :references) do
redo_deferrability =
if differently_deferrable?(new_attribute, old_attribute) do
[]
else
if has_reference?(old_snapshot.multitenancy, old_attribute) and
differently_deferrable?(new_attribute, old_attribute) do
[
%Operation.AlterDeferrability{
table: snapshot.table,
Expand All @@ -2213,24 +2211,38 @@ defmodule AshPostgres.MigrationGenerator do
direction: :up
}
]
else
[]
end

old_and_alter =
[
%Operation.DropForeignKey{
attribute: old_attribute,
table: snapshot.table,
schema: snapshot.schema,
multitenancy: old_snapshot.multitenancy,
direction: :up
},
%Operation.AlterAttribute{
new_attribute: new_attribute,
old_attribute: old_attribute,
schema: snapshot.schema,
table: snapshot.table
}
] ++ redo_deferrability
if has_reference?(old_snapshot.multitenancy, old_attribute) do
[
%Operation.DropForeignKey{
attribute: old_attribute,
table: snapshot.table,
schema: snapshot.schema,
multitenancy: old_snapshot.multitenancy,
direction: :up
},
%Operation.AlterAttribute{
new_attribute: new_attribute,
old_attribute: old_attribute,
schema: snapshot.schema,
table: snapshot.table
}
]
else
[
%Operation.AlterAttribute{
new_attribute: new_attribute,
old_attribute: old_attribute,
schema: snapshot.schema,
table: snapshot.table
}
]
end ++
redo_deferrability

if has_reference?(snapshot.multitenancy, new_attribute) do
reference_ops = [
Expand Down
2 changes: 1 addition & 1 deletion lib/migration_generator/operation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ defmodule AshPostgres.MigrationGenerator.Operation do
Map.get(old_attribute, :references) != Map.get(attribute, :references) do
reference(multitenancy, attribute, schema)
else
if attribute.type == :biging and attribute.default == "nil" and attribute.generated? do
if attribute.type == :bigint and attribute.default == "nil" and attribute.generated? do
":bigserial"
else
inspect(attribute.type)
Expand Down

0 comments on commit 10c9508

Please sign in to comment.