···11+defmodule Sower.Repo.Migrations.InstallAshFunctionsExtension320240505035410 do
22+ @moduledoc """
33+ Installs any extensions that are mentioned in the repo's `installed_extensions/0` callback
44+55+ This file was autogenerated with `mix ash_postgres.generate_migrations`
66+ """
77+88+ use Ecto.Migration
99+1010+ def up do
1111+ execute("""
1212+ CREATE OR REPLACE FUNCTION ash_elixir_or(left BOOLEAN, in right ANYCOMPATIBLE, out f1 ANYCOMPATIBLE)
1313+ AS $$ SELECT COALESCE(NULLIF($1, FALSE), $2) $$
1414+ LANGUAGE SQL
1515+ IMMUTABLE;
1616+ """)
1717+1818+ execute("""
1919+ CREATE OR REPLACE FUNCTION ash_elixir_or(left ANYCOMPATIBLE, in right ANYCOMPATIBLE, out f1 ANYCOMPATIBLE)
2020+ AS $$ SELECT COALESCE($1, $2) $$
2121+ LANGUAGE SQL
2222+ IMMUTABLE;
2323+ """)
2424+2525+ execute("""
2626+ CREATE OR REPLACE FUNCTION ash_elixir_and(left BOOLEAN, in right ANYCOMPATIBLE, out f1 ANYCOMPATIBLE) AS $$
2727+ SELECT CASE
2828+ WHEN $1 IS TRUE THEN $2
2929+ ELSE $1
3030+ END $$
3131+ LANGUAGE SQL
3232+ IMMUTABLE;
3333+ """)
3434+3535+ execute("""
3636+ CREATE OR REPLACE FUNCTION ash_elixir_and(left ANYCOMPATIBLE, in right ANYCOMPATIBLE, out f1 ANYCOMPATIBLE) AS $$
3737+ SELECT CASE
3838+ WHEN $1 IS NOT NULL THEN $2
3939+ ELSE $1
4040+ END $$
4141+ LANGUAGE SQL
4242+ IMMUTABLE;
4343+ """)
4444+4545+ execute("""
4646+ CREATE OR REPLACE FUNCTION ash_trim_whitespace(arr text[])
4747+ RETURNS text[] AS $$
4848+ DECLARE
4949+ start_index INT = 1;
5050+ end_index INT = array_length(arr, 1);
5151+ BEGIN
5252+ WHILE start_index <= end_index AND arr[start_index] = '' LOOP
5353+ start_index := start_index + 1;
5454+ END LOOP;
5555+5656+ WHILE end_index >= start_index AND arr[end_index] = '' LOOP
5757+ end_index := end_index - 1;
5858+ END LOOP;
5959+6060+ IF start_index > end_index THEN
6161+ RETURN ARRAY[]::text[];
6262+ ELSE
6363+ RETURN arr[start_index : end_index];
6464+ END IF;
6565+ END; $$
6666+ LANGUAGE plpgsql
6767+ IMMUTABLE;
6868+ """)
6969+7070+ execute("""
7171+ CREATE OR REPLACE FUNCTION ash_raise_error(json_data jsonb)
7272+ RETURNS BOOLEAN AS $$
7373+ BEGIN
7474+ -- Raise an error with the provided JSON data.
7575+ -- The JSON object is converted to text for inclusion in the error message.
7676+ RAISE EXCEPTION 'ash_error: %', json_data::text;
7777+ RETURN NULL;
7878+ END;
7979+ $$ LANGUAGE plpgsql;
8080+ """)
8181+8282+ execute("""
8383+ CREATE OR REPLACE FUNCTION ash_raise_error(json_data jsonb, type_signal ANYCOMPATIBLE)
8484+ RETURNS ANYCOMPATIBLE AS $$
8585+ BEGIN
8686+ -- Raise an error with the provided JSON data.
8787+ -- The JSON object is converted to text for inclusion in the error message.
8888+ RAISE EXCEPTION 'ash_error: %', json_data::text;
8989+ RETURN NULL;
9090+ END;
9191+ $$ LANGUAGE plpgsql;
9292+ """)
9393+ end
9494+9595+ def down do
9696+ # Uncomment this if you actually want to uninstall the extensions
9797+ # when this migration is rolled back:
9898+ execute(
9999+ "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[])"
100100+ )
101101+ end
102102+end