From cfebfa278a7e205655d50eadcf9698f1991af4ea Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Thu, 29 Feb 2024 00:07:56 -0500 Subject: [PATCH] chore: fix dialyzer issue --- lib/aggregate.ex | 5 +- .../test_repo/extensions.json | 10 ++ .../20240229050455_install_5_extensions.exs | 120 ++++++++++++++++++ test_snapshot_path/test_repo/extensions.json | 10 ++ 4 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 priv/resource_snapshots/test_repo/extensions.json create mode 100644 priv/test_repo/migrations/20240229050455_install_5_extensions.exs create mode 100644 test_snapshot_path/test_repo/extensions.json diff --git a/lib/aggregate.ex b/lib/aggregate.ex index 88986c9..82d2ea8 100644 --- a/lib/aggregate.ex +++ b/lib/aggregate.ex @@ -1445,8 +1445,9 @@ defmodule AshPostgres.Aggregate do defp single_path?(resource, [relationship | rest]) do relationship = Ash.Resource.Info.relationship(resource, relationship) - (relationship.type == :belongs_to || - has_one_with_identity?(relationship)) && + !Map.get(relationship, :from_many?) && + (relationship.type == :belongs_to || + has_one_with_identity?(relationship)) && single_path?(relationship.destination, rest) end diff --git a/priv/resource_snapshots/test_repo/extensions.json b/priv/resource_snapshots/test_repo/extensions.json new file mode 100644 index 0000000..e084bbf --- /dev/null +++ b/priv/resource_snapshots/test_repo/extensions.json @@ -0,0 +1,10 @@ +{ + "installed": [ + "ash-functions", + "uuid-ossp", + "pg_trgm", + "citext", + "demo-functions_v1" + ], + "ash_functions_version": 3 +} \ No newline at end of file diff --git a/priv/test_repo/migrations/20240229050455_install_5_extensions.exs b/priv/test_repo/migrations/20240229050455_install_5_extensions.exs new file mode 100644 index 0000000..3222fd8 --- /dev/null +++ b/priv/test_repo/migrations/20240229050455_install_5_extensions.exs @@ -0,0 +1,120 @@ +defmodule AshPostgres.TestRepo.Migrations.Install5Extensions do + @moduledoc """ + Installs any extensions that are mentioned in the repo's `installed_extensions/0` callback + + This file was autogenerated with `mix ash_postgres.generate_migrations` + """ + + use Ecto.Migration + + def up do + execute(""" + CREATE OR REPLACE FUNCTION ash_elixir_or(left BOOLEAN, in right ANYCOMPATIBLE, out f1 ANYCOMPATIBLE) + AS $$ SELECT COALESCE(NULLIF($1, FALSE), $2) $$ + LANGUAGE SQL + IMMUTABLE; + """) + + execute(""" + CREATE OR REPLACE FUNCTION ash_elixir_or(left ANYCOMPATIBLE, in right ANYCOMPATIBLE, out f1 ANYCOMPATIBLE) + AS $$ SELECT COALESCE($1, $2) $$ + LANGUAGE SQL + IMMUTABLE; + """) + + execute(""" + CREATE OR REPLACE FUNCTION ash_elixir_and(left BOOLEAN, in right ANYCOMPATIBLE, out f1 ANYCOMPATIBLE) AS $$ + SELECT CASE + WHEN $1 IS TRUE THEN $2 + ELSE $1 + END $$ + LANGUAGE SQL + IMMUTABLE; + """) + + execute(""" + CREATE OR REPLACE FUNCTION ash_elixir_and(left ANYCOMPATIBLE, in right ANYCOMPATIBLE, out f1 ANYCOMPATIBLE) AS $$ + SELECT CASE + WHEN $1 IS NOT NULL THEN $2 + ELSE $1 + END $$ + LANGUAGE SQL + IMMUTABLE; + """) + + execute(""" + CREATE OR REPLACE FUNCTION ash_trim_whitespace(arr text[]) + RETURNS text[] AS $$ + DECLARE + start_index INT = 1; + end_index INT = array_length(arr, 1); + BEGIN + WHILE start_index <= end_index AND arr[start_index] = '' LOOP + start_index := start_index + 1; + END LOOP; + + WHILE end_index >= start_index AND arr[end_index] = '' LOOP + end_index := end_index - 1; + END LOOP; + + IF start_index > end_index THEN + RETURN ARRAY[]::text[]; + ELSE + RETURN arr[start_index : end_index]; + END IF; + END; $$ + LANGUAGE plpgsql + IMMUTABLE; + """) + + execute(""" + CREATE OR REPLACE FUNCTION ash_raise_error(json_data jsonb) + RETURNS BOOLEAN AS $$ + BEGIN + -- Raise an error with the provided JSON data. + -- The JSON object is converted to text for inclusion in the error message. + RAISE EXCEPTION 'ash_error: %', json_data::text; + RETURN NULL; + END; + $$ LANGUAGE plpgsql; + """) + + execute(""" + CREATE OR REPLACE FUNCTION ash_raise_error(json_data jsonb, type_signal ANYCOMPATIBLE) + RETURNS ANYCOMPATIBLE AS $$ + BEGIN + -- Raise an error with the provided JSON data. + -- The JSON object is converted to text for inclusion in the error message. + RAISE EXCEPTION 'ash_error: %', json_data::text; + RETURN NULL; + END; + $$ LANGUAGE plpgsql; + """) + + execute("CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\"") + execute("CREATE EXTENSION IF NOT EXISTS \"pg_trgm\"") + execute("CREATE EXTENSION IF NOT EXISTS \"citext\"") + + execute(""" + CREATE OR REPLACE FUNCTION ash_demo_functions() + RETURNS boolean AS $$ SELECT FALSE $$ + LANGUAGE SQL + IMMUTABLE; + """) + end + + def down do + # Uncomment this if you actually want to uninstall the extensions + # when this migration is rolled back: + execute( + "DROP FUNCTION IF EXISTS ash_raise_error(jsonb), ash_raise_error(jsonb, ANYCOMPATIBLE), ash_elixir_and(BOOLEAN, ANYCOMPATIBLE), ash_elixir_and(ANYCOMPATIBLE, ANYCOMPATIBLE), ash_elixir_or(ANYCOMPATIBLE, ANYCOMPATIBLE), ash_elixir_or(BOOLEAN, ANYCOMPATIBLE) ash_trim_whitespace(text[])" + ) + + # execute("DROP EXTENSION IF EXISTS \"uuid-ossp\"") + # execute("DROP EXTENSION IF EXISTS \"pg_trgm\"") + # execute("DROP EXTENSION IF EXISTS \"citext\"") + execute(""" + DROP FUNCTION IF EXISTS ash_demo_functions() + """) + end +end \ No newline at end of file diff --git a/test_snapshot_path/test_repo/extensions.json b/test_snapshot_path/test_repo/extensions.json new file mode 100644 index 0000000..e084bbf --- /dev/null +++ b/test_snapshot_path/test_repo/extensions.json @@ -0,0 +1,10 @@ +{ + "installed": [ + "ash-functions", + "uuid-ossp", + "pg_trgm", + "citext", + "demo-functions_v1" + ], + "ash_functions_version": 3 +} \ No newline at end of file