./migrations/047a51b_to_49bed63.sql

This commit is contained in:
Orion Kindel 2023-07-17 14:13:48 -04:00
parent e3283d6fdf
commit 61933c88d3
Signed by untrusted user who does not match committer: orion
GPG Key ID: 6D4165AE4C928719

37
047a51b_to_49bed63.sql Normal file
View File

@ -0,0 +1,37 @@
drop type "public"."usr_username";
set check_function_bodies = off;
CREATE OR REPLACE FUNCTION public.create_newtype_text(qualified_name text)
RETURNS void
LANGUAGE plpgsql
AS $function$
begin
execute concat('create type ', qualified_name, ' as (str text);');
execute concat( 'create function '
, qualified_name || '_to_string(val ' || qualified_name || ')'
, E' returns text language sql as \'select (val.str);\';'
);
execute concat( 'create function '
, qualified_name || '_of_string(val text)'
, ' returns ' || qualified_name || E' language sql as \'select row(val);\';'
);
end;
$function$
;
CREATE OR REPLACE FUNCTION public.usr_username_of_string(val text)
RETURNS usr_username
LANGUAGE sql
AS $function$select row(val);$function$
;
CREATE OR REPLACE FUNCTION public.usr_username_to_string(val usr_username)
RETURNS text
LANGUAGE sql
AS $function$select (val.str);$function$
;
create type "public"."usr_username" as ("str" text);