fix: set default properly when modifying

This commit is contained in:
Zach Daniel 2020-12-01 01:54:20 -05:00
parent 803a6d79b8
commit 055e22f3b7
2 changed files with 19 additions and 1 deletions

View file

@ -471,6 +471,17 @@ defmodule AshPostgres.MigrationGenerator do
else
string
end
rescue
exception ->
IO.puts("""
Exception while formatting:
#{inspect(exception)}
#{inspect(string)}
""")
reraise exception, __STACKTRACE__
end
defp streamline(ops, acc \\ [])
@ -619,6 +630,9 @@ defmodule AshPostgres.MigrationGenerator do
name in keys || (multitenancy.attribute && name == multitenancy.attribute)
end
defp after?(%Operation.AddUniqueIndex{table: table}, %Operation.RemoveUniqueIndex{table: table}),
do: true
defp after?(
%Operation.AddUniqueIndex{identity: %{keys: keys}, table: table},
%Operation.AlterAttribute{table: table, new_attribute: %{name: name}}

View file

@ -124,7 +124,11 @@ defmodule AshPostgres.MigrationGenerator.Operation do
default =
if attribute.default != old_attribute.default do
", default: #{attribute.default}"
if is_nil(attribute.default) do
", default: nil"
else
", default: #{attribute.default}"
end
end
null =