Skip to content

Commit 3e24e7c

Browse files
committed
fix: don't use :"timestamptz(6)" in ecto storage type
1 parent afa872b commit 3e24e7c

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

lib/migration_generator/migration_generator.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3364,8 +3364,13 @@ defmodule AshPostgres.MigrationGenerator do
33643364

33653365
defp migration_type(other, constraints) do
33663366
type = Ash.Type.get_type(other)
3367+
Code.ensure_loaded(type)
33673368

3368-
migration_type_from_storage_type(Ash.Type.storage_type(type, constraints))
3369+
if function_exported?(type, :migration_type, 1) do
3370+
type.migration_type(constraints)
3371+
else
3372+
migration_type_from_storage_type(Ash.Type.storage_type(type, constraints))
3373+
end
33693374
end
33703375

33713376
defp migration_type_from_storage_type(:string), do: :text

lib/type.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ defmodule AshPostgres.Type do
1111
@callback postgres_reference_expr(Ash.Type.t(), Ash.Type.constraints(), term) ::
1212
{:ok, term} | :error
1313

14+
@callback migration_type(Ash.Type.constraints()) :: term()
15+
1416
@optional_callbacks value_to_postgres_default: 3,
15-
postgres_reference_expr: 3
17+
postgres_reference_expr: 3,
18+
migration_type: 1
1619

1720
defmacro __using__(_) do
1821
quote do

lib/types/timestamptz.ex

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ defmodule AshPostgres.Timestamptz do
2828
attribute :timestamp, :timestamptz
2929
timestamps type: :timestamptz
3030
```
31-
32-
33-
34-
3531
"""
3632
use Ash.Type.NewType, subtype_of: :datetime, constraints: [precision: :second]
3733

lib/types/timestamptz_usec.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ defmodule AshPostgres.TimestamptzUsec do
2121
timestamps type: :timestamptz_usec
2222
```
2323
24-
25-
2624
Please see `AshPostgres.Timestamptz` for details about the usecase for this type.
2725
"""
2826
use Ash.Type.NewType, subtype_of: :datetime, constraints: [precision: :microsecond]
2927

3028
@impl true
3129
def storage_type(_constraints) do
30+
:timestamptz
31+
end
32+
33+
def migration_type(_constraints) do
3234
:"timestamptz(6)"
3335
end
3436
end

0 commit comments

Comments
 (0)