mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 21:43:12 +12:00
60 lines
1.8 KiB
Elixir
60 lines
1.8 KiB
Elixir
defmodule AshPostgres.TestRepo.Migrations.InstallAshFunctions 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("""
|
|
ALTER FUNCTION ash_elixir_or(left BOOLEAN, in right ANYCOMPATIBLE, out f1 ANYCOMPATIBLE) IMMUTABLE
|
|
""")
|
|
|
|
execute("""
|
|
ALTER FUNCTION ash_elixir_or(left ANYCOMPATIBLE, in right ANYCOMPATIBLE, out f1 ANYCOMPATIBLE) IMMUTABLE
|
|
""")
|
|
|
|
execute("""
|
|
ALTER FUNCTION ash_elixir_and(left BOOLEAN, in right ANYCOMPATIBLE, out f1 ANYCOMPATIBLE) IMMUTABLE
|
|
""")
|
|
|
|
execute("""
|
|
ALTER FUNCTION ash_elixir_and(left ANYCOMPATIBLE, in right ANYCOMPATIBLE, out f1 ANYCOMPATIBLE) 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;
|
|
""")
|
|
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_elixir_and(BOOLEAN, ANYCOMPATIBLE), ash_elixir_and(ANYCOMPATIBLE, ANYCOMPATIBLE), ash_elixir_or(ANYCOMPATIBLE, ANYCOMPATIBLE), ash_elixir_or(BOOLEAN, ANYCOMPATIBLE)"
|
|
)
|
|
end
|
|
end
|