Supabase Self-Hosted not load correctly postgres schema
See original GitHub issueBug report
Describe the bug
I have those functions:
-- Set up is_member_of function
CREATE FUNCTION is_member_of(_user_email text, _channel_id int8) RETURNS bool AS $$
SELECT EXISTS (
SELECT 1
FROM public.channel_users cu
WHERE cu.channel_id::int8 = _channel_id::int8
AND cu.user_mail::text = _user_email::text
);
$$ LANGUAGE sql SECURITY DEFINER;
-- Set up is_admin function
CREATE FUNCTION is_admin(_user_email text) RETURNS bool AS $$
SELECT EXISTS (
SELECT 1
FROM auth.users u
WHERE u.email::text = _user_email
AND u.raw_user_meta_data->>'role' = 'admin'
);
$$ LANGUAGE sql SECURITY DEFINER;
-- Set up get_channel_list function
CREATE FUNCTION public.get_channel_list(mail text)
RETURNS TABLE(id bigint, created_at timestamp with time zone, starter_email character varying, shop_id bigint, logo character varying, name character varying, total_message bigint, last_message_read bigint, to_read bigint)
LANGUAGE plpgsql
AS $function$
begin
return query
select init.id,init.created_at,init.starter_mail,init.shop_id,init.logo,init.name,init.total_messages,
(case when init.last_message_read > 0 then init.last_message_read else 0 end) as last_message_read,
(select count(cm2.id) from public.channel_messages cm2 where cm2.id > init.last_message_read) to_read
from
(
select *,
(select count(cm.id) from public.channel_messages cm where cm.channel_id = c.id ) as total_messages,
(select cu.last_message_read from public.channel_users cu where cu.channel_id = c.id and cu.user_mail = mail ) as last_message_read
from public.channel as c
) as init
order by init.shop_id asc, to_read desc, init.total_messages desc;
end
$function$
;
-- Set up get_channel_list_shop function
CREATE FUNCTION public.get_channel_list_shop(mail text, shopID int8)
RETURNS TABLE(id bigint, created_at timestamp with time zone, starter_email character varying, shop_id bigint, logo character varying, name character varying, total_message bigint, last_message_read bigint, to_read bigint)
LANGUAGE plpgsql
AS $function$
begin
return query
select init.id,init.created_at,init.starter_mail,init.shop_id,init.logo,init.name,init.total_messages,
(case when init.last_message_read > 0 then init.last_message_read else 0 end) as last_message_read,
(select count(cm2.id) from public.channel_messages cm2 where cm2.id > init.last_message_read) to_read
from
(
select *,
(select count(cm.id) from public.channel_messages cm where cm.channel_id = c.id ) as total_messages,
(select cu.last_message_read from public.channel_users cu where cu.channel_id = c.id and cu.user_mail = mail ) as last_message_read
from public.channel as c
where c.shop_id = shopID
) as init
order by init.shop_id asc, to_read desc, init.total_messages desc;
end
$function$
;
-- Set up get_channel_list_user function
CREATE FUNCTION public.get_channel_list_user(mail text)
RETURNS TABLE(id bigint, created_at timestamp with time zone, starter_email character varying, shop_id bigint, logo character varying, name character varying, total_message bigint, last_message_read bigint, to_read bigint)
LANGUAGE plpgsql
AS $function$
begin
return query
select init.id,init.created_at,init.starter_mail,init.shop_id,init.logo,init.name,init.total_messages,
(case when init.last_message_read > 0 then init.last_message_read else 0 end) as last_message_read,
(select count(cm2.id) from public.channel_messages cm2 where cm2.id > init.last_message_read) to_read
from
(
select *,
(select count(cm.id) from public.channel_messages cm where cm.channel_id = c.id ) as total_messages,
(select cu.last_message_read from public.channel_users cu where cu.channel_id = c.id and cu.user_mail = mail ) as last_message_read
from public.channel as c
where c.starter_mail = mail
) as init
order by init.shop_id asc, to_read desc, init.total_messages desc;
end
$function$
;
-- Set up get_specific_channel_data function
CREATE FUNCTION public.get_specific_channel_data(mail text, cid int8)
RETURNS TABLE(id bigint, created_at timestamp with time zone, starter_email character varying, shop_id bigint, logo character varying, name character varying, total_message bigint, last_message_read bigint, to_read bigint)
LANGUAGE plpgsql
AS $function$
begin
return query
select init.id,init.created_at,init.starter_mail,init.shop_id,init.logo,init.name,init.total_messages,
(case when init.last_message_read > 0 then init.last_message_read else 0 end) as last_message_read,
(select count(cm2.id) from public.channel_messages cm2 where cm2.id > init.last_message_read) to_read
from
(
select *,
(select count(cm.id) from public.channel_messages cm where cm.channel_id = c.id ) as total_messages,
(select cu.last_message_read from public.channel_users cu where cu.channel_id = c.id and cu.user_mail = mail ) as last_message_read
from public.channel as c
where c.id = cid
) as init
order by init.shop_id asc, to_read desc, init.total_messages desc;
end
$function$
;
But supabase load only three: get_channel_list, is_admin, is_member_of
Of course all functions exist into postgres and work perfectly if runned by SQL editor on postgres, checking the permission ect are equal of all the three loaded by supabase-studio
To Reproduce
- Execute the create function queries
- Reload the supabase-db container using: “[sudo] docker-compose restart supabase-db”
- Connect to supabase studio and go to API section
- See error
Expected behavior
I need execute those function via supabase-js using supabase.rpc function
System information
- OS: Linux
- Browser: Chrome
- Version of supabase-js: ^1.28.5
- Version of Node.js: 16.0.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Self-Hosting - Supabase
Supabase requires some Postgres extensions to be enabled by default for the API and Auth system to work. You can find the extensions...
Read more >Self-hosting with Supabase - DEV Community
Supabase is an open-source database solution based on Postgres. It includes all the standard features of Postgres with some killer additions ...
Read more >Supabase Self hosting issue - postgresql - Stack Overflow
According to their docs, they say that Supabase uses pgjwt for auth. However, AWS RDS or Azure PosrgreSQL doesnt not support pgjwt ....
Read more >External PostgreSQL database instead of a db service with ...
I'm trying to self-host Supabase , a Firebase open source alternative, ... My external db is working, I can correctly access with psql...
Read more >Supabase - User Guide - What is Jet Admin?
Supabase is an open-source Firebase alternative with an array of ... from writing queries or creating schemas using UI to simply uploading CSV...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi dbmikus,
personally I fixed in this way:
04-custom.sql
This SQL will create a function to watch schema changes and force the cache to reload schemas + the various triggers on it, for more info this is the documentation: https://postgrest.org/en/latest/schema_cache.html
Probably you will need rebuild the containers pruning the volumes
Please ignore my comment above above the filepath. I was using an old version of the Supabase CLI.