Skip to content

Commit a2584b7

Browse files
authored
Update DB schema (#55)
1 parent 209ba25 commit a2584b7

File tree

1 file changed

+101
-16
lines changed

1 file changed

+101
-16
lines changed

supabase/migrations/20260114193202_remote_schema.sql renamed to supabase/migrations/20260124180207_remote_schema.sql

Lines changed: 101 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ COMMENT ON SCHEMA "public" IS 'standard public schema';
1717

1818

1919

20+
CREATE EXTENSION IF NOT EXISTS "hypopg" WITH SCHEMA "extensions";
21+
22+
23+
24+
25+
26+
27+
CREATE EXTENSION IF NOT EXISTS "index_advisor" WITH SCHEMA "extensions";
28+
29+
30+
31+
32+
33+
2034
CREATE EXTENSION IF NOT EXISTS "moddatetime" WITH SCHEMA "extensions";
2135

2236

@@ -61,6 +75,7 @@ CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA "extensions";
6175

6276
CREATE OR REPLACE FUNCTION "public"."delete_user_account"() RETURNS "void"
6377
LANGUAGE "plpgsql" SECURITY DEFINER
78+
SET "search_path" TO 'public'
6479
AS $$
6580
declare
6681
requesting_user_id uuid;
@@ -112,6 +127,10 @@ CREATE TABLE IF NOT EXISTS "public"."contact_messages" (
112127
ALTER TABLE "public"."contact_messages" OWNER TO "postgres";
113128

114129

130+
COMMENT ON TABLE "public"."contact_messages" IS 'Stores Contact Messages';
131+
132+
133+
115134
CREATE TABLE IF NOT EXISTS "public"."notification" (
116135
"id" bigint NOT NULL,
117136
"created_at" timestamp with time zone DEFAULT "now"() NOT NULL,
@@ -126,6 +145,10 @@ CREATE TABLE IF NOT EXISTS "public"."notification" (
126145
ALTER TABLE "public"."notification" OWNER TO "postgres";
127146

128147

148+
COMMENT ON TABLE "public"."notification" IS 'Stores User Notifications';
149+
150+
151+
129152
ALTER TABLE "public"."notification" ALTER COLUMN "id" ADD GENERATED BY DEFAULT AS IDENTITY (
130153
SEQUENCE NAME "public"."notification_id_seq"
131154
START WITH 1
@@ -156,6 +179,10 @@ CREATE TABLE IF NOT EXISTS "public"."tracker" (
156179
ALTER TABLE "public"."tracker" OWNER TO "postgres";
157180

158181

182+
COMMENT ON TABLE "public"."tracker" IS 'Stores User-added Attendance Tracking Records';
183+
184+
185+
159186
ALTER TABLE "public"."tracker" ALTER COLUMN "id" ADD GENERATED BY DEFAULT AS IDENTITY (
160187
SEQUENCE NAME "public"."tracker_id_seq"
161188
START WITH 1
@@ -178,6 +205,10 @@ CREATE TABLE IF NOT EXISTS "public"."user_settings" (
178205
ALTER TABLE "public"."user_settings" OWNER TO "postgres";
179206

180207

208+
COMMENT ON TABLE "public"."user_settings" IS 'Stores User Settings';
209+
210+
211+
181212
CREATE TABLE IF NOT EXISTS "public"."users" (
182213
"id" bigint NOT NULL,
183214
"username" "text" NOT NULL,
@@ -195,13 +226,17 @@ CREATE TABLE IF NOT EXISTS "public"."users" (
195226
"last_synced_at" timestamp with time zone,
196227
"auth_id" "uuid",
197228
"terms_accepted_at" timestamp with time zone,
198-
"terms_version" "text"
229+
"terms_version" "text" NOT NULL
199230
);
200231

201232

202233
ALTER TABLE "public"."users" OWNER TO "postgres";
203234

204235

236+
COMMENT ON TABLE "public"."users" IS 'Stores User Information';
237+
238+
239+
205240
ALTER TABLE ONLY "public"."contact_messages"
206241
ADD CONSTRAINT "contact_messages_pkey" PRIMARY KEY ("id");
207242

@@ -213,12 +248,12 @@ ALTER TABLE ONLY "public"."notification"
213248

214249

215250
ALTER TABLE ONLY "public"."tracker"
216-
ADD CONSTRAINT "tracker_id_key" UNIQUE ("id");
251+
ADD CONSTRAINT "tracker_pkey" PRIMARY KEY ("id");
217252

218253

219254

220255
ALTER TABLE ONLY "public"."tracker"
221-
ADD CONSTRAINT "tracker_pkey" PRIMARY KEY ("id");
256+
ADD CONSTRAINT "unique_attendance_slot" UNIQUE ("auth_user_id", "course", "date", "session");
222257

223258

224259

@@ -247,6 +282,14 @@ ALTER TABLE ONLY "public"."users"
247282

248283

249284

285+
CREATE INDEX "idx_contact_messages_user" ON "public"."contact_messages" USING "btree" ("user_id");
286+
287+
288+
289+
CREATE INDEX "idx_notification_user" ON "public"."notification" USING "btree" ("auth_user_id");
290+
291+
292+
250293
CREATE INDEX "idx_users_auth_id" ON "public"."users" USING "btree" ("auth_id");
251294

252295

@@ -300,55 +343,55 @@ CREATE POLICY "Service Role Full Access" ON "public"."users" TO "service_role" U
300343

301344

302345

303-
CREATE POLICY "Users can delete own tracker" ON "public"."tracker" FOR DELETE USING (("auth_user_id" = "auth"."uid"()));
346+
CREATE POLICY "Users can delete own tracker" ON "public"."tracker" FOR DELETE USING (("auth_user_id" = ( SELECT "auth"."uid"() AS "uid")));
304347

305348

306349

307-
CREATE POLICY "Users can insert own notifications" ON "public"."notification" FOR INSERT WITH CHECK (("auth_user_id" = "auth"."uid"()));
350+
CREATE POLICY "Users can insert own notifications" ON "public"."notification" FOR INSERT WITH CHECK (("auth_user_id" = ( SELECT "auth"."uid"() AS "uid")));
308351

309352

310353

311-
CREATE POLICY "Users can insert own profile" ON "public"."users" FOR INSERT WITH CHECK (("auth_id" = "auth"."uid"()));
354+
CREATE POLICY "Users can insert own profile" ON "public"."users" FOR INSERT WITH CHECK (("auth_id" = ( SELECT "auth"."uid"() AS "uid")));
312355

313356

314357

315-
CREATE POLICY "Users can insert own settings" ON "public"."user_settings" FOR INSERT WITH CHECK (("auth"."uid"() = "user_id"));
358+
CREATE POLICY "Users can insert own settings" ON "public"."user_settings" FOR INSERT WITH CHECK (("user_id" = ( SELECT "auth"."uid"() AS "uid")));
316359

317360

318361

319-
CREATE POLICY "Users can insert own tracker" ON "public"."tracker" FOR INSERT WITH CHECK (("auth_user_id" = "auth"."uid"()));
362+
CREATE POLICY "Users can insert own tracker" ON "public"."tracker" FOR INSERT WITH CHECK (("auth_user_id" = ( SELECT "auth"."uid"() AS "uid")));
320363

321364

322365

323-
CREATE POLICY "Users can read own notification" ON "public"."notification" FOR SELECT USING (("auth_user_id" = "auth"."uid"()));
366+
CREATE POLICY "Users can read own notification" ON "public"."notification" FOR SELECT USING (("auth_user_id" = ( SELECT "auth"."uid"() AS "uid")));
324367

325368

326369

327-
CREATE POLICY "Users can read own profile" ON "public"."users" FOR SELECT TO "authenticated" USING (("auth_id" = "auth"."uid"()));
370+
CREATE POLICY "Users can read own profile" ON "public"."users" FOR SELECT TO "authenticated" USING (("auth_id" = ( SELECT "auth"."uid"() AS "uid")));
328371

329372

330373

331-
CREATE POLICY "Users can read own tracker" ON "public"."tracker" FOR SELECT USING (("auth_user_id" = "auth"."uid"()));
374+
CREATE POLICY "Users can read own tracker" ON "public"."tracker" FOR SELECT USING (("auth_user_id" = ( SELECT "auth"."uid"() AS "uid")));
332375

333376

334377

335-
CREATE POLICY "Users can see own messages" ON "public"."contact_messages" FOR SELECT TO "authenticated" USING (("auth"."uid"() = "user_id"));
378+
CREATE POLICY "Users can see own messages" ON "public"."contact_messages" FOR SELECT TO "authenticated" USING (("user_id" = ( SELECT "auth"."uid"() AS "uid")));
336379

337380

338381

339-
CREATE POLICY "Users can update own notifications" ON "public"."notification" FOR UPDATE USING (("auth_user_id" = "auth"."uid"()));
382+
CREATE POLICY "Users can update own notifications" ON "public"."notification" FOR UPDATE USING (("auth_user_id" = ( SELECT "auth"."uid"() AS "uid")));
340383

341384

342385

343-
CREATE POLICY "Users can update own profile" ON "public"."users" FOR UPDATE TO "authenticated" USING (("auth_id" = "auth"."uid"())) WITH CHECK (("auth_id" = "auth"."uid"()));
386+
CREATE POLICY "Users can update own profile" ON "public"."users" FOR UPDATE TO "authenticated" USING (("auth_id" = ( SELECT "auth"."uid"() AS "uid"))) WITH CHECK (("auth_id" = ( SELECT "auth"."uid"() AS "uid")));
344387

345388

346389

347-
CREATE POLICY "Users can update own settings" ON "public"."user_settings" FOR UPDATE USING (("auth"."uid"() = "user_id"));
390+
CREATE POLICY "Users can update own settings" ON "public"."user_settings" FOR UPDATE USING (("user_id" = ( SELECT "auth"."uid"() AS "uid")));
348391

349392

350393

351-
CREATE POLICY "Users can view own settings" ON "public"."user_settings" FOR SELECT USING (("auth"."uid"() = "user_id"));
394+
CREATE POLICY "Users can view own settings" ON "public"."user_settings" FOR SELECT USING (("user_id" = ( SELECT "auth"."uid"() AS "uid")));
352395

353396

354397

@@ -511,6 +554,42 @@ GRANT USAGE ON SCHEMA "public" TO "service_role";
511554

512555

513556

557+
558+
559+
560+
561+
562+
563+
564+
565+
566+
567+
568+
569+
570+
571+
572+
573+
574+
575+
576+
577+
578+
579+
580+
581+
582+
583+
584+
585+
586+
587+
588+
589+
590+
591+
592+
514593

515594

516595

@@ -548,6 +627,12 @@ GRANT ALL ON FUNCTION "public"."delete_user_account"() TO "service_role";
548627

549628

550629

630+
631+
632+
633+
634+
635+
551636

552637

553638

0 commit comments

Comments
 (0)