wipe out old repo & replace with template

This commit is contained in:
2025-06-09 05:57:10 -05:00
parent 4576ebdf88
commit 5f2d25f9dd
171 changed files with 9144 additions and 4691 deletions

View File

@ -2,7 +2,7 @@
create table profiles (
id uuid references auth.users on delete cascade not null primary key,
updated_at timestamp with time zone,
email text,
email text unique,
full_name text,
avatar_url text,
provider text,
@ -35,7 +35,7 @@ begin
new.id,
new.email,
new.raw_user_meta_data->>'full_name',
new.raw_user_meta_data->>'avatar_url'
new.raw_user_meta_data->>'avatar_url',
new.raw_user_meta_data->>'provider',
now()
);
@ -58,48 +58,68 @@ create policy "Avatar images are publicly accessible." on storage.objects
create policy "Anyone can upload an avatar." on storage.objects
for insert with check (bucket_id = 'avatars');
create policy "Anyone can update an avatar." on storage.objects
for update using (bucket_id = 'avatars');
-- Create a table for public statuses
CREATE TABLE statuses (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
user_id uuid REFERENCES auth.users ON DELETE CASCADE NOT NULL,
updated_by_id uuid REFERENCES auth.users ON DELETE SET NULL DEFAULT auth.uid(),
created_at timestamp with time zone DEFAULT now() NOT NULL,
status text NOT NULL,
CONSTRAINT status_length CHECK (char_length(status) >= 3 AND char_length(status) <= 80),
CONSTRAINT statuses_user_id_fkey FOREIGN KEY (user_id) REFERENCES profiles(id) ON DELETE CASCADE
);
create policy "Anyone can delete an avatar." on storage.objects
for delete using (bucket_id = 'avatars');
-- Set up Row Level Security (RLS)
ALTER TABLE statuses
ENABLE ROW LEVEL SECURITY;
-- -- Create a table for public statuses
-- CREATE TABLE statuses (
-- id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
-- user_id uuid REFERENCES auth.users ON DELETE CASCADE NOT NULL,
-- updated_by_id uuid REFERENCES auth.users ON DELETE SET NULL DEFAULT auth.uid(),
-- created_at timestamp with time zone DEFAULT now() NOT NULL,
-- status text NOT NULL,
-- CONSTRAINT status_length CHECK (char_length(status) >= 3 AND char_length(status) <= 80)
-- );
-- Policies
CREATE POLICY "Public statuses are viewable by everyone." ON statuses
FOR SELECT USING (true);
-- -- Set up Row Level Security (RLS)
-- ALTER TABLE statuses
-- ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Users can insert statuses for any user." ON statuses
FOR INSERT WITH CHECK (auth.role() = 'authenticated');
-- -- Policies
-- CREATE POLICY "Public statuses are viewable by everyone." ON statuses
-- FOR SELECT USING (true);
-- Function to add first status
CREATE FUNCTION public.handle_first_status()
RETURNS TRIGGER
SET search_path = ''
AS $$
BEGIN
INSERT INTO public.statuses (user_id, updated_by_id, status)
VALUES (
NEW.id,
NEW.id,
'Just joined!'
);
RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
-- -- RECREATE it using the recommended sub-select form
-- CREATE POLICY "Authenticated users can insert statuses for any user."
-- ON public.statuses
-- FOR INSERT
-- WITH CHECK (
-- (SELECT auth.role()) = 'authenticated'
-- );
-- Create a separate trigger for the status
CREATE TRIGGER on_auth_user_created_add_status
AFTER INSERT ON auth.users
FOR EACH ROW EXECUTE PROCEDURE public.handle_first_status();
-- -- ADD an UPDATE policy so anyone signed-in can update *any* status
-- CREATE POLICY "Authenticated users can update statuses for any user."
-- ON public.statuses
-- FOR UPDATE
-- USING (
-- (SELECT auth.role()) = 'authenticated'
-- )
-- WITH CHECK (
-- (SELECT auth.role()) = 'authenticated'
-- );
alter publication supabase_realtime add table statuses;
-- -- Function to add first status
-- CREATE FUNCTION public.handle_first_status()
-- RETURNS TRIGGER
-- SET search_path = ''
-- AS $$
-- BEGIN
-- INSERT INTO public.statuses (user_id, updated_by_id, status)
-- VALUES (
-- NEW.id,
-- NEW.id,
-- 'Just joined!'
-- );
-- RETURN NEW;
-- END;
-- $$ LANGUAGE plpgsql SECURITY DEFINER;
-- -- Create a separate trigger for the status
-- CREATE TRIGGER on_auth_user_created_add_status
-- AFTER INSERT ON auth.users
-- FOR EACH ROW EXECUTE PROCEDURE public.handle_first_status();
-- alter publication supabase_realtime add table statuses;