|
| 1 | +create table "public"."guest_poll_votes" ( |
| 2 | + "id" uuid not null default gen_random_uuid(), |
| 3 | + "guest_id" uuid, |
| 4 | + "option_id" uuid, |
| 5 | + "created_at" timestamp with time zone not null default (now() AT TIME ZONE 'utc'::text) |
| 6 | +); |
| 7 | + |
| 8 | + |
| 9 | +alter table "public"."guest_poll_votes" enable row level security; |
| 10 | + |
| 11 | +create table "public"."poll_option" ( |
| 12 | + "id" uuid not null default gen_random_uuid(), |
| 13 | + "option_value" text default ''::text, |
| 14 | + "poll_id" uuid, |
| 15 | + "created_at" timestamp with time zone not null default (now() AT TIME ZONE 'utc'::text) |
| 16 | +); |
| 17 | + |
| 18 | + |
| 19 | +alter table "public"."poll_option" enable row level security; |
| 20 | + |
| 21 | +create table "public"."polls" ( |
| 22 | + "id" uuid not null default gen_random_uuid(), |
| 23 | + "poll_name" text default ''::text, |
| 24 | + "plan_id" uuid, |
| 25 | + "created_at" timestamp with time zone not null default (now() AT TIME ZONE 'utc'::text) |
| 26 | +); |
| 27 | + |
| 28 | + |
| 29 | +alter table "public"."polls" enable row level security; |
| 30 | + |
| 31 | +create table "public"."users_poll_votes" ( |
| 32 | + "id" uuid not null default gen_random_uuid(), |
| 33 | + "option_id" uuid, |
| 34 | + "user_id" uuid, |
| 35 | + "created_at" timestamp with time zone not null default (now() AT TIME ZONE 'utc'::text) |
| 36 | +); |
| 37 | + |
| 38 | + |
| 39 | +alter table "public"."users_poll_votes" enable row level security; |
| 40 | + |
| 41 | + |
| 42 | +CREATE UNIQUE INDEX guest_poll_votes_pkey ON public.guest_poll_votes USING btree (id); |
| 43 | + |
| 44 | +CREATE UNIQUE INDEX poll_option_pkey ON public.poll_option USING btree (id); |
| 45 | + |
| 46 | +CREATE UNIQUE INDEX polls_pkey ON public.polls USING btree (id); |
| 47 | + |
| 48 | +CREATE UNIQUE INDEX users_poll_votes_pkey ON public.users_poll_votes USING btree (id); |
| 49 | + |
| 50 | +alter table "public"."guest_poll_votes" add constraint "guest_poll_votes_pkey" PRIMARY KEY using index "guest_poll_votes_pkey"; |
| 51 | + |
| 52 | +alter table "public"."poll_option" add constraint "poll_option_pkey" PRIMARY KEY using index "poll_option_pkey"; |
| 53 | + |
| 54 | +alter table "public"."polls" add constraint "polls_pkey" PRIMARY KEY using index "polls_pkey"; |
| 55 | + |
| 56 | +alter table "public"."users_poll_votes" add constraint "users_poll_votes_pkey" PRIMARY KEY using index "users_poll_votes_pkey"; |
| 57 | + |
| 58 | +alter table "public"."guest_poll_votes" add constraint "guest_poll_votes_guest_id_fkey" FOREIGN KEY (guest_id) REFERENCES meet_together_guests(id) ON UPDATE CASCADE ON DELETE CASCADE not valid; |
| 59 | + |
| 60 | +alter table "public"."guest_poll_votes" validate constraint "guest_poll_votes_guest_id_fkey"; |
| 61 | + |
| 62 | +alter table "public"."guest_poll_votes" add constraint "guest_poll_votes_option_id_fkey" FOREIGN KEY (option_id) REFERENCES poll_option(id) ON UPDATE CASCADE ON DELETE CASCADE not valid; |
| 63 | + |
| 64 | +alter table "public"."guest_poll_votes" validate constraint "guest_poll_votes_option_id_fkey"; |
| 65 | + |
| 66 | +alter table "public"."poll_option" add constraint "poll_option_poll_id_fkey" FOREIGN KEY (poll_id) REFERENCES polls(id) ON UPDATE CASCADE ON DELETE CASCADE not valid; |
| 67 | + |
| 68 | +alter table "public"."poll_option" validate constraint "poll_option_poll_id_fkey"; |
| 69 | + |
| 70 | +alter table "public"."polls" add constraint "polls_plan_id_fkey" FOREIGN KEY (plan_id) REFERENCES meet_together_plans(id) ON UPDATE CASCADE ON DELETE CASCADE not valid; |
| 71 | + |
| 72 | +alter table "public"."polls" validate constraint "polls_plan_id_fkey"; |
| 73 | + |
| 74 | +alter table "public"."users_poll_votes" add constraint "users_poll_votes_option_id_fkey" FOREIGN KEY (option_id) REFERENCES poll_option(id) ON UPDATE CASCADE ON DELETE CASCADE not valid; |
| 75 | + |
| 76 | +alter table "public"."users_poll_votes" validate constraint "users_poll_votes_option_id_fkey"; |
| 77 | + |
| 78 | +alter table "public"."users_poll_votes" add constraint "users_poll_votes_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE not valid; |
| 79 | + |
| 80 | +alter table "public"."users_poll_votes" validate constraint "users_poll_votes_user_id_fkey"; |
| 81 | + |
| 82 | +grant delete on table "public"."guest_poll_votes" to "anon"; |
| 83 | + |
| 84 | +grant insert on table "public"."guest_poll_votes" to "anon"; |
| 85 | + |
| 86 | +grant references on table "public"."guest_poll_votes" to "anon"; |
| 87 | + |
| 88 | +grant select on table "public"."guest_poll_votes" to "anon"; |
| 89 | + |
| 90 | +grant trigger on table "public"."guest_poll_votes" to "anon"; |
| 91 | + |
| 92 | +grant truncate on table "public"."guest_poll_votes" to "anon"; |
| 93 | + |
| 94 | +grant update on table "public"."guest_poll_votes" to "anon"; |
| 95 | + |
| 96 | +grant delete on table "public"."guest_poll_votes" to "authenticated"; |
| 97 | + |
| 98 | +grant insert on table "public"."guest_poll_votes" to "authenticated"; |
| 99 | + |
| 100 | +grant references on table "public"."guest_poll_votes" to "authenticated"; |
| 101 | + |
| 102 | +grant select on table "public"."guest_poll_votes" to "authenticated"; |
| 103 | + |
| 104 | +grant trigger on table "public"."guest_poll_votes" to "authenticated"; |
| 105 | + |
| 106 | +grant truncate on table "public"."guest_poll_votes" to "authenticated"; |
| 107 | + |
| 108 | +grant update on table "public"."guest_poll_votes" to "authenticated"; |
| 109 | + |
| 110 | +grant delete on table "public"."guest_poll_votes" to "service_role"; |
| 111 | + |
| 112 | +grant insert on table "public"."guest_poll_votes" to "service_role"; |
| 113 | + |
| 114 | +grant references on table "public"."guest_poll_votes" to "service_role"; |
| 115 | + |
| 116 | +grant select on table "public"."guest_poll_votes" to "service_role"; |
| 117 | + |
| 118 | +grant trigger on table "public"."guest_poll_votes" to "service_role"; |
| 119 | + |
| 120 | +grant truncate on table "public"."guest_poll_votes" to "service_role"; |
| 121 | + |
| 122 | +grant update on table "public"."guest_poll_votes" to "service_role"; |
| 123 | + |
| 124 | +grant delete on table "public"."poll_option" to "anon"; |
| 125 | + |
| 126 | +grant insert on table "public"."poll_option" to "anon"; |
| 127 | + |
| 128 | +grant references on table "public"."poll_option" to "anon"; |
| 129 | + |
| 130 | +grant select on table "public"."poll_option" to "anon"; |
| 131 | + |
| 132 | +grant trigger on table "public"."poll_option" to "anon"; |
| 133 | + |
| 134 | +grant truncate on table "public"."poll_option" to "anon"; |
| 135 | + |
| 136 | +grant update on table "public"."poll_option" to "anon"; |
| 137 | + |
| 138 | +grant delete on table "public"."poll_option" to "authenticated"; |
| 139 | + |
| 140 | +grant insert on table "public"."poll_option" to "authenticated"; |
| 141 | + |
| 142 | +grant references on table "public"."poll_option" to "authenticated"; |
| 143 | + |
| 144 | +grant select on table "public"."poll_option" to "authenticated"; |
| 145 | + |
| 146 | +grant trigger on table "public"."poll_option" to "authenticated"; |
| 147 | + |
| 148 | +grant truncate on table "public"."poll_option" to "authenticated"; |
| 149 | + |
| 150 | +grant update on table "public"."poll_option" to "authenticated"; |
| 151 | + |
| 152 | +grant delete on table "public"."poll_option" to "service_role"; |
| 153 | + |
| 154 | +grant insert on table "public"."poll_option" to "service_role"; |
| 155 | + |
| 156 | +grant references on table "public"."poll_option" to "service_role"; |
| 157 | + |
| 158 | +grant select on table "public"."poll_option" to "service_role"; |
| 159 | + |
| 160 | +grant trigger on table "public"."poll_option" to "service_role"; |
| 161 | + |
| 162 | +grant truncate on table "public"."poll_option" to "service_role"; |
| 163 | + |
| 164 | +grant update on table "public"."poll_option" to "service_role"; |
| 165 | + |
| 166 | +grant delete on table "public"."polls" to "anon"; |
| 167 | + |
| 168 | +grant insert on table "public"."polls" to "anon"; |
| 169 | + |
| 170 | +grant references on table "public"."polls" to "anon"; |
| 171 | + |
| 172 | +grant select on table "public"."polls" to "anon"; |
| 173 | + |
| 174 | +grant trigger on table "public"."polls" to "anon"; |
| 175 | + |
| 176 | +grant truncate on table "public"."polls" to "anon"; |
| 177 | + |
| 178 | +grant update on table "public"."polls" to "anon"; |
| 179 | + |
| 180 | +grant delete on table "public"."polls" to "authenticated"; |
| 181 | + |
| 182 | +grant insert on table "public"."polls" to "authenticated"; |
| 183 | + |
| 184 | +grant references on table "public"."polls" to "authenticated"; |
| 185 | + |
| 186 | +grant select on table "public"."polls" to "authenticated"; |
| 187 | + |
| 188 | +grant trigger on table "public"."polls" to "authenticated"; |
| 189 | + |
| 190 | +grant truncate on table "public"."polls" to "authenticated"; |
| 191 | + |
| 192 | +grant update on table "public"."polls" to "authenticated"; |
| 193 | + |
| 194 | +grant delete on table "public"."polls" to "service_role"; |
| 195 | + |
| 196 | +grant insert on table "public"."polls" to "service_role"; |
| 197 | + |
| 198 | +grant references on table "public"."polls" to "service_role"; |
| 199 | + |
| 200 | +grant select on table "public"."polls" to "service_role"; |
| 201 | + |
| 202 | +grant trigger on table "public"."polls" to "service_role"; |
| 203 | + |
| 204 | +grant truncate on table "public"."polls" to "service_role"; |
| 205 | + |
| 206 | +grant update on table "public"."polls" to "service_role"; |
| 207 | + |
| 208 | +grant delete on table "public"."users_poll_votes" to "anon"; |
| 209 | + |
| 210 | +grant insert on table "public"."users_poll_votes" to "anon"; |
| 211 | + |
| 212 | +grant references on table "public"."users_poll_votes" to "anon"; |
| 213 | + |
| 214 | +grant select on table "public"."users_poll_votes" to "anon"; |
| 215 | + |
| 216 | +grant trigger on table "public"."users_poll_votes" to "anon"; |
| 217 | + |
| 218 | +grant truncate on table "public"."users_poll_votes" to "anon"; |
| 219 | + |
| 220 | +grant update on table "public"."users_poll_votes" to "anon"; |
| 221 | + |
| 222 | +grant delete on table "public"."users_poll_votes" to "authenticated"; |
| 223 | + |
| 224 | +grant insert on table "public"."users_poll_votes" to "authenticated"; |
| 225 | + |
| 226 | +grant references on table "public"."users_poll_votes" to "authenticated"; |
| 227 | + |
| 228 | +grant select on table "public"."users_poll_votes" to "authenticated"; |
| 229 | + |
| 230 | +grant trigger on table "public"."users_poll_votes" to "authenticated"; |
| 231 | + |
| 232 | +grant truncate on table "public"."users_poll_votes" to "authenticated"; |
| 233 | + |
| 234 | +grant update on table "public"."users_poll_votes" to "authenticated"; |
| 235 | + |
| 236 | +grant delete on table "public"."users_poll_votes" to "service_role"; |
| 237 | + |
| 238 | +grant insert on table "public"."users_poll_votes" to "service_role"; |
| 239 | + |
| 240 | +grant references on table "public"."users_poll_votes" to "service_role"; |
| 241 | + |
| 242 | +grant select on table "public"."users_poll_votes" to "service_role"; |
| 243 | + |
| 244 | +grant trigger on table "public"."users_poll_votes" to "service_role"; |
| 245 | + |
| 246 | +grant truncate on table "public"."users_poll_votes" to "service_role"; |
| 247 | + |
| 248 | +grant update on table "public"."users_poll_votes" to "service_role"; |
| 249 | + |
| 250 | +create policy "Enable read access for all users" |
| 251 | +on "public"."guest_poll_votes" |
| 252 | +as permissive |
| 253 | +for select |
| 254 | +to public |
| 255 | +using (true); |
| 256 | + |
| 257 | + |
| 258 | +create policy "Enable insert for all users" |
| 259 | +on "public"."poll_option" |
| 260 | +as permissive |
| 261 | +for insert |
| 262 | +to public |
| 263 | +with check (true); |
| 264 | + |
| 265 | + |
| 266 | +create policy "Enable read access for all users" |
| 267 | +on "public"."poll_option" |
| 268 | +as permissive |
| 269 | +for select |
| 270 | +to public |
| 271 | +using (true); |
| 272 | + |
| 273 | + |
| 274 | +create policy "Enable insert for authenticated users only" |
| 275 | +on "public"."polls" |
| 276 | +as permissive |
| 277 | +for insert |
| 278 | +to authenticated |
| 279 | +with check (true); |
| 280 | + |
| 281 | + |
| 282 | +create policy "Enable read access for all users" |
| 283 | +on "public"."polls" |
| 284 | +as permissive |
| 285 | +for select |
| 286 | +to public |
| 287 | +using (true); |
| 288 | + |
| 289 | + |
| 290 | +create policy "Enable insert for users based on user_id" |
| 291 | +on "public"."users_poll_votes" |
| 292 | +as permissive |
| 293 | +for insert |
| 294 | +to public |
| 295 | +with check ((( SELECT auth.uid() AS uid) = user_id)); |
| 296 | + |
| 297 | + |
| 298 | +create policy "Enable read access for all users" |
| 299 | +on "public"."users_poll_votes" |
| 300 | +as permissive |
| 301 | +for select |
| 302 | +to public |
| 303 | +using (true); |
| 304 | + |
| 305 | + |
| 306 | +create policy "Enable update for users based on uid" |
| 307 | +on "public"."users_poll_votes" |
| 308 | +as permissive |
| 309 | +for update |
| 310 | +to public |
| 311 | +using ((( SELECT auth.uid() AS uid) = user_id)) |
| 312 | +with check ((( SELECT auth.uid() AS uid) = user_id)); |
| 313 | + |
| 314 | + |
| 315 | + |
0 commit comments