github.com/supabase/cli@v1.168.1/internal/migration/squash/testdata/after.sql (about)

     1  
     2  SET statement_timeout = 0;
     3  SET lock_timeout = 0;
     4  SET idle_in_transaction_session_timeout = 0;
     5  SET client_encoding = 'UTF8';
     6  SET standard_conforming_strings = on;
     7  SELECT pg_catalog.set_config('search_path', '', false);
     8  SET check_function_bodies = false;
     9  SET xmloption = content;
    10  SET client_min_messages = warning;
    11  SET row_security = off;
    12  
    13  CREATE SCHEMA IF NOT EXISTS "storage";
    14  
    15  ALTER SCHEMA "storage" OWNER TO "supabase_admin";
    16  
    17  CREATE OR REPLACE FUNCTION "storage"."can_insert_object"("bucketid" "text", "name" "text", "owner" "uuid", "metadata" "jsonb") RETURNS "void"
    18      LANGUAGE "plpgsql"
    19      AS $$
    20  BEGIN
    21    INSERT INTO "storage"."objects" ("bucket_id", "name", "owner", "metadata") VALUES (bucketid, name, owner, metadata);
    22    -- hack to rollback the successful insert
    23    RAISE sqlstate 'PT200' using
    24    message = 'ROLLBACK',
    25    detail = 'rollback successful insert';
    26  END
    27  $$;
    28  
    29  ALTER FUNCTION "storage"."can_insert_object"("bucketid" "text", "name" "text", "owner" "uuid", "metadata" "jsonb") OWNER TO "supabase_storage_admin";
    30  
    31  CREATE TABLE IF NOT EXISTS "storage"."objects" (
    32      "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL,
    33      "bucket_id" "text",
    34      "name" "text",
    35      "owner" "uuid",
    36      "created_at" timestamp with time zone DEFAULT "now"(),
    37      "updated_at" timestamp with time zone DEFAULT "now"(),
    38      "last_accessed_at" timestamp with time zone DEFAULT "now"(),
    39      "metadata" "jsonb",
    40      "path_tokens" "text"[] GENERATED ALWAYS AS ("string_to_array"("name", '/'::"text")) STORED,
    41      "version" "text",
    42      "owner_id" "text"
    43  );
    44  
    45  ALTER TABLE "storage"."objects" OWNER TO "supabase_storage_admin";
    46  
    47  COMMENT ON COLUMN "storage"."objects"."owner" IS 'Field is deprecated, use owner_id instead';
    48  
    49  ALTER TABLE ONLY "storage"."buckets"
    50      ADD CONSTRAINT "buckets_pkey" PRIMARY KEY ("id");
    51  
    52  ALTER TABLE ONLY "storage"."migrations"
    53      ADD CONSTRAINT "migrations_name_key" UNIQUE ("name");
    54  
    55  ALTER TABLE ONLY "storage"."migrations"
    56      ADD CONSTRAINT "migrations_pkey" PRIMARY KEY ("id");
    57  
    58  ALTER TABLE ONLY "storage"."objects"
    59      ADD CONSTRAINT "objects_pkey" PRIMARY KEY ("id");
    60  
    61  CREATE UNIQUE INDEX "bname" ON "storage"."buckets" USING "btree" ("name");
    62  
    63  CREATE UNIQUE INDEX "bucketid_objname" ON "storage"."objects" USING "btree" ("bucket_id", "name");
    64  
    65  CREATE INDEX "name_prefix_search" ON "storage"."objects" USING "btree" ("name" "text_pattern_ops");
    66  
    67  CREATE OR REPLACE TRIGGER "delete_images" AFTER DELETE ON "storage"."objects" FOR EACH ROW EXECUTE FUNCTION "public"."check_can_upload"();
    68  
    69  CREATE OR REPLACE TRIGGER "insert_images" AFTER INSERT ON "storage"."objects" FOR EACH ROW EXECUTE FUNCTION "public"."check_can_upload"();
    70  
    71  CREATE OR REPLACE TRIGGER "update_objects_updated_at" BEFORE UPDATE ON "storage"."objects" FOR EACH ROW EXECUTE FUNCTION "storage"."update_updated_at_column"();
    72  
    73  ALTER TABLE ONLY "storage"."objects"
    74      ADD CONSTRAINT "objects_bucketId_fkey" FOREIGN KEY ("bucket_id") REFERENCES "storage"."buckets"("id");
    75  
    76  ALTER TABLE ONLY "storage"."objects"
    77      ADD CONSTRAINT "objects_owner_fkey" FOREIGN KEY ("owner") REFERENCES "auth"."users"("id");
    78  
    79  CREATE POLICY "Anyone can read owner" ON "storage"."objects" FOR SELECT USING ((("bucket_id" = 'public-images'::"text") AND ("owner" IS NULL)));
    80  
    81  CREATE POLICY "Authenticated users can delete images" ON "storage"."objects" FOR DELETE TO "authenticated" USING ((("bucket_id" = 'public-images'::"text") AND ("auth"."uid"() = "owner")));
    82  
    83  CREATE POLICY "Authenticated users can insert images" ON "storage"."objects" FOR INSERT TO "authenticated" WITH CHECK ((("bucket_id" = 'public-images'::"text") AND ("auth"."uid"() = "owner")));
    84  
    85  CREATE POLICY "Authenticated users can read images" ON "storage"."objects" FOR SELECT TO "authenticated" USING ((("bucket_id" = 'public-images'::"text") AND ("auth"."uid"() = "owner")));
    86  
    87  CREATE POLICY "Authenticated users can update images" ON "storage"."objects" FOR UPDATE TO "authenticated" USING (("bucket_id" = 'public-images'::"text")) WITH CHECK (("auth"."uid"() = "owner"));
    88  
    89  ALTER TABLE "storage"."buckets" ENABLE ROW LEVEL SECURITY;
    90  
    91  ALTER TABLE "storage"."migrations" ENABLE ROW LEVEL SECURITY;
    92  
    93  ALTER TABLE "storage"."objects" ENABLE ROW LEVEL SECURITY;
    94  
    95  CREATE POLICY "objects_auth_select" ON "storage"."objects" FOR SELECT TO "authenticated" USING (("owner" = "auth"."uid"()));
    96  
    97  GRANT ALL ON SCHEMA "storage" TO "postgres";
    98  GRANT USAGE ON SCHEMA "storage" TO "anon";
    99  GRANT USAGE ON SCHEMA "storage" TO "authenticated";
   100  GRANT USAGE ON SCHEMA "storage" TO "service_role";
   101  GRANT ALL ON SCHEMA "storage" TO "supabase_storage_admin";
   102  GRANT ALL ON SCHEMA "storage" TO "dashboard_user";
   103  
   104  ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "storage" GRANT ALL ON SEQUENCES  TO "postgres";
   105  ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "storage" GRANT ALL ON SEQUENCES  TO "anon";
   106  ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "storage" GRANT ALL ON SEQUENCES  TO "authenticated";
   107  ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "storage" GRANT ALL ON SEQUENCES  TO "service_role";
   108  
   109  RESET ALL;