diff --git a/lib/ash_uuid/uuid.ex b/lib/ash_uuid/uuid.ex index 23fdb6d..cc71437 100644 --- a/lib/ash_uuid/uuid.ex +++ b/lib/ash_uuid/uuid.ex @@ -26,19 +26,6 @@ defmodule AshUUID.UUID do StreamData.repeatedly(fn -> generate(constraints) end) end - def generate(constraints) do - {:ok, term} = - generate_uuid(constraints[:version]) - |> process( - constraints[:prefix], - constraints[:strict?], - :raw, - requested_format(constraints[:encoded?], constraints[:prefixed?]) - ) - - term - end - @impl true def matches_type?(v, constraints) do case cast_input(v, constraints) do @@ -88,7 +75,18 @@ defmodule AshUUID.UUID do @impl true def apply_constraints(_term, _constraints), do: :ok - ### + def generate(constraints) do + {:ok, term} = + generate_uuid(constraints[:version]) + |> process( + constraints[:prefix], + constraints[:strict?], + :raw, + requested_format(constraints[:encoded?], constraints[:prefixed?]) + ) + + term + end defp process(term, prefix, strict, initial_format, requested_format) do with {:ok, term} <- validate(term, initial_format), @@ -104,26 +102,18 @@ defmodule AshUUID.UUID do end end - ### - defp initial_format(term), do: AshUUID.identify_format(term) - ### - defp requested_format(encoded, prefixed) defp requested_format(nil, nil), do: :raw defp requested_format(false, _prefixed), do: :raw defp requested_format(true, false), do: :encoded defp requested_format(true, true), do: :prefixed - ### - defp generate_uuid(version) defp generate_uuid(4), do: Uniq.UUID.uuid4() defp generate_uuid(7), do: Uniq.UUID.uuid7() - ### - defp validate(term, initial_format) defp validate(term, initial_format) when initial_format in [:integer, :raw] do @@ -134,8 +124,6 @@ defmodule AshUUID.UUID do defp validate(nil, _initial_format), do: {:ok, nil} defp validate(_term, _initial_format), do: {:error, "got invalid term"} - ### - defp restore(result, initial_format, requested_format) defp restore(term, :integer, requested_format) when requested_format in [:raw, :encoded, :prefixed], @@ -143,8 +131,6 @@ defmodule AshUUID.UUID do defp restore(term, _initial_format, _requested_format), do: {:ok, term} - ### - defp strip(result, prefix, strict, initial_format) defp strip(term, nil, _strict, :prefixed) do @@ -164,8 +150,6 @@ defmodule AshUUID.UUID do defp strip(term, _prefix, _strict, _initial_format), do: {:ok, term} - ### - defp decode(result, initial_format) defp decode(nil, nil), do: {:ok, nil} @@ -175,8 +159,6 @@ defmodule AshUUID.UUID do defp decode(term, _initial_format), do: {:ok, term} - ### - defp encode(result, requested_format) defp encode(nil, _requested_format), do: {:ok, nil} @@ -186,15 +168,11 @@ defmodule AshUUID.UUID do defp encode(term, _requested_format), do: {:ok, term} - ### - defp prefix(result, prefix, requested_format) defp prefix(nil, _prefix, _requested_format), do: {:ok, nil} defp prefix(term, prefix, :prefixed), do: {:ok, "#{prefix}_#{term}"} defp prefix(term, _prefix, _requested_format), do: {:ok, term} - ### - defp dump(result, initial_format, requested_format) defp dump(term, initial_format, :integer) when initial_format in [:raw, :encoded, :prefixed] do diff --git a/mix.lock b/mix.lock index 921f20e..8ec3b68 100644 --- a/mix.lock +++ b/mix.lock @@ -1,6 +1,6 @@ %{ "ash": {:hex, :ash, "3.0.15", "1cea8ca799dc8281d09e316a189fddfb27a2a29a0b0e5af369aa83d6f731ca75", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, ">= 0.8.1 and < 1.0.0-0", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.1.18 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.2", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "97abfed57f2bf29c3889c51f0dfa23b382a1361a9d70e7d82d7e59a2be6bdc73"}, - "ash_postgres": {:hex, :ash_postgres, "2.0.11", "e06fc6767b9952af7221f2d66aaae6eb1644e8b1f644fa578150d249f107e836", [:mix], [{:ash, ">= 3.0.15 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:ash_sql, ">= 0.2.6 and < 1.0.0-0", [hex: :ash_sql, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.9", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm", "c2d512743e89da21cc903c16e67af77530c0c97fc1ffce3bf76abab0a3d19fca"}, + "ash_postgres": {:hex, :ash_postgres, "2.0.12", "0cd30b5eab6ef6fc77d1f29c23bd8b9ad62e676f8aa14bf9194d3cf87e10adf2", [:mix], [{:ash, ">= 3.0.15 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:ash_sql, ">= 0.2.6 and < 1.0.0-0", [hex: :ash_sql, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.9", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm", "a6536a641bcb3dc0ff5b351c35b9334e5586170037f88c0035f532dcba872700"}, "ash_sql": {:hex, :ash_sql, "0.2.6", "097a191b138af6bd5104ae0e166db5deb443fe3a4616b349fffe98120382765d", [:mix], [{:ash, "~> 3.0", [hex: :ash, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.9", [hex: :ecto_sql, repo: "hexpm", optional: false]}], "hexpm", "076abb07d7762537880a12699b756c7c86c1a4e98fcd0dc8c8059de93f7e9265"}, "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, "castore": {:hex, :castore, "1.0.7", "b651241514e5f6956028147fe6637f7ac13802537e895a724f90bf3e36ddd1dd", [:mix], [], "hexpm", "da7785a4b0d2a021cd1292a60875a784b6caef71e76bf4917bdee1f390455cf5"}, @@ -13,17 +13,17 @@ "earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"}, "ecto": {:hex, :ecto, "3.11.2", "e1d26be989db350a633667c5cda9c3d115ae779b66da567c68c80cfb26a8c9ee", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3c38bca2c6f8d8023f2145326cc8a80100c3ffe4dcbd9842ff867f7fc6156c65"}, "ecto_sql": {:hex, :ecto_sql, "3.11.3", "4eb7348ff8101fbc4e6bbc5a4404a24fecbe73a3372d16569526b0cf34ebc195", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.11.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e5f36e3d736b99c7fee3e631333b8394ade4bafe9d96d35669fca2d81c2be928"}, - "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, + "erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"}, "ets": {:hex, :ets, "0.9.0", "79c6a6c205436780486f72d84230c6cba2f8a9920456750ddd1e47389107d5fd", [:mix], [], "hexpm", "2861fdfb04bcaeff370f1a5904eec864f0a56dcfebe5921ea9aadf2a481c822b"}, "ex_check": {:hex, :ex_check, "0.16.0", "07615bef493c5b8d12d5119de3914274277299c6483989e52b0f6b8358a26b5f", [:mix], [], "hexpm", "4d809b72a18d405514dda4809257d8e665ae7cf37a7aee3be6b74a34dec310f5"}, - "ex_doc": {:hex, :ex_doc, "0.34.0", "ab95e0775db3df71d30cf8d78728dd9261c355c81382bcd4cefdc74610bef13e", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "60734fb4c1353f270c3286df4a0d51e65a2c1d9fba66af3940847cc65a8066d7"}, + "ex_doc": {:hex, :ex_doc, "0.34.1", "9751a0419bc15bc7580c73fde506b17b07f6402a1e5243be9e0f05a68c723368", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "d441f1a86a235f59088978eff870de2e815e290e44a8bd976fe5d64470a4c9d2"}, "file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"}, "finch": {:hex, :finch, "0.18.0", "944ac7d34d0bd2ac8998f79f7a811b21d87d911e77a786bc5810adb75632ada4", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6 or ~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "69f5045b042e531e53edc2574f15e25e735b522c37e2ddb766e15b979e03aa65"}, "git_cli": {:hex, :git_cli, "0.3.0", "a5422f9b95c99483385b976f5d43f7e8233283a47cda13533d7c16131cb14df5", [:mix], [], "hexpm", "78cb952f4c86a41f4d3511f1d3ecb28edb268e3a7df278de2faa1bd4672eaf9b"}, "git_ops": {:hex, :git_ops, "2.6.1", "cc7799a68c26cf814d6d1a5121415b4f5bf813de200908f930b27a2f1fe9dad5", [:mix], [{:git_cli, "~> 0.2", [hex: :git_cli, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "ce62d07e41fe993ec22c35d5edb11cf333a21ddaead6f5d9868fcb607d42039e"}, "glob_ex": {:hex, :glob_ex, "0.1.7", "eae6b6377147fb712ac45b360e6dbba00346689a87f996672fe07e97d70597b1", [:mix], [], "hexpm", "decc1c21c0c73df3c9c994412716345c1692477b9470e337f628a7e08da0da6a"}, "hpax": {:hex, :hpax, "0.2.0", "5a58219adcb75977b2edce5eb22051de9362f08236220c9e859a47111c194ff5", [:mix], [], "hexpm", "bea06558cdae85bed075e6c036993d43cd54d447f76d8190a8db0dc5893fa2f1"}, - "igniter": {:hex, :igniter, "0.1.8", "7f9b04ce2748c3411028e1426c73494ab39946f2174e115e19eeca1ca0ac9e1e", [:mix], [{:glob_ex, "~> 0.1.7", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:req, "~> 0.4", [hex: :req, repo: "hexpm", optional: false]}, {:rewrite, "~> 0.9", [hex: :rewrite, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.3", [hex: :sourceror, repo: "hexpm", optional: false]}, {:spitfire, ">= 0.1.3 and < 1.0.0-0", [hex: :spitfire, repo: "hexpm", optional: false]}], "hexpm", "09c15d725399fade83b94d4118f271954b85ad191dda8a66ce3f1f2ba1d4ff95"}, + "igniter": {:hex, :igniter, "0.2.0", "a163b308954878c5dd16d8e61e295dc2ff9562761a23c2a1bb154dd0f204f2a0", [:mix], [{:glob_ex, "~> 0.1.7", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:req, "~> 0.4", [hex: :req, repo: "hexpm", optional: false]}, {:rewrite, "~> 0.9", [hex: :rewrite, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.3", [hex: :sourceror, repo: "hexpm", optional: false]}, {:spitfire, ">= 0.1.3 and < 1.0.0-0", [hex: :spitfire, repo: "hexpm", optional: false]}], "hexpm", "012ed8a8c0d3e6f3bd3585925e87421e67f924b64ce5045920dae9ee9aca2707"}, "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, "libgraph": {:hex, :libgraph, "0.16.0", "3936f3eca6ef826e08880230f806bfea13193e49bf153f93edcf0239d4fd1d07", [:mix], [], "hexpm", "41ca92240e8a4138c30a7e06466acc709b0cbb795c643e9e17174a178982d6bf"}, "makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"}, @@ -42,7 +42,7 @@ "rewrite": {:hex, :rewrite, "0.10.5", "6afadeae0b9d843b27ac6225e88e165884875e0aed333ef4ad3bf36f9c101bed", [:mix], [{:glob_ex, "~> 0.1", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.0", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "51cc347a4269ad3a1e7a2c4122dbac9198302b082f5615964358b4635ebf3d4f"}, "sobelow": {:hex, :sobelow, "0.13.0", "218afe9075904793f5c64b8837cc356e493d88fddde126a463839351870b8d1e", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "cd6e9026b85fc35d7529da14f95e85a078d9dd1907a9097b3ba6ac7ebbe34a0d"}, "sourceror": {:hex, :sourceror, "1.3.0", "70ab9e8bf6df085a1effba4b49ad621b7153b065f69ef6cdb82e6088f2026029", [:mix], [], "hexpm", "1794c3ceeca4eb3f9437261721e4d9cbf846d7c64c7aee4f64062b18d5ce1eac"}, - "spark": {:hex, :spark, "2.2.3", "d41c45f0d7e8289499bf104173543be41ee1d8d213cb7503e9328b30751f2f13", [:mix], [{:igniter, ">= 0.1.7 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.2", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "401dec157c8b88634c27f241f4e374476081c577f51d2b08512f2c681c25a852"}, + "spark": {:hex, :spark, "2.2.4", "077363750eec4d80ffd4b20075676d17fce8bf82af1aa6aa51d2a539685b8d83", [:mix], [{:igniter, "~> 0.2", [hex: :igniter, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.2", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "fd92bdd4508852bcd445c463d0536d0f130ed828d90401d17a061bcdeca4372a"}, "spitfire": {:hex, :spitfire, "0.1.3", "7ea0f544005dfbe48e615ed90250c9a271bfe126914012023fd5e4b6b82b7ec7", [:mix], [], "hexpm", "d53b5107bcff526a05c5bb54c95e77b36834550affd5830c9f58760e8c543657"}, "splode": {:hex, :splode, "0.2.4", "71046334c39605095ca4bed5d008372e56454060997da14f9868534c17b84b53", [:mix], [], "hexpm", "ca3b95f0d8d4b482b5357954fec857abd0fa3ea509d623334c1328e7382044c2"}, "stream_data": {:hex, :stream_data, "1.1.1", "fd515ca95619cca83ba08b20f5e814aaf1e5ebff114659dc9731f966c9226246", [:mix], [], "hexpm", "45d0cd46bd06738463fd53f22b70042dbb58c384bb99ef4e7576e7bb7d3b8c8c"}, diff --git a/test/ash_uuid_test.exs b/test/ash_uuid_test.exs index 5ff57f4..26eb70f 100644 --- a/test/ash_uuid_test.exs +++ b/test/ash_uuid_test.exs @@ -435,5 +435,51 @@ defmodule AshUUIDTest do expected = "embedded-thing_#{encoded_uuid}" assert {:ok, ^expected} = result end + + test "testing hams and burgers" do + ham = + AshUUID.Test.Ham + |> Ash.Changeset.for_create(:create, %{}) + |> Ash.create!() + + assert %AshUUID.Test.Ham{} = ham + assert :prefixed = AshUUID.identify_format(ham.id) + assert ["ham", b62_string_uuid] = String.split(ham.id, "_") + assert {:ok, string_uuid} = AshUUID.Encoder.decode(b62_string_uuid) + assert {:ok, %{version: 7}} = Uniq.UUID.info(string_uuid) + + burger = + AshUUID.Test.Burger + |> Ash.Changeset.for_create(:create, %{ham_id: ham.id}) + |> Ash.create!() + + assert %AshUUID.Test.Burger{} = burger + assert :prefixed = AshUUID.identify_format(burger.id) + assert ["bur", b62_string_uuid] = String.split(burger.id, "_") + assert {:ok, string_uuid} = AshUUID.Encoder.decode(b62_string_uuid) + assert {:ok, %{version: 4}} = Uniq.UUID.info(string_uuid) + assert :prefixed = AshUUID.identify_format(burger.ham_id) + assert ["ham", b62_string_uuid] = String.split(burger.ham_id, "_") + assert {:ok, string_uuid} = AshUUID.Encoder.decode(b62_string_uuid) + assert {:ok, %{version: 7}} = Uniq.UUID.info(string_uuid) + + ham = + ham + |> Ash.Changeset.for_update(:update, %{burger_id: burger.id}) + |> Ash.update!() + + assert :prefixed = AshUUID.identify_format(ham.burger_id) + assert ["bur", b62_string_uuid] = String.split(ham.burger_id, "_") + assert {:ok, string_uuid} = AshUUID.Encoder.decode(b62_string_uuid) + assert {:ok, %{version: 4}} = Uniq.UUID.info(string_uuid) + + burger = Ash.load!(burger, :ham) + ham_id = ham.id + + assert %AshUUID.Test.Ham{id: ^ham_id} = loaded_ham = burger.ham + assert :prefixed = AshUUID.identify_format(loaded_ham.id) + + assert burger.id == ham.burger_id + end end end diff --git a/test/support/resources/burger.ex b/test/support/resources/burger.ex new file mode 100644 index 0000000..097a2ee --- /dev/null +++ b/test/support/resources/burger.ex @@ -0,0 +1,32 @@ +defmodule AshUUID.Test.Burger do + @moduledoc false + + use Ash.Resource, domain: AshUUID.Test, data_layer: AshPostgres.DataLayer, extensions: [AshUUID] + + postgres do + table "burgers" + repo AshUUID.Test.Repo + end + + attributes do + uuid_attribute :id, prefix: "bur", version: 4 + + uuid_attribute :ham_id, + prefix: "ham", + primary_key?: false, + default: nil, + writable?: true, + public?: true + + create_timestamp :inserted_at + end + + relationships do + belongs_to :ham, AshUUID.Test.Ham, define_attribute?: false + end + + actions do + defaults [:read, create: :*, update: :*] + default_accept :* + end +end diff --git a/test/support/resources/ham.ex b/test/support/resources/ham.ex new file mode 100644 index 0000000..b4c2352 --- /dev/null +++ b/test/support/resources/ham.ex @@ -0,0 +1,34 @@ +defmodule AshUUID.Test.Ham do + @moduledoc false + + use Ash.Resource, domain: AshUUID.Test, data_layer: AshPostgres.DataLayer, extensions: [AshUUID] + + postgres do + table "hams" + repo AshUUID.Test.Repo + end + + attributes do + uuid_attribute :id, prefix: "ham" + + uuid_attribute :burger_id, + prefix: "bur", + version: 4, + primary_key?: false, + allow_nil?: true, + default: nil, + writable?: true, + public?: true + + create_timestamp :inserted_at + end + + relationships do + belongs_to :burger, AshUUID.Test.Burger, define_attribute?: false + end + + actions do + defaults [:read, create: :*, update: :*] + default_accept :* + end +end diff --git a/test/support/test.ex b/test/support/test.ex index a221bd1..83d7404 100644 --- a/test/support/test.ex +++ b/test/support/test.ex @@ -11,6 +11,9 @@ defmodule AshUUID.Test do resource AshUUID.Test.Blib resource AshUUID.Test.BlibBlob resource AshUUID.Test.Blob + resource AshUUID.Test.Blob + resource AshUUID.Test.Burger + resource AshUUID.Test.Ham resource AshUUID.Test.Lime resource AshUUID.Test.LimeSmoothie resource AshUUID.Test.Mango