From 2f7fd75722669087152ad6b0ead9bb9806484b76 Mon Sep 17 00:00:00 2001 From: siassaj Date: Fri, 26 Sep 2025 10:41:04 +0300 Subject: [PATCH] fix: use default constraint of 'now()' for AshPostgres.Timestamptz AshPostgres.Timestamptz creates a pg column of type 'timestamptz', however the existing default behaviour was to implement the default constraint as a 'timestamp' type. Effectively 'now()::timestamptz' was converted to 'timestamp' then back to 'timestamptz'. This has been changed to 'now()'. --- lib/migration_generator/migration_generator.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/migration_generator/migration_generator.ex b/lib/migration_generator/migration_generator.ex index 86920ed4..1a3a396d 100644 --- a/lib/migration_generator/migration_generator.ex +++ b/lib/migration_generator/migration_generator.ex @@ -3489,7 +3489,7 @@ defmodule AshPostgres.MigrationGenerator do @uuid_functions [&Ash.UUID.generate/0, &Ecto.UUID.generate/0] - defp default(%{name: name, default: default}, resource, _repo) when is_function(default) do + defp default(%{name: name, default: default, type: type}, resource, _repo) when is_function(default) do configured_default(resource, name) || cond do default in @uuid_functions -> @@ -3498,6 +3498,9 @@ defmodule AshPostgres.MigrationGenerator do default == (&Ash.UUIDv7.generate/0) -> ~S[fragment("uuid_generate_v7()")] + default == (&DateTime.utc_now/0) && type == AshPostgres.Timestamptz -> + ~S[fragment("now()")] + default == (&DateTime.utc_now/0) -> ~S[fragment("(now() AT TIME ZONE 'utc')")]