Files
drp-48/supabase/schemas/0001_study_spaces.sql

45 lines
1.3 KiB
SQL

INSERT INTO storage.buckets (id, name, public)
VALUES ('files_bucket', 'files_bucket', true);
CREATE POLICY "Whack"
ON storage.objects
FOR ALL
USING (bucket_id = 'files_bucket');
CREATE TABLE study_spaces (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
title text NOT NULL,
created_at timestamp with time zone DEFAULT now(),
updated_at timestamp with time zone DEFAULT now()
);
CREATE TABLE study_space_images (
study_space_id uuid REFERENCES study_spaces(id) ON DELETE CASCADE,
image_path text NOT NULL,
created_at timestamp with time zone DEFAULT now(),
updated_at timestamp with time zone DEFAULT now(),
PRIMARY KEY (study_space_id, image_path)
);
-- Triggers
CREATE TRIGGER study_spaces_updated_at
AFTER UPDATE ON study_spaces
FOR EACH ROW EXECUTE FUNCTION handle_updated_at();
CREATE TRIGGER study_space_images_updated_at
AFTER UPDATE ON study_space_images
FOR EACH ROW EXECUTE FUNCTION handle_updated_at();
-- Security
-- ALTER TABLE study_spaces ENABLE ROW LEVEL SECURITY;
-- ALTER TABLE study_space_images ENABLE ROW LEVEL SECURITY;
-- CREATE POLICY "Allow all users to view study spaces"
-- ON study_spaces
-- FOR SELECT
-- USING (true);
-- CREATE POLICY "Allow all users to view study space images"
-- ON study_space_images
-- FOR SELECT
-- USING (true);