improvement: remove LEAKPROOF from function to prevent migration issues

chore: add some tests to show calculation w/ fragment
This commit is contained in:
Zach Daniel 2024-09-13 09:37:12 -04:00
parent ec3273f163
commit e2b648a9e4
3 changed files with 9 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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,