mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 21:43:12 +12:00
49 lines
1.5 KiB
Elixir
49 lines
1.5 KiB
Elixir
|
defmodule :"Elixir.AshPostgres.TestRepo.Migrations.InstallAsh-functions" 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;
|
||
|
""")
|
||
|
|
||
|
execute("""
|
||
|
CREATE OR REPLACE FUNCTION ash_elixir_or(left ANYCOMPATIBLE, in right ANYCOMPATIBLE, out f1 ANYCOMPATIBLE)
|
||
|
AS $$ SELECT COALESCE($1, $2) $$
|
||
|
LANGUAGE SQL;
|
||
|
""")
|
||
|
|
||
|
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;
|
||
|
""")
|
||
|
|
||
|
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;
|
||
|
""")
|
||
|
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
|