From 920bdf38b458dfc758c1e07a7ff28d62b589b124 Mon Sep 17 00:00:00 2001 From: "Michael B. Klein" Date: Wed, 2 Oct 2024 17:05:41 +0000 Subject: [PATCH] Fix introspection, migration, and casting for ecto_sql 3.12.x and ecto_ranked 0.6.x --- app/lib/meadow/data/csv/import.ex | 1 + .../meadow/data/schemas/types/edtf_date.ex | 4 +++- app/lib/meadow/data/schemas/validations.ex | 19 ++++++++++++------- app/mix.exs | 2 +- app/mix.lock | 4 ++-- .../20190920155454_create_file_sets.exs | 2 +- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/lib/meadow/data/csv/import.ex b/app/lib/meadow/data/csv/import.ex index 0348aa677..8367f0f02 100644 --- a/app/lib/meadow/data/csv/import.ex +++ b/app/lib/meadow/data/csv/import.ex @@ -119,6 +119,7 @@ defmodule Meadow.Data.CSV.Import do defp add_scheme(value, _), do: value defp decode_field({:array, _}, nil), do: [] + defp decode_field({type, {schema, spec}}, value), do: decode_field({type, schema, spec}, value) defp decode_field({_, _, %Ecto.Embedded{cardinality: :many, related: _}}, nil), do: [] defp decode_field({_, _, %Ecto.Embedded{cardinality: :one, related: _}}, nil), do: nil defp decode_field(_, nil), do: nil diff --git a/app/lib/meadow/data/schemas/types/edtf_date.ex b/app/lib/meadow/data/schemas/types/edtf_date.ex index 21b8a2320..8608463ef 100644 --- a/app/lib/meadow/data/schemas/types/edtf_date.ex +++ b/app/lib/meadow/data/schemas/types/edtf_date.ex @@ -37,9 +37,11 @@ defmodule Meadow.Data.Types.EDTFDate do defp humanize(%{edtf: edtf}), do: humanize(edtf) + defp humanize(""), do: {:error, message: "cannot be blank"} + defp humanize(edtf) when is_binary(edtf) do case EDTF.humanize(edtf) do - {:error, error} -> {:error, message: error} + {:error, _} -> :error result -> {:ok, %{edtf: edtf, humanized: result}} end end diff --git a/app/lib/meadow/data/schemas/validations.ex b/app/lib/meadow/data/schemas/validations.ex index 70454f81d..3e4373f18 100644 --- a/app/lib/meadow/data/schemas/validations.ex +++ b/app/lib/meadow/data/schemas/validations.ex @@ -10,18 +10,13 @@ defmodule Meadow.Data.Schemas.Validations do """ def prepare_embed(%Ecto.Changeset{data: data, params: params} = change, field) when is_atom(field) do - empty_struct = fn -> - {:parameterized, _type, field_spec} = data.__struct__.__schema__(:type, field) - field_spec.related.__struct__ |> Map.from_struct() - end - with f <- to_string(field), current <- Enum.find([field, f], &Map.get(data, &1)) do value = cond do - Map.has_key?(params, f) and is_nil(Map.get(params, f)) -> empty_struct.() + Map.has_key?(params, f) and is_nil(Map.get(params, f)) -> empty_struct(data, field) Map.has_key?(params, f) -> Map.get(params, f) - is_nil(current) -> empty_struct.() + is_nil(current) -> empty_struct(data, field) true -> nil end @@ -35,4 +30,14 @@ defmodule Meadow.Data.Schemas.Validations do end end end + + defp empty_struct(data, field) do + field_spec = + case data.__struct__.__schema__(:type, field) do + {:parameterized, _type, f} -> f + {:parameterized, {_type, f}} -> f + end + + field_spec.related.__struct__ |> Map.from_struct() + end end diff --git a/app/mix.exs b/app/mix.exs index c76fd1b01..55ef3744d 100644 --- a/app/mix.exs +++ b/app/mix.exs @@ -64,7 +64,7 @@ defmodule Meadow.MixProject do {:dataloader, "~> 1.0.6"}, {:ecto_enum, "~> 1.4.0"}, {:ecto_psql_extras, "~> 0.2"}, - {:ecto_ranked, "~> 0.5.0"}, + {:ecto_ranked, "~> 0.5"}, {:ecto_sql, "~> 3.0 and >= 3.4.4"}, {:elastix, "~> 0.10.0"}, {:ets, "~> 0.9.0"}, diff --git a/app/mix.lock b/app/mix.lock index 9af53a3ab..a26f62fbb 100644 --- a/app/mix.lock +++ b/app/mix.lock @@ -24,10 +24,10 @@ "dataloader": {:hex, :dataloader, "1.0.11", "49bbfc7dd8a1990423c51000b869b1fecaab9e3ccd6b29eab51616ae8ad0a2f5", [:mix], [{:ecto, ">= 3.4.3 and < 4.0.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:telemetry, "~> 1.0 or ~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ba0b0ec532ec68e9d033d03553561d693129bd7cbd5c649dc7903f07ffba08fe"}, "db_connection": {:hex, :db_connection, "2.7.0", "b99faa9291bb09892c7da373bb82cba59aefa9b36300f6145c5f201c7adf48ec", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "dcf08f31b2701f857dfc787fbad78223d61a32204f217f15e881dd93e4bdd3ff"}, "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, - "ecto": {:hex, :ecto, "3.12.1", "626765f7066589de6fa09e0876a253ff60c3d00870dd3a1cd696e2ba67bfceea", [: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", "df0045ab9d87be947228e05a8d153f3e06e0d05ab10c3b3cc557d2f7243d1940"}, + "ecto": {:hex, :ecto, "3.12.3", "1a9111560731f6c3606924c81c870a68a34c819f6d4f03822f370ea31a582208", [: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", "9efd91506ae722f95e48dc49e70d0cb632ede3b7a23896252a60a14ac6d59165"}, "ecto_enum": {:hex, :ecto_enum, "1.4.0", "d14b00e04b974afc69c251632d1e49594d899067ee2b376277efd8233027aec8", [:mix], [{:ecto, ">= 3.0.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "> 3.0.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:mariaex, ">= 0.0.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "8fb55c087181c2b15eee406519dc22578fa60dd82c088be376d0010172764ee4"}, "ecto_psql_extras": {:hex, :ecto_psql_extras, "0.8.1", "cdfee5cb21d51af37d14233e4aa3ef38189bf42c499d6a8160a943c990cc74e2", [:mix], [{:ecto_sql, "~> 3.7", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:postgrex, "> 0.16.0 and < 0.20.0", [hex: :postgrex, repo: "hexpm", optional: false]}, {:table_rex, "~> 3.1.1 or ~> 4.0.0", [hex: :table_rex, repo: "hexpm", optional: false]}], "hexpm", "c0a1df8181c87a0419afa881452329a9dfd2c1fb2a737bf147f862dfa44a1af0"}, - "ecto_ranked": {:hex, :ecto_ranked, "0.5.0", "0e428901fe4586f6561b039b90b44940383e90da534b1842a728b56b076fdd68", [:mix], [{:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}], "hexpm", "7f9e119539aca2cf6d98916409e592c884f89069014b7731db1f42483da7e192"}, + "ecto_ranked": {:hex, :ecto_ranked, "0.6.0", "c3bc7925610244d3f0be01befb02991670c00f32890174392f2701f760124b26", [:mix], [{:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}], "hexpm", "735dd6e02096445f4084e0f76e1d0e100cdcf5386d40d6d4cb7e54f2d437fb27"}, "ecto_sql": {:hex, :ecto_sql, "3.12.0", "73cea17edfa54bde76ee8561b30d29ea08f630959685006d9c6e7d1e59113b7d", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.12", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.19 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", "dc9e4d206f274f3947e96142a8fdc5f69a2a6a9abb4649ef5c882323b6d512f0"}, "elastix": {:hex, :elastix, "0.10.0", "7567da885677ba9deffc20063db5f3ca8cd10f23cff1ab3ed9c52b7063b7e340", [:mix], [{:httpoison, "~> 1.4", [hex: :httpoison, repo: "hexpm", optional: false]}, {:poison, "~> 3.0 or ~> 4.0", [hex: :poison, repo: "hexpm", optional: true]}, {:retry, "~> 0.8", [hex: :retry, repo: "hexpm", optional: false]}], "hexpm", "5fb342ce068b20f7845f5dd198c2dc80d967deafaa940a6e51b846db82696d1d"}, "eternal": {:hex, :eternal, "1.2.2", "d1641c86368de99375b98d183042dd6c2b234262b8d08dfd72b9eeaafc2a1abd", [:mix], [], "hexpm", "2c9fe32b9c3726703ba5e1d43a1d255a4f3f2d8f8f9bc19f094c7cb1a7a9e782"}, diff --git a/app/priv/repo/migrations/20190920155454_create_file_sets.exs b/app/priv/repo/migrations/20190920155454_create_file_sets.exs index e95437acd..425d356c8 100644 --- a/app/priv/repo/migrations/20190920155454_create_file_sets.exs +++ b/app/priv/repo/migrations/20190920155454_create_file_sets.exs @@ -9,7 +9,7 @@ defmodule Meadow.Repo.Migrations.CreateFileSets do add(:extracted_metadata, :map, default: %{}) add(:structural_metadata, :map, default: %{}) add(:derivatives, :map, default: %{}) - add(:work_id, references(:works, null: false, on_delete: :delete_all)) + add(:work_id, references(:works, on_delete: :delete_all)) add(:rank, :integer) add(:poster_offset, :integer)