From 61933c88d3081ef962f08ecdbdc5c8f8f55893c5 Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Mon, 17 Jul 2023 14:13:48 -0400 Subject: [PATCH] ./migrations/047a51b_to_49bed63.sql --- 047a51b_to_49bed63.sql | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 047a51b_to_49bed63.sql diff --git a/047a51b_to_49bed63.sql b/047a51b_to_49bed63.sql new file mode 100644 index 0000000..037d026 --- /dev/null +++ b/047a51b_to_49bed63.sql @@ -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); + +