mirror of
https://github.com/ash-project/ash_archival.git
synced 2024-09-19 13:02:55 +12:00
improvement: upgrade to 3.0
This commit is contained in:
parent
e89291c575
commit
d7ae1173d9
9 changed files with 124 additions and 95 deletions
7
.github/ISSUE_TEMPLATE/feature_request.md
vendored
7
.github/ISSUE_TEMPLATE/feature_request.md
vendored
|
@ -1,10 +1,9 @@
|
|||
---
|
||||
name: Proposal
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
title: ""
|
||||
labels: enhancement, needs review
|
||||
assignees: ''
|
||||
|
||||
assignees: ""
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
|
@ -29,7 +28,7 @@ For example
|
|||
Or
|
||||
|
||||
```elixir
|
||||
Api.read(:resource, bar: 10) # <- Adding `bar` here would cause <x>
|
||||
Ash.read(:resource, bar: 10) # <- Adding `bar` here would cause <x>
|
||||
```
|
||||
|
||||
**Additional context**
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
import Config
|
||||
|
||||
if Mix.env() == :test do
|
||||
config :ash, :validate_domain_resource_inclusion?, false
|
||||
config :ash, :validate_domain_config_inclusion?, false
|
||||
end
|
||||
|
||||
if Mix.env() == :dev do
|
||||
config :git_ops,
|
||||
mix_project: AshArchival.MixProject,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Un-archiving
|
||||
|
||||
At the moment, there is no way to unarchive an entry with a simple action on that resource. However, if you define a simple resource that uses the same storage under the hood (e.g same database table), but does *not* use the archival extension. You could then fabricate unarchival with something like this (this is not vetted, it is a pseudo-code example):
|
||||
At the moment, there is no way to unarchive an entry with a simple action on that resource. However, if you define a simple resource that uses the same storage under the hood (e.g same database table), but does _not_ use the archival extension. You could then fabricate unarchival with something like this (this is not vetted, it is a pseudo-code example):
|
||||
|
||||
```elixir
|
||||
# on the archived resource
|
||||
|
@ -20,12 +20,12 @@ with an `Unarchive` change like this
|
|||
```elixir
|
||||
def change(changeset, _, _) do
|
||||
# no data yet, so match on result being `nil`
|
||||
Ash.Changeset.after_action(changeset, fn changeset, nil ->
|
||||
Ash.Changeset.after_action(changeset, fn changeset, nil ->
|
||||
id = Ash.Changeset.get_argument(changeset, :id)
|
||||
|
||||
ResourceWithoutArchival
|
||||
|> Ash.Query.filter(id == ^id)
|
||||
|> Api.read_one()
|
||||
|> Ash.read_one()
|
||||
|> case do
|
||||
{:ok, nil} ->
|
||||
# not found error
|
||||
|
@ -33,10 +33,10 @@ def change(changeset, _, _) do
|
|||
# unarchive
|
||||
found
|
||||
|> Ash.Changeset.for_update(:update, %{archived_at: nil})
|
||||
|> Api.update!()
|
||||
|> Ash.update!()
|
||||
|
||||
{:ok, Api.get!(changeset.resource, id)}
|
||||
{:ok, Ash.get!(changeset.resource, id)}
|
||||
end
|
||||
end)
|
||||
end
|
||||
```
|
||||
```
|
||||
|
|
|
@ -11,8 +11,8 @@ defmodule AshArchival.Resource.Changes.ArchiveRelated do
|
|||
else
|
||||
Ash.Changeset.after_action(changeset, fn changeset, result ->
|
||||
# This is not optimized. We should do this with bulk queries, not resource actions.
|
||||
opts = context |> Ash.context_to_opts()
|
||||
loaded = changeset.api.load!(result, archive_related, opts)
|
||||
opts = context |> Ash.Context.to_opts(domain: changeset.domain)
|
||||
loaded = Ash.load!(result, archive_related, opts)
|
||||
|
||||
notifications =
|
||||
Enum.flat_map(archive_related, fn relationship ->
|
||||
|
@ -21,13 +21,16 @@ defmodule AshArchival.Resource.Changes.ArchiveRelated do
|
|||
destroy_action =
|
||||
Ash.Resource.Info.primary_action!(relationship.destination, :destroy).name
|
||||
|
||||
opts =
|
||||
Keyword.put(opts, :domain, Ash.Domain.Info.related_domain(changeset, relationship))
|
||||
|
||||
loaded
|
||||
|> Map.get(relationship.name)
|
||||
|> List.wrap()
|
||||
|> Enum.flat_map(fn related ->
|
||||
related
|
||||
|> Ash.Changeset.for_destroy(destroy_action, %{}, opts)
|
||||
|> (relationship.api || changeset.api).destroy!(
|
||||
|> Ash.destroy!(
|
||||
opts
|
||||
|> Keyword.merge(return_notifications?: true)
|
||||
)
|
||||
|
|
|
@ -37,7 +37,7 @@ defmodule AshArchival.Resource.Transformers.SetupArchival do
|
|||
Transformer.build_entity(Ash.Resource.Dsl, [:attributes], :attribute,
|
||||
name: :archived_at,
|
||||
type: :utc_datetime_usec,
|
||||
private?: true,
|
||||
public?: false,
|
||||
allow_nil?: true
|
||||
) do
|
||||
{:ok, Transformer.add_entity(dsl_state, [:attributes], archived_at)}
|
||||
|
|
6
mix.exs
6
mix.exs
|
@ -87,8 +87,10 @@ defmodule AshArchival.MixProject do
|
|||
# Run "mix help deps" to learn about dependencies.
|
||||
defp deps do
|
||||
[
|
||||
{:ash, ash_version("~> 2.0")},
|
||||
{:git_ops, "~> 2.4.5", only: [:dev, :test]},
|
||||
{:ash, ash_version("~> 3.0.0-rc.0")},
|
||||
# dev/test dependencies
|
||||
{:simple_sat, "~> 0.1.0", only: [:dev, :test]},
|
||||
{:git_ops, "~> 2.5", only: [:dev, :test]},
|
||||
{:ex_doc, github: "elixir-lang/ex_doc", only: [:dev, :test], runtime: false},
|
||||
{:ex_check, "~> 0.14", only: [:dev, :test]},
|
||||
{:credo, ">= 0.0.0", only: [:dev, :test], runtime: false},
|
||||
|
|
22
mix.lock
22
mix.lock
|
@ -1,32 +1,32 @@
|
|||
%{
|
||||
"ash": {:hex, :ash, "2.19.3", "51437dbfe74e1844b13bfc72ae9524d6a99b16ee74a013ba0b8005cdbec0f4f6", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:earmark, "~> 1.4", [hex: :earmark, 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: false]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:spark, ">= 1.1.50 and < 2.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.6", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "abfc99154296cd23e96b619ff3b4c9702b32bc19a11f6da19bfe006242b7d622"},
|
||||
"ash": {:hex, :ash, "3.0.0-rc.3", "9d2af1a4baef19ef0ef8a7f4bbdbbd640d54d62b484cdfd42e583d88c566115f", [: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", [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.7 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.2", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.6", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "83a16dace30aabb1f623e6f1b405cfe1af14f87a1411b1af9bbc745cd968a373"},
|
||||
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
|
||||
"comparable": {:hex, :comparable, "1.0.0", "bb669e91cedd14ae9937053e5bcbc3c52bb2f22422611f43b6e38367d94a495f", [:mix], [{:typable, "~> 0.1", [hex: :typable, repo: "hexpm", optional: false]}], "hexpm", "277c11eeb1cd726e7cd41c6c199e7e52fa16ee6830b45ad4cdc62e51f62eb60c"},
|
||||
"credo": {:hex, :credo, "1.7.4", "68ca5cf89071511c12fd9919eb84e388d231121988f6932756596195ccf7fd35", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "9cf776d062c78bbe0f0de1ecaee183f18f2c3ec591326107989b054b7dddefc2"},
|
||||
"credo": {:hex, :credo, "1.7.5", "643213503b1c766ec0496d828c90c424471ea54da77c8a168c725686377b9545", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "f799e9b5cd1891577d8c773d245668aa74a2fcd15eb277f51a0131690ebfb3fd"},
|
||||
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
|
||||
"dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"},
|
||||
"earmark": {:hex, :earmark, "1.4.46", "8c7287bd3137e99d26ae4643e5b7ef2129a260e3dcf41f251750cb4563c8fb81", [:mix], [], "hexpm", "798d86db3d79964e759ddc0c077d5eb254968ed426399fbf5a62de2b5ff8910a"},
|
||||
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
|
||||
"ecto": {:hex, :ecto, "3.11.1", "4b4972b717e7ca83d30121b12998f5fcdc62ba0ed4f20fd390f16f3270d85c3e", [: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", "ebd3d3772cd0dfcd8d772659e41ed527c28b2a8bde4b00fe03e0463da0f1983b"},
|
||||
"elixir_make": {:hex, :elixir_make, "0.7.8", "505026f266552ee5aabca0b9f9c229cbb496c689537c9f922f3eb5431157efc7", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "7a71945b913d37ea89b06966e1342c85cfe549b15e6d6d081e8081c493062c07"},
|
||||
"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"},
|
||||
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
|
||||
"ets": {:hex, :ets, "0.9.0", "79c6a6c205436780486f72d84230c6cba2f8a9920456750ddd1e47389107d5fd", [:mix], [], "hexpm", "2861fdfb04bcaeff370f1a5904eec864f0a56dcfebe5921ea9aadf2a481c822b"},
|
||||
"ex_check": {:hex, :ex_check, "0.15.0", "074b94c02de11c37bba1ca82ae5cc4926e6ccee862e57a485b6ba60fca2d8dc1", [:mix], [], "hexpm", "33848031a0c7e4209c3b4369ce154019788b5219956220c35ca5474299fb6a0e"},
|
||||
"ex_check": {:hex, :ex_check, "0.16.0", "07615bef493c5b8d12d5119de3914274277299c6483989e52b0f6b8358a26b5f", [:mix], [], "hexpm", "4d809b72a18d405514dda4809257d8e665ae7cf37a7aee3be6b74a34dec310f5"},
|
||||
"ex_doc": {:git, "https://github.com/elixir-lang/ex_doc.git", "e305f27f26cbd929410397cd3b6466f4c1b7d835", []},
|
||||
"excoveralls": {:hex, :excoveralls, "0.18.0", "b92497e69465dc51bc37a6422226ee690ab437e4c06877e836f1c18daeb35da9", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1109bb911f3cb583401760be49c02cbbd16aed66ea9509fc5479335d284da60b"},
|
||||
"file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"},
|
||||
"git_cli": {:hex, :git_cli, "0.3.0", "a5422f9b95c99483385b976f5d43f7e8233283a47cda13533d7c16131cb14df5", [:mix], [], "hexpm", "78cb952f4c86a41f4d3511f1d3ecb28edb268e3a7df278de2faa1bd4672eaf9b"},
|
||||
"git_ops": {:hex, :git_ops, "2.4.5", "185a724dfde3745edd22f7571d59c47a835cf54ded67e9ccbc951920b7eec4c2", [:mix], [{:git_cli, "~> 0.2", [hex: :git_cli, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e323a5b01ad53bc8c19c3a444be3e61ed7803ecd2e95530446ae9327d0143ecc"},
|
||||
"git_ops": {:hex, :git_ops, "2.6.0", "e0791ee1cf5db03f2c61b7ebd70e2e95cba2bb9b9793011f26609f22c0900087", [:mix], [{:git_cli, "~> 0.2", [hex: :git_cli, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "b98fca849b18aaf490f4ac7d1dd8c6c469b0cc3e6632562d366cab095e666ffe"},
|
||||
"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.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"},
|
||||
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
|
||||
"makeup_erlang": {:hex, :makeup_erlang, "0.1.4", "29563475afa9b8a2add1b7a9c8fb68d06ca7737648f28398e04461f008b69521", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f4ed47ecda66de70dd817698a703f8816daa91272e7e45812469498614ae8b29"},
|
||||
"nimble_options": {:hex, :nimble_options, "1.1.0", "3b31a57ede9cb1502071fade751ab0c7b8dbe75a9a4c2b5bbb0943a690b63172", [:mix], [], "hexpm", "8bbbb3941af3ca9acc7835f5655ea062111c9c27bcac53e004460dfd19008a99"},
|
||||
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
|
||||
"picosat_elixir": {:hex, :picosat_elixir, "0.2.3", "bf326d0f179fbb3b706bb2c15fbc367dacfa2517157d090fdfc32edae004c597", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "f76c9db2dec9d2561ffaa9be35f65403d53e984e8cd99c832383b7ab78c16c66"},
|
||||
"reactor": {:hex, :reactor, "0.8.1", "1aec71d16083901277727c8162f6dd0f07e80f5ca98911b6ef4f2c95e6e62758", [:mix], [{:libgraph, "~> 0.16", [hex: :libgraph, repo: "hexpm", optional: false]}, {:spark, "~> 2.0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.2", [hex: :splode, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.2", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ae3936d97a3e4a316744f70c77b85345b08b70da334024c26e6b5eb8ede1246b"},
|
||||
"simple_sat": {:hex, :simple_sat, "0.1.1", "68a5ebe6f6d5956bd806e4881c495692c14580a2f1a4420488985abd0fba2119", [:mix], [], "hexpm", "63571218f92ff029838df7645eb8f0c38df8ed60d2d14578412a8d142a94471e"},
|
||||
"sobelow": {:hex, :sobelow, "0.13.0", "218afe9075904793f5c64b8837cc356e493d88fddde126a463839351870b8d1e", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "cd6e9026b85fc35d7529da14f95e85a078d9dd1907a9097b3ba6ac7ebbe34a0d"},
|
||||
"sourceror": {:hex, :sourceror, "0.14.1", "c6fb848d55bd34362880da671debc56e77fd722fa13b4dcbeac89a8998fc8b09", [:mix], [], "hexpm", "8b488a219e4c4d7d9ff29d16346fd4a5858085ccdd010e509101e226bbfd8efc"},
|
||||
"spark": {:hex, :spark, "1.1.54", "54dac39403a2960f738ba5d60678d20b30de7381fb51b787b6bcb6aeabb73d9d", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.5 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:sourceror, "~> 0.1", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "abc9a67cfb60a97d2f3c7e270fa968a2ace94f389e2741d406239d237ec6dbb1"},
|
||||
"sourceror": {:hex, :sourceror, "1.0.2", "c5e86fdc14881f797749d1fe5df017ca66727a8146e7ee3e736605a3df78f3e6", [:mix], [], "hexpm", "832335e87d0913658f129d58b2a7dc0490ddd4487b02de6d85bca0169ec2bd79"},
|
||||
"spark": {:hex, :spark, "2.1.10", "f32cf6a0231f7a8a128889ee82682d53743c05b9c5b26392fefc0513b9be06d7", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.0", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "86a88091a754ea2a4ed6dbc919e57e60828112b3552de14adb83ee20064813a2"},
|
||||
"splode": {:hex, :splode, "0.2.1", "020079ec06c9e00f8b6586852e781b5e07aee6ba588f3f45dd993831c87b0511", [:mix], [], "hexpm", "d232a933666061fe1f659d9906042fa94b9b393bb1129a4fde6fa680033b2611"},
|
||||
"stream_data": {:hex, :stream_data, "0.6.0", "e87a9a79d7ec23d10ff83eb025141ef4915eeb09d4491f79e52f2562b73e5f47", [:mix], [], "hexpm", "b92b5031b650ca480ced047578f1d57ea6dd563f5b57464ad274718c9c29501c"},
|
||||
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
|
||||
"typable": {:hex, :typable, "0.3.0", "0431e121d124cd26f312123e313d2689b9a5322b15add65d424c07779eaa3ca1", [:mix], [], "hexpm", "880a0797752da1a4c508ac48f94711e04c86156f498065a83d160eef945858f8"},
|
||||
|
|
|
@ -3,6 +3,7 @@ defmodule ArchivalTest do
|
|||
|
||||
defmodule Author do
|
||||
use Ash.Resource,
|
||||
domain: ArchivalTest.Domain,
|
||||
data_layer: Ash.DataLayer.Ets,
|
||||
extensions: [AshArchival.Resource]
|
||||
|
||||
|
@ -16,6 +17,7 @@ defmodule ArchivalTest do
|
|||
end
|
||||
|
||||
actions do
|
||||
default_accept(:*)
|
||||
defaults([:create, :read, :update, :destroy])
|
||||
end
|
||||
|
||||
|
@ -24,12 +26,15 @@ defmodule ArchivalTest do
|
|||
end
|
||||
|
||||
relationships do
|
||||
has_many(:posts, ArchivalTest.Post)
|
||||
has_many(:posts, ArchivalTest.Post) do
|
||||
public?(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defmodule AuthorWithArchive do
|
||||
use Ash.Resource,
|
||||
domain: ArchivalTest.Domain,
|
||||
data_layer: Ash.DataLayer.Ets
|
||||
|
||||
ets do
|
||||
|
@ -38,17 +43,19 @@ defmodule ArchivalTest do
|
|||
end
|
||||
|
||||
actions do
|
||||
default_accept(:*)
|
||||
defaults([:create, :read, :update, :destroy])
|
||||
end
|
||||
|
||||
attributes do
|
||||
uuid_primary_key(:id)
|
||||
attribute(:archived_at, :utc_datetime_usec)
|
||||
attribute(:archived_at, :utc_datetime_usec, public?: true)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Post do
|
||||
use Ash.Resource,
|
||||
domain: ArchivalTest.Domain,
|
||||
data_layer: Ash.DataLayer.Ets,
|
||||
extensions: [AshArchival.Resource]
|
||||
|
||||
|
@ -62,6 +69,7 @@ defmodule ArchivalTest do
|
|||
end
|
||||
|
||||
actions do
|
||||
default_accept(:*)
|
||||
defaults([:create, :read, :update, :destroy])
|
||||
end
|
||||
|
||||
|
@ -71,15 +79,19 @@ defmodule ArchivalTest do
|
|||
|
||||
relationships do
|
||||
belongs_to :author, Author do
|
||||
public?(true)
|
||||
attribute_writable?(true)
|
||||
end
|
||||
|
||||
has_many(:comments, ArchivalTest.Comment)
|
||||
has_many(:comments, ArchivalTest.Comment) do
|
||||
public?(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defmodule PostWithArchive do
|
||||
use Ash.Resource,
|
||||
domain: ArchivalTest.Domain,
|
||||
data_layer: Ash.DataLayer.Ets
|
||||
|
||||
ets do
|
||||
|
@ -88,17 +100,19 @@ defmodule ArchivalTest do
|
|||
end
|
||||
|
||||
actions do
|
||||
default_accept(:*)
|
||||
defaults([:create, :read, :update, :destroy])
|
||||
end
|
||||
|
||||
attributes do
|
||||
uuid_primary_key(:id)
|
||||
attribute(:archived_at, :utc_datetime_usec)
|
||||
attribute(:archived_at, :utc_datetime_usec, public?: true)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Comment do
|
||||
use Ash.Resource,
|
||||
domain: ArchivalTest.Domain,
|
||||
data_layer: Ash.DataLayer.Ets,
|
||||
extensions: [AshArchival.Resource]
|
||||
|
||||
|
@ -108,6 +122,7 @@ defmodule ArchivalTest do
|
|||
end
|
||||
|
||||
actions do
|
||||
default_accept(:*)
|
||||
defaults([:create, :read, :update, :destroy])
|
||||
end
|
||||
|
||||
|
@ -117,6 +132,7 @@ defmodule ArchivalTest do
|
|||
|
||||
relationships do
|
||||
belongs_to :post, Post do
|
||||
public?(true)
|
||||
attribute_writable?(true)
|
||||
end
|
||||
end
|
||||
|
@ -124,6 +140,7 @@ defmodule ArchivalTest do
|
|||
|
||||
defmodule CommentWithArchive do
|
||||
use Ash.Resource,
|
||||
domain: ArchivalTest.Domain,
|
||||
data_layer: Ash.DataLayer.Ets
|
||||
|
||||
ets do
|
||||
|
@ -132,33 +149,26 @@ defmodule ArchivalTest do
|
|||
end
|
||||
|
||||
actions do
|
||||
default_accept(:*)
|
||||
defaults([:create, :read, :update, :destroy])
|
||||
end
|
||||
|
||||
attributes do
|
||||
uuid_primary_key(:id)
|
||||
attribute(:archived_at, :utc_datetime_usec)
|
||||
attribute(:archived_at, :utc_datetime_usec, public?: true)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Registry do
|
||||
use Ash.Registry
|
||||
|
||||
entries do
|
||||
entry(Author)
|
||||
entry(AuthorWithArchive)
|
||||
entry(Post)
|
||||
entry(PostWithArchive)
|
||||
entry(Comment)
|
||||
entry(CommentWithArchive)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Api do
|
||||
use Ash.Api
|
||||
defmodule Domain do
|
||||
use Ash.Domain
|
||||
|
||||
resources do
|
||||
registry(Registry)
|
||||
resource(Author)
|
||||
resource(AuthorWithArchive)
|
||||
resource(Post)
|
||||
resource(PostWithArchive)
|
||||
resource(Comment)
|
||||
resource(CommentWithArchive)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -166,11 +176,11 @@ defmodule ArchivalTest do
|
|||
post =
|
||||
Post
|
||||
|> Ash.Changeset.for_create(:create)
|
||||
|> Api.create!()
|
||||
|> Ash.create!()
|
||||
|
||||
assert :ok = post |> Api.destroy!()
|
||||
assert :ok = post |> Ash.destroy!()
|
||||
|
||||
[archived] = Api.read!(PostWithArchive)
|
||||
[archived] = Ash.read!(PostWithArchive)
|
||||
assert archived.id == post.id
|
||||
assert archived.archived_at
|
||||
end
|
||||
|
@ -179,16 +189,16 @@ defmodule ArchivalTest do
|
|||
post =
|
||||
Post
|
||||
|> Ash.Changeset.for_create(:create)
|
||||
|> Api.create!()
|
||||
|> Ash.create!()
|
||||
|
||||
comment =
|
||||
Comment
|
||||
|> Ash.Changeset.for_create(:create, %{post_id: post.id})
|
||||
|> Api.create!()
|
||||
|> Ash.create!()
|
||||
|
||||
assert :ok = post |> Api.destroy!()
|
||||
assert :ok = post |> Ash.destroy!()
|
||||
|
||||
[archived] = Api.read!(CommentWithArchive)
|
||||
[archived] = Ash.read!(CommentWithArchive)
|
||||
assert archived.id == comment.id
|
||||
assert archived.archived_at
|
||||
end
|
||||
|
@ -197,25 +207,25 @@ defmodule ArchivalTest do
|
|||
author =
|
||||
Author
|
||||
|> Ash.Changeset.for_create(:create)
|
||||
|> Api.create!()
|
||||
|> Ash.create!()
|
||||
|
||||
post =
|
||||
Post
|
||||
|> Ash.Changeset.for_create(:create, %{author_id: author.id})
|
||||
|> Api.create!()
|
||||
|> Ash.create!()
|
||||
|
||||
comment =
|
||||
Comment
|
||||
|> Ash.Changeset.for_create(:create, %{post_id: post.id})
|
||||
|> Api.create!()
|
||||
|> Ash.create!()
|
||||
|
||||
assert :ok = author |> Api.destroy!()
|
||||
assert :ok = author |> Ash.destroy!()
|
||||
|
||||
[archived_post] = Api.read!(PostWithArchive)
|
||||
[archived_post] = Ash.read!(PostWithArchive)
|
||||
assert archived_post.id == post.id
|
||||
assert archived_post.archived_at
|
||||
|
||||
[archived_comment] = Api.read!(CommentWithArchive)
|
||||
[archived_comment] = Ash.read!(CommentWithArchive)
|
||||
assert archived_comment.id == comment.id
|
||||
assert archived_comment.archived_at
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ defmodule ArchivalWithPolicyTest do
|
|||
|
||||
defmodule Author do
|
||||
use Ash.Resource,
|
||||
domain: ArchivalWithPolicyTest.Domain,
|
||||
data_layer: Ash.DataLayer.Ets,
|
||||
extensions: [AshArchival.Resource],
|
||||
authorizers: [Ash.Policy.Authorizer]
|
||||
|
@ -17,6 +18,7 @@ defmodule ArchivalWithPolicyTest do
|
|||
end
|
||||
|
||||
actions do
|
||||
default_accept(:*)
|
||||
defaults([:create, :read, :update, :destroy])
|
||||
end
|
||||
|
||||
|
@ -25,7 +27,9 @@ defmodule ArchivalWithPolicyTest do
|
|||
end
|
||||
|
||||
relationships do
|
||||
has_many(:posts, ArchivalWithPolicyTest.Post)
|
||||
has_many(:posts, ArchivalWithPolicyTest.Post) do
|
||||
public?(true)
|
||||
end
|
||||
end
|
||||
|
||||
policies do
|
||||
|
@ -39,6 +43,7 @@ defmodule ArchivalWithPolicyTest do
|
|||
|
||||
defmodule AuthorWithArchive do
|
||||
use Ash.Resource,
|
||||
domain: ArchivalWithPolicyTest.Domain,
|
||||
data_layer: Ash.DataLayer.Ets
|
||||
|
||||
ets do
|
||||
|
@ -47,17 +52,19 @@ defmodule ArchivalWithPolicyTest do
|
|||
end
|
||||
|
||||
actions do
|
||||
default_accept(:*)
|
||||
defaults([:create, :read, :update, :destroy])
|
||||
end
|
||||
|
||||
attributes do
|
||||
uuid_primary_key(:id)
|
||||
attribute(:archived_at, :utc_datetime_usec)
|
||||
attribute(:archived_at, :utc_datetime_usec, public?: true)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Post do
|
||||
use Ash.Resource,
|
||||
domain: ArchivalWithPolicyTest.Domain,
|
||||
data_layer: Ash.DataLayer.Ets,
|
||||
extensions: [AshArchival.Resource],
|
||||
authorizers: [Ash.Policy.Authorizer]
|
||||
|
@ -72,6 +79,7 @@ defmodule ArchivalWithPolicyTest do
|
|||
end
|
||||
|
||||
actions do
|
||||
default_accept(:*)
|
||||
defaults([:create, :read, :update, :destroy])
|
||||
end
|
||||
|
||||
|
@ -81,10 +89,13 @@ defmodule ArchivalWithPolicyTest do
|
|||
|
||||
relationships do
|
||||
belongs_to :author, Author do
|
||||
public?(true)
|
||||
attribute_writable?(true)
|
||||
end
|
||||
|
||||
has_many(:comments, ArchivalWithPolicyTest.Comment)
|
||||
has_many(:comments, ArchivalWithPolicyTest.Comment) do
|
||||
public?(true)
|
||||
end
|
||||
end
|
||||
|
||||
policies do
|
||||
|
@ -98,6 +109,7 @@ defmodule ArchivalWithPolicyTest do
|
|||
|
||||
defmodule PostWithArchive do
|
||||
use Ash.Resource,
|
||||
domain: ArchivalWithPolicyTest.Domain,
|
||||
data_layer: Ash.DataLayer.Ets
|
||||
|
||||
ets do
|
||||
|
@ -106,17 +118,19 @@ defmodule ArchivalWithPolicyTest do
|
|||
end
|
||||
|
||||
actions do
|
||||
default_accept(:*)
|
||||
defaults([:create, :read, :update, :destroy])
|
||||
end
|
||||
|
||||
attributes do
|
||||
uuid_primary_key(:id)
|
||||
attribute(:archived_at, :utc_datetime_usec)
|
||||
attribute(:archived_at, :utc_datetime_usec, public?: true)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Comment do
|
||||
use Ash.Resource,
|
||||
domain: ArchivalWithPolicyTest.Domain,
|
||||
data_layer: Ash.DataLayer.Ets,
|
||||
extensions: [AshArchival.Resource],
|
||||
authorizers: [Ash.Policy.Authorizer]
|
||||
|
@ -127,6 +141,7 @@ defmodule ArchivalWithPolicyTest do
|
|||
end
|
||||
|
||||
actions do
|
||||
default_accept(:*)
|
||||
defaults([:create, :read, :update, :destroy])
|
||||
end
|
||||
|
||||
|
@ -136,6 +151,7 @@ defmodule ArchivalWithPolicyTest do
|
|||
|
||||
relationships do
|
||||
belongs_to :post, Post do
|
||||
public?(true)
|
||||
attribute_writable?(true)
|
||||
end
|
||||
end
|
||||
|
@ -151,6 +167,7 @@ defmodule ArchivalWithPolicyTest do
|
|||
|
||||
defmodule CommentWithArchive do
|
||||
use Ash.Resource,
|
||||
domain: ArchivalWithPolicyTest.Domain,
|
||||
data_layer: Ash.DataLayer.Ets
|
||||
|
||||
ets do
|
||||
|
@ -159,37 +176,30 @@ defmodule ArchivalWithPolicyTest do
|
|||
end
|
||||
|
||||
actions do
|
||||
default_accept(:*)
|
||||
defaults([:create, :read, :update, :destroy])
|
||||
end
|
||||
|
||||
attributes do
|
||||
uuid_primary_key(:id)
|
||||
attribute(:archived_at, :utc_datetime_usec)
|
||||
attribute(:archived_at, :utc_datetime_usec, public?: true)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Registry do
|
||||
use Ash.Registry
|
||||
|
||||
entries do
|
||||
entry(Author)
|
||||
entry(AuthorWithArchive)
|
||||
entry(Post)
|
||||
entry(PostWithArchive)
|
||||
entry(Comment)
|
||||
entry(CommentWithArchive)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Api do
|
||||
use Ash.Api
|
||||
defmodule Domain do
|
||||
use Ash.Domain
|
||||
|
||||
authorization do
|
||||
authorize(:always)
|
||||
end
|
||||
|
||||
resources do
|
||||
registry(Registry)
|
||||
resource(Author)
|
||||
resource(AuthorWithArchive)
|
||||
resource(Post)
|
||||
resource(PostWithArchive)
|
||||
resource(Comment)
|
||||
resource(CommentWithArchive)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -197,11 +207,11 @@ defmodule ArchivalWithPolicyTest do
|
|||
comment =
|
||||
Comment
|
||||
|> Ash.Changeset.for_create(:create)
|
||||
|> Api.create!()
|
||||
|> Ash.create!()
|
||||
|
||||
assert :ok = comment |> Api.destroy!(actor: %{admin: true})
|
||||
assert :ok = comment |> Ash.destroy!(actor: %{admin: true})
|
||||
|
||||
[archived] = Api.read!(CommentWithArchive)
|
||||
[archived] = Ash.read!(CommentWithArchive)
|
||||
assert archived.id == comment.id
|
||||
assert archived.archived_at
|
||||
end
|
||||
|
@ -210,16 +220,16 @@ defmodule ArchivalWithPolicyTest do
|
|||
post =
|
||||
Post
|
||||
|> Ash.Changeset.for_create(:create)
|
||||
|> Api.create!()
|
||||
|> Ash.create!()
|
||||
|
||||
comment =
|
||||
Comment
|
||||
|> Ash.Changeset.for_create(:create, %{post_id: post.id})
|
||||
|> Api.create!()
|
||||
|> Ash.create!()
|
||||
|
||||
assert :ok = post |> Api.destroy!(actor: %{admin: true})
|
||||
assert :ok = post |> Ash.destroy!(actor: %{admin: true})
|
||||
|
||||
[archived] = Api.read!(CommentWithArchive)
|
||||
[archived] = Ash.read!(CommentWithArchive)
|
||||
assert archived.id == comment.id
|
||||
assert archived.archived_at
|
||||
end
|
||||
|
@ -228,25 +238,25 @@ defmodule ArchivalWithPolicyTest do
|
|||
author =
|
||||
Author
|
||||
|> Ash.Changeset.for_create(:create)
|
||||
|> Api.create!()
|
||||
|> Ash.create!()
|
||||
|
||||
post =
|
||||
Post
|
||||
|> Ash.Changeset.for_create(:create, %{author_id: author.id})
|
||||
|> Api.create!()
|
||||
|> Ash.create!()
|
||||
|
||||
comment =
|
||||
Comment
|
||||
|> Ash.Changeset.for_create(:create, %{post_id: post.id})
|
||||
|> Api.create!()
|
||||
|> Ash.create!()
|
||||
|
||||
assert :ok = author |> Api.destroy!(actor: %{admin: true})
|
||||
assert :ok = author |> Ash.destroy!(actor: %{admin: true})
|
||||
|
||||
[archived_post] = Api.read!(PostWithArchive)
|
||||
[archived_post] = Ash.read!(PostWithArchive)
|
||||
assert archived_post.id == post.id
|
||||
assert archived_post.archived_at
|
||||
|
||||
[archived_comment] = Api.read!(CommentWithArchive)
|
||||
[archived_comment] = Ash.read!(CommentWithArchive)
|
||||
assert archived_comment.id == comment.id
|
||||
assert archived_comment.archived_at
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue