diff --git a/supabase/migrations/20240000000010_squashed_file_uploads.sql b/supabase/migrations/20240000000010_squashed_file_uploads.sql index 9d96dd8..f51e4a1 100644 --- a/supabase/migrations/20240000000010_squashed_file_uploads.sql +++ b/supabase/migrations/20240000000010_squashed_file_uploads.sql @@ -1,8 +1,13 @@ --- Drop existing tables and objects if they exist -DROP TRIGGER IF EXISTS tr_file_version ON public.file_uploads; -DROP FUNCTION IF EXISTS set_file_version(); -DROP FUNCTION IF EXISTS get_next_file_version(); -DROP TABLE IF EXISTS public.file_uploads; +-- Drop existing tables and objects if they exist within DO $$ block, which will prevent errors if the table does not exist. +DO $$ +BEGIN + IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'file_uploads' AND table_schema = 'public') THEN + DROP TRIGGER IF EXISTS tr_file_version ON public.file_uploads; + DROP FUNCTION IF EXISTS set_file_version(); + DROP FUNCTION IF EXISTS get_next_file_version(); + DROP TABLE IF EXISTS public.file_uploads; + END IF; +END $$; -- Create the file_uploads table with all required columns and constraints CREATE TABLE public.file_uploads ( @@ -148,4 +153,4 @@ GRANT SELECT ON public.file_uploads TO public; GRANT ALL ON storage.objects TO authenticated; GRANT SELECT ON storage.objects TO public; GRANT ALL ON storage.buckets TO authenticated; -GRANT SELECT ON storage.buckets TO public; \ No newline at end of file +GRANT SELECT ON storage.buckets TO public;