From e2b648a9e47bb41b4e6d1bb970b0928ede5cc043 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Fri, 13 Sep 2024 09:37:12 -0400 Subject: [PATCH] improvement: remove LEAKPROOF from function to prevent migration issues chore: add some tests to show calculation w/ fragment --- lib/migration_generator/ash_functions.ex | 2 +- test/calculation_test.exs | 4 ++++ test/support/resources/post.ex | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/migration_generator/ash_functions.ex b/lib/migration_generator/ash_functions.ex index 609bb48..369173c 100644 --- a/lib/migration_generator/ash_functions.ex +++ b/lib/migration_generator/ash_functions.ex @@ -230,7 +230,7 @@ defmodule AshPostgres.MigrationGenerator.AshFunctions do SELECT to_timestamp(('x0000' || substr(_uuid::TEXT, 1, 8) || substr(_uuid::TEXT, 10, 4))::BIT(64)::BIGINT::NUMERIC / 1000); $$ LANGUAGE SQL - IMMUTABLE PARALLEL SAFE STRICT LEAKPROOF; + IMMUTABLE PARALLEL SAFE STRICT; \"\"\") """ end diff --git a/test/calculation_test.exs b/test/calculation_test.exs index 38cc70f..0301868 100644 --- a/test/calculation_test.exs +++ b/test/calculation_test.exs @@ -312,6 +312,10 @@ defmodule AshPostgres.CalculationTest do refute Ash.calculate!(Post, :author_has_post_with_follower_named_fred, refs: %{id: post.id}) end + test "calculation works with simple fragments" do + Post.upper_title!("example") + end + test "calculations that refer to aggregates can be authorized" do post = Post diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index cbef1c1..615d1c3 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -409,6 +409,8 @@ defmodule AshPostgres.Test.Post do define(:increment_score, args: [{:optional, :amount}]) define(:destroy) define(:update_constrained_int, args: [:amount]) + + define_calculation(:upper_title, args: [:title]) end relationships do @@ -542,6 +544,8 @@ defmodule AshPostgres.Test.Post do calculations do calculate(:upper_thing, :string, expr(fragment("UPPER(?)", uniq_on_upper))) + calculate(:upper_title, :string, expr(fragment("UPPER(?)", title))) + calculate( :author_has_post_with_follower_named_fred, :boolean,