From 33a84e179927d4e421aab054ad9dfa1889974486 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Mon, 22 Feb 2021 23:53:18 -0500 Subject: [PATCH] improvement: support latest ash --- .github/workflows/elixir.yml | 2 +- lib/data_layer.ex | 26 +++++++++---------- .../migration_generator.ex | 22 ++++++++-------- lib/mix/helpers.ex | 2 +- mix.exs | 2 +- mix.lock | 4 +-- test/support/resources/comment.ex | 2 +- test/support/resources/post.ex | 2 +- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index d077a6b..4248143 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -18,7 +18,7 @@ jobs: matrix: otp: ["23"] elixir: ["1.11.0"] - ash: ["master", "1.33.0"] + ash: ["master", "1.34.3"] pg_version: ["9.5", "9.6", "11"] env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/lib/data_layer.ex b/lib/data_layer.ex index 64fc0d0..7225487 100644 --- a/lib/data_layer.ex +++ b/lib/data_layer.ex @@ -182,14 +182,14 @@ defmodule AshPostgres.DataLayer do def can?(_, :upsert), do: true def can?(resource, {:join, other_resource}) do - data_layer = Ash.Resource.data_layer(resource) - other_data_layer = Ash.Resource.data_layer(other_resource) + data_layer = Ash.DataLayer.data_layer(resource) + other_data_layer = Ash.DataLayer.data_layer(other_resource) data_layer == other_data_layer and repo(data_layer) == repo(other_data_layer) end def can?(resource, {:lateral_join, other_resource}) do - data_layer = Ash.Resource.data_layer(resource) - other_data_layer = Ash.Resource.data_layer(other_resource) + data_layer = Ash.DataLayer.data_layer(resource) + other_data_layer = Ash.DataLayer.data_layer(other_resource) data_layer == other_data_layer and repo(data_layer) == repo(other_data_layer) end @@ -263,7 +263,7 @@ defmodule AshPostgres.DataLayer do end defp repo_opts(%{tenant: tenant, resource: resource}) when not is_nil(tenant) do - if Ash.Resource.multitenancy_strategy(resource) == :context do + if Ash.Resource.Info.multitenancy_strategy(resource) == :context do [prefix: tenant] else [] @@ -497,7 +497,7 @@ defmodule AshPostgres.DataLayer do defp add_unique_indexes(changeset, resource, tenant, ash_changeset) do changeset = resource - |> Ash.Resource.identities() + |> Ash.Resource.Info.identities() |> Enum.reduce(changeset, fn identity, changeset -> name = if tenant do @@ -525,7 +525,7 @@ defmodule AshPostgres.DataLayer do end names = [ - {Ash.Resource.primary_key(resource), table(resource, ash_changeset) <> "_pkey"} | names + {Ash.Resource.Info.primary_key(resource), table(resource, ash_changeset) <> "_pkey"} | names ] Enum.reduce(names, changeset, fn {keys, name}, changeset -> @@ -539,7 +539,7 @@ defmodule AshPostgres.DataLayer do changeset |> repo_opts() |> Keyword.put(:on_conflict, {:replace, Map.keys(changeset.attributes)}) - |> Keyword.put(:conflict_target, Ash.Resource.primary_key(resource)) + |> Keyword.put(:conflict_target, Ash.Resource.Info.primary_key(resource)) if AshPostgres.manage_tenant_update?(resource) do {:error, "Cannot currently upsert a resource that owns a tenant"} @@ -727,7 +727,7 @@ defmodule AshPostgres.DataLayer do {query, binding} = case get_binding(resource, aggregate.relationship_path, query, :aggregate) do nil -> - relationship = Ash.Resource.relationship(resource, aggregate.relationship_path) + relationship = Ash.Resource.Info.relationship(resource, aggregate.relationship_path) subquery = aggregate_subquery(relationship, aggregate) new_query = @@ -864,7 +864,7 @@ defmodule AshPostgres.DataLayer do filter( join.source.from.source.query, aggregate.authorization_filter, - Ash.Resource.related(resource, aggregate.relationship_path) + Ash.Resource.Info.related(resource, aggregate.relationship_path) ) filter @@ -969,7 +969,7 @@ defmodule AshPostgres.DataLayer do defp add_subquery_aggregate_select(query, %{kind: :count} = aggregate, resource) do query = default_bindings(query, aggregate.resource) - key = aggregate.field || List.first(Ash.Resource.primary_key(resource)) + key = aggregate.field || List.first(Ash.Resource.Info.primary_key(resource)) type = Ash.Type.ecto_type(aggregate.type) field = {:count, [], [{{:., [], [{:&, [], [0]}, key]}, [], []}]} @@ -1000,7 +1000,7 @@ defmodule AshPostgres.DataLayer do defp relationship_path_to_relationships(_resource, [], acc), do: Enum.reverse(acc) defp relationship_path_to_relationships(resource, [relationship | rest], acc) do - relationship = Ash.Resource.relationship(resource, relationship) + relationship = Ash.Resource.Info.relationship(resource, relationship) relationship_path_to_relationships(relationship.destination, rest, [relationship | acc]) end @@ -1085,7 +1085,7 @@ defmodule AshPostgres.DataLayer do defp add_distinct(relationship, join_type, joined_query) do if relationship.cardinality == :many and join_type == :left && !joined_query.distinct do from(row in joined_query, - distinct: ^Ash.Resource.primary_key(relationship.destination) + distinct: ^Ash.Resource.Info.primary_key(relationship.destination) ) else joined_query diff --git a/lib/migration_generator/migration_generator.ex b/lib/migration_generator/migration_generator.ex index 5b53e20..007e76f 100644 --- a/lib/migration_generator/migration_generator.ex +++ b/lib/migration_generator/migration_generator.ex @@ -35,7 +35,7 @@ defmodule AshPostgres.MigrationGenerator do {tenant_snapshots, snapshots} = all_resources - |> Enum.filter(&(Ash.Resource.data_layer(&1) == AshPostgres.DataLayer)) + |> Enum.filter(&(Ash.DataLayer.data_layer(&1) == AshPostgres.DataLayer)) |> Enum.filter(&AshPostgres.migrate?/1) |> Enum.flat_map(&get_snapshots(&1, all_resources)) |> Enum.split_with(&(&1.multitenancy.strategy == :context)) @@ -1095,7 +1095,7 @@ defmodule AshPostgres.MigrationGenerator do def get_snapshots(resource, all_resources) do if AshPostgres.polymorphic?(resource) do all_resources - |> Enum.flat_map(&Ash.Resource.relationships/1) + |> Enum.flat_map(&Ash.Resource.Info.relationships/1) |> Enum.filter(&(&1.destination == resource)) |> Enum.reject(&(&1.type == :belongs_to)) |> Enum.filter(& &1.context[:data_layer][:table]) @@ -1140,9 +1140,9 @@ defmodule AshPostgres.MigrationGenerator do end defp multitenancy(resource) do - strategy = Ash.Resource.multitenancy_strategy(resource) - attribute = Ash.Resource.multitenancy_attribute(resource) - global = Ash.Resource.multitenancy_global?(resource) + strategy = Ash.Resource.Info.multitenancy_strategy(resource) + attribute = Ash.Resource.Info.multitenancy_attribute(resource) + global = Ash.Resource.Info.multitenancy_global?(resource) %{ strategy: strategy, @@ -1155,7 +1155,7 @@ defmodule AshPostgres.MigrationGenerator do repo = AshPostgres.repo(resource) resource - |> Ash.Resource.attributes() + |> Ash.Resource.Info.attributes() |> Enum.sort_by(& &1.name) |> Enum.map(&Map.take(&1, [:name, :type, :default, :allow_nil?, :generated?, :primary_key?])) |> Enum.map(fn attribute -> @@ -1175,7 +1175,7 @@ defmodule AshPostgres.MigrationGenerator do end defp find_reference(resource, attribute) do - Enum.find_value(Ash.Resource.relationships(resource), fn relationship -> + Enum.find_value(Ash.Resource.Info.relationships(resource), fn relationship -> if attribute.name == relationship.source_field && relationship.type == :belongs_to && foreign_key?(relationship) do %{ @@ -1196,19 +1196,19 @@ defmodule AshPostgres.MigrationGenerator do defp migration_type_from_storage_type(storage_type), do: storage_type defp foreign_key?(relationship) do - Ash.Resource.data_layer(relationship.source) == AshPostgres.DataLayer && + Ash.DataLayer.data_layer(relationship.source) == AshPostgres.DataLayer && AshPostgres.repo(relationship.source) == AshPostgres.repo(relationship.destination) end defp identities(resource) do resource - |> Ash.Resource.identities() + |> Ash.Resource.Info.identities() |> case do [] -> [] identities -> - base_filter = Ash.Resource.base_filter(resource) + base_filter = Ash.Resource.Info.base_filter(resource) if base_filter && !AshPostgres.base_filter_sql(resource) do raise """ @@ -1223,7 +1223,7 @@ defmodule AshPostgres.MigrationGenerator do end) |> Enum.filter(fn identity -> Enum.all?(identity.keys, fn key -> - Ash.Resource.attribute(resource, key) + Ash.Resource.Info.attribute(resource, key) end) end) |> Enum.map(fn identity -> diff --git a/lib/mix/helpers.ex b/lib/mix/helpers.ex index aba2e95..1de4a6b 100644 --- a/lib/mix/helpers.ex +++ b/lib/mix/helpers.ex @@ -33,7 +33,7 @@ defmodule AshPostgres.MixHelpers do opts |> apis(args) |> Enum.flat_map(&Ash.Api.resources/1) - |> Enum.filter(&(Ash.Resource.data_layer(&1) == AshPostgres.DataLayer)) + |> Enum.filter(&(Ash.DataLayer.data_layer(&1) == AshPostgres.DataLayer)) |> Enum.map(&AshPostgres.repo(&1)) |> Enum.uniq() end diff --git a/mix.exs b/mix.exs index 116dffd..1bcc347 100644 --- a/mix.exs +++ b/mix.exs @@ -89,7 +89,7 @@ defmodule AshPostgres.MixProject do {:ecto_sql, "~> 3.5"}, {:jason, "~> 1.0"}, {:postgrex, ">= 0.0.0"}, - {:ash, ash_version("~> 1.33.0")}, + {:ash, ash_version("~> 1.34 and >= 1.34.3")}, {:git_ops, "~> 2.0.1", only: :dev}, {:ex_doc, "~> 0.22", only: :dev, runtime: false}, {:ex_check, "~> 0.11.0", only: :dev}, diff --git a/mix.lock b/mix.lock index ddcb180..adfef43 100644 --- a/mix.lock +++ b/mix.lock @@ -1,5 +1,5 @@ %{ - "ash": {:hex, :ash, "1.33.0", "f00dd8f51defd5fb98afcdf7c4aab91cb15446a3e7a30fa34caaf4d56e81d002", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8.0", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.3.5", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.1.5", [hex: :picosat_elixir, repo: "hexpm", optional: false]}, {:timex, ">= 3.0.0", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm", "c362e48dc4d7d1e14582f849b3368298a9b12222fe5bee86de383e9aab0c4bbc"}, + "ash": {:hex, :ash, "1.34.3", "bc997dd3eba1b2a2c15448df30ac5508d8c12d3b2e6611add6f0f3e9df94a420", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8.0", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.3.5", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.1.5", [hex: :picosat_elixir, repo: "hexpm", optional: false]}, {:timex, ">= 3.0.0", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm", "85a8b8a64c1ff5ee2b7f41a9e25c8bbddc133b24f73d57ce5604449046732f9d"}, "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, "certifi": {:hex, :certifi, "2.5.3", "70bdd7e7188c804f3a30ee0e7c99655bc35d8ac41c23e12325f36ab449b70651", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "ed516acb3929b101208a9d700062d520f3953da3b6b918d866106ffa980e1c10"}, "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"}, @@ -10,7 +10,7 @@ "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"}, "earmark": {:hex, :earmark, "1.4.5", "62ffd3bd7722fb7a7b1ecd2419ea0b458c356e7168c1f5d65caf09b4fbdd13c8", [:mix], [], "hexpm", "b7d0e6263d83dc27141a523467799a685965bf8b13b6743413f19a7079843f4f"}, - "ecto": {:hex, :ecto, "3.5.6", "29c77e999e471921c7ce7347732bab7bfa3e24c587640a36f17e0744d1474b8e", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3ae1f3eaecc3e72eeb65ed43239b292bb1eaf335c7e6cea3a7fc27aadb6e93e7"}, + "ecto": {:hex, :ecto, "3.5.8", "8ebf12be6016cb99313348ba7bb4612f4114b9a506d6da79a2adc7ef449340bc", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ea0be182ea8922eb7742e3ae8e71b67ee00ae177de1bf76210299a5f16ba4c77"}, "ecto_sql": {:hex, :ecto_sql, "3.5.2", "45502b7deb987b46f0d3714e694e07de2a41c06b2fcb7597dc40caf7d2fb5544", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.5.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "aaa3ea1a514b4364a95be4bdb4b2ece41dccb6293159da47dceb3a208e97d196"}, "elixir_make": {:hex, :elixir_make, "0.6.2", "7dffacd77dec4c37b39af867cedaabb0b59f6a871f89722c25b28fcd4bd70530", [:mix], [], "hexpm", "03e49eadda22526a7e5279d53321d1cced6552f344ba4e03e619063de75348d9"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, diff --git a/test/support/resources/comment.ex b/test/support/resources/comment.ex index bb64b17..426acaf 100644 --- a/test/support/resources/comment.ex +++ b/test/support/resources/comment.ex @@ -14,7 +14,7 @@ defmodule AshPostgres.Test.Comment do create :create do argument(:rating, :map) - change(manage_relationship(:rating, :ratings, on_destroy: :ignore, on_update: :create)) + change(manage_relationship(:rating, :ratings, on_missing: :ignore, on_match: :create)) end end diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index 2dceb3c..6b929e9 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -14,7 +14,7 @@ defmodule AshPostgres.Test.Post do create :create do argument(:rating, :map) - change(manage_relationship(:rating, :ratings, on_destroy: :ignore, on_update: :create)) + change(manage_relationship(:rating, :ratings, on_missing: :ignore, on_match: :create)) end end