Skip to content

Commit

Permalink
Sqaush migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesTaylor7 committed May 12, 2024
1 parent ce111b4 commit 647622f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 135 deletions.
57 changes: 0 additions & 57 deletions supabase/migrations/20240509152702_remote_schema.sql

This file was deleted.

61 changes: 0 additions & 61 deletions supabase/migrations/20240511155803_remote_schema.sql

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
Expand All @@ -9,6 +10,8 @@ SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

CREATE EXTENSION IF NOT EXISTS "pg_net" WITH SCHEMA "extensions";

CREATE EXTENSION IF NOT EXISTS "pgsodium" WITH SCHEMA "pgsodium";

COMMENT ON SCHEMA "public" IS 'standard public schema';
Expand All @@ -29,26 +32,28 @@ SET default_tablespace = '';

SET default_table_access_method = "heap";

CREATE TABLE "public"."game_districts" (
CREATE TABLE IF NOT EXISTS "public"."game_districts" (
"positions" "jsonb" DEFAULT '{}'::"jsonb" NOT NULL,
"game_id" bigint NOT NULL,
"user_id" "uuid" DEFAULT "auth"."uid"() NOT NULL
);

ALTER TABLE "public"."game_districts" OWNER TO "postgres";

CREATE TABLE "public"."game_hands" (
CREATE TABLE IF NOT EXISTS "public"."game_hands" (
"game_id" bigint NOT NULL,
"user_id" "uuid" DEFAULT "auth"."uid"() NOT NULL,
"districts" "text"[] NOT NULL
);

ALTER TABLE "public"."game_hands" OWNER TO "postgres";

CREATE TABLE "public"."games" (
CREATE TABLE IF NOT EXISTS "public"."games" (
"id" bigint NOT NULL,
"created_at" timestamp with time zone DEFAULT "now"() NOT NULL,
"state" "jsonb" NOT NULL
"state" "jsonb" NOT NULL,
"ended_at" timestamp with time zone,
"started_at" timestamp with time zone DEFAULT "now"() NOT NULL,
"version" bigint NOT NULL
);

ALTER TABLE "public"."games" OWNER TO "postgres";
Expand All @@ -62,11 +67,21 @@ ALTER TABLE "public"."games" ALTER COLUMN "id" ADD GENERATED BY DEFAULT AS IDENT
CACHE 1
);

CREATE TABLE "public"."rooms" (
CREATE TABLE IF NOT EXISTS "public"."profiles" (
"user_id" "uuid" DEFAULT "auth"."uid"() NOT NULL,
"created_at" timestamp with time zone DEFAULT "now"() NOT NULL,
"username" character varying NOT NULL
);

ALTER TABLE "public"."profiles" OWNER TO "postgres";

CREATE TABLE IF NOT EXISTS "public"."rooms" (
"id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL,
"created_at" timestamp with time zone DEFAULT "now"() NOT NULL,
"owner_id" "uuid" DEFAULT "auth"."uid"() NOT NULL,
"game_id" bigint
"game_id" bigint,
"game_config" "jsonb" NOT NULL,
"host_id" "uuid" DEFAULT "auth"."uid"() NOT NULL,
"player_ids" "text"[] DEFAULT '{auth.uid()::text}'::"text"[] NOT NULL
);

ALTER TABLE "public"."rooms" OWNER TO "postgres";
Expand All @@ -80,8 +95,14 @@ ALTER TABLE ONLY "public"."game_hands"
ALTER TABLE ONLY "public"."games"
ADD CONSTRAINT "games_pkey" PRIMARY KEY ("id");

ALTER TABLE ONLY "public"."profiles"
ADD CONSTRAINT "profiles_pkey" PRIMARY KEY ("user_id");

ALTER TABLE ONLY "public"."profiles"
ADD CONSTRAINT "profiles_username_key" UNIQUE ("username");

ALTER TABLE ONLY "public"."rooms"
ADD CONSTRAINT "rooms_owner_id_key" UNIQUE ("owner_id");
ADD CONSTRAINT "rooms_owner_id_key" UNIQUE ("host_id");

ALTER TABLE ONLY "public"."rooms"
ADD CONSTRAINT "rooms_pkey" PRIMARY KEY ("id");
Expand All @@ -90,32 +111,45 @@ ALTER TABLE ONLY "public"."game_districts"
ADD CONSTRAINT "game_districts_game_id_fkey" FOREIGN KEY ("game_id") REFERENCES "public"."games"("id");

ALTER TABLE ONLY "public"."game_districts"
ADD CONSTRAINT "game_districts_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "auth"."users"("id");
ADD CONSTRAINT "game_districts_user_id_fkey1" FOREIGN KEY ("user_id") REFERENCES "public"."profiles"("user_id");

ALTER TABLE ONLY "public"."game_hands"
ADD CONSTRAINT "game_hands_game_id_fkey" FOREIGN KEY ("game_id") REFERENCES "public"."games"("id");

ALTER TABLE ONLY "public"."game_hands"
ADD CONSTRAINT "game_hands_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "auth"."users"("id");

ALTER TABLE ONLY "public"."game_hands"
ADD CONSTRAINT "hands_game_id_fkey" FOREIGN KEY ("game_id") REFERENCES "public"."games"("id");
ADD CONSTRAINT "game_hands_user_id_fkey1" FOREIGN KEY ("user_id") REFERENCES "public"."profiles"("user_id");

ALTER TABLE ONLY "public"."game_hands"
ADD CONSTRAINT "hands_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "auth"."users"("id");
ALTER TABLE ONLY "public"."profiles"
ADD CONSTRAINT "profiles_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "auth"."users"("id") ON DELETE CASCADE;

ALTER TABLE ONLY "public"."rooms"
ADD CONSTRAINT "rooms_game_id_fkey" FOREIGN KEY ("game_id") REFERENCES "public"."games"("id");

ALTER TABLE ONLY "public"."rooms"
ADD CONSTRAINT "rooms_owner_id_fkey" FOREIGN KEY ("owner_id") REFERENCES "auth"."users"("id");
ADD CONSTRAINT "rooms_host_id_fkey1" FOREIGN KEY ("host_id") REFERENCES "public"."profiles"("user_id");

CREATE POLICY "Anyone can view" ON "public"."rooms" AS RESTRICTIVE FOR SELECT USING (true);

CREATE POLICY "Anyone can view city district positions" ON "public"."game_districts" FOR SELECT USING (true);

CREATE POLICY "Owner can close room" ON "public"."rooms" FOR DELETE USING (("host_id" = "auth"."uid"()));

CREATE POLICY "Owner can create room" ON "public"."rooms" FOR INSERT WITH CHECK (("host_id" = "auth"."uid"()));

CREATE POLICY "Owner can move districts in their city" ON "public"."game_districts" FOR UPDATE USING (("user_id" = "auth"."uid"()));

CREATE POLICY "Owner can update room ( to kick players)" ON "public"."rooms" AS RESTRICTIVE FOR UPDATE USING (("host_id" = "auth"."uid"()));

CREATE POLICY "Owner can view their hands" ON "public"."game_hands" FOR SELECT USING (("user_id" = "auth"."uid"()));

ALTER TABLE "public"."game_districts" ENABLE ROW LEVEL SECURITY;

ALTER TABLE "public"."game_hands" ENABLE ROW LEVEL SECURITY;

ALTER TABLE "public"."games" ENABLE ROW LEVEL SECURITY;

ALTER TABLE "public"."profiles" ENABLE ROW LEVEL SECURITY;

ALTER TABLE "public"."rooms" ENABLE ROW LEVEL SECURITY;

ALTER PUBLICATION "supabase_realtime" OWNER TO "postgres";
Expand All @@ -141,6 +175,10 @@ GRANT ALL ON SEQUENCE "public"."games_id_seq" TO "anon";
GRANT ALL ON SEQUENCE "public"."games_id_seq" TO "authenticated";
GRANT ALL ON SEQUENCE "public"."games_id_seq" TO "service_role";

GRANT ALL ON TABLE "public"."profiles" TO "anon";
GRANT ALL ON TABLE "public"."profiles" TO "authenticated";
GRANT ALL ON TABLE "public"."profiles" TO "service_role";

GRANT ALL ON TABLE "public"."rooms" TO "anon";
GRANT ALL ON TABLE "public"."rooms" TO "authenticated";
GRANT ALL ON TABLE "public"."rooms" TO "service_role";
Expand All @@ -161,3 +199,8 @@ ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TAB
ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "service_role";

RESET ALL;

--
-- Dumped schema changes for auth and storage
--

0 comments on commit 647622f

Please sign in to comment.