Skip to content

Commit 7c6b625

Browse files
dev-guyterris-citizen
authored andcommitted
Merge branch 'main' into 35
2 parents 793e8e6 + 79efb33 commit 7c6b625

3 files changed

Lines changed: 27 additions & 39 deletions

File tree

lib/geo/geography/country.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule Geo.Geography.Country do
33
otp_app: :geo,
44
domain: Geo.Geography,
55
data_layer: AshPostgres.DataLayer,
6-
extensions: [Geo.Resources.Extensions.Id]
6+
extensions: [Geo.Resources.Attributes.Id]
77

88
# === Attributes ===
99
use Geo.Resources.Attributes.Name, allow_nil?: false, unique?: true

lib/geo/resources/attributes/id.ex

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
1-
defmodule Geo.Resources.Attributes.Id.Defunct do
1+
defmodule Geo.Resources.Attributes.Id do
22
@moduledoc """
3+
An Ash extension that adds a UUID v7 primary key attribute to a resource.
34
"""
45

5-
defmacro __using__(_opts) do
6-
quote do
7-
attributes do
8-
uuid_v7_primary_key :id
9-
end
6+
use Spark.Dsl.Extension,
7+
transformers: [
8+
__MODULE__.Transformer
9+
]
10+
11+
defmodule Transformer do
12+
@moduledoc false
13+
use Spark.Dsl.Transformer
14+
15+
def before?(Ash.Resource.Transformers.BelongsToAttribute), do: true
16+
def before?(_), do: false
17+
18+
def transform(dsl_state) do
19+
attribute = %Ash.Resource.Attribute{
20+
name: :id,
21+
type: :uuid_v7,
22+
allow_nil?: false,
23+
writable?: false,
24+
public?: true,
25+
primary_key?: true,
26+
default: &Ash.UUIDv7.generate/0
27+
}
28+
29+
{:ok, Spark.Dsl.Transformer.add_entity(dsl_state, [:attributes], attribute)}
1030
end
1131
end
1232
end

lib/geo/resources/extensions/id.ex

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)