Skip to content

Commit

Permalink
Merge pull request #4166 from nulib/ecto-dependencies
Browse files Browse the repository at this point in the history
Fix some small things related to Ecto dependency updates
  • Loading branch information
mbklein authored Oct 3, 2024
2 parents 6fb2eb3 + 920bdf3 commit 1a18bb6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/lib/meadow/data/csv/import.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion app/lib/meadow/data/schemas/types/edtf_date.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions app/lib/meadow/data/schemas/validations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
2 changes: 1 addition & 1 deletion app/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
6 changes: 3 additions & 3 deletions app/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
"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.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": {: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_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"},
"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"},
"ets": {:hex, :ets, "0.9.0", "79c6a6c205436780486f72d84230c6cba2f8a9920456750ddd1e47389107d5fd", [:mix], [], "hexpm", "2861fdfb04bcaeff370f1a5904eec864f0a56dcfebe5921ea9aadf2a481c822b"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 1a18bb6

Please sign in to comment.