vkashti / supabase / migrations / 20250312014558_remote_schema.sql
20250312014558_remote_schema.sql
Raw
create sequence "public"."deal_tags_id_seq";

create sequence "public"."deals_id_seq";

create sequence "public"."reservation_tags_id_seq";

create sequence "public"."tags_id_seq";

drop policy "can view quizes" on "public"."quizes";

drop policy "Manage reservations" on "public"."reservations";

drop policy "can manage schedule" on "public"."schedules";

drop policy "can manage tasks" on "public"."tasks";

create table "public"."deal_tags" (
    "id" integer not null default nextval('deal_tags_id_seq'::regclass),
    "deal_id" integer,
    "tag_id" integer
);


alter table "public"."deal_tags" enable row level security;

create table "public"."deals" (
    "id" integer not null default nextval('deals_id_seq'::regclass),
    "title" character varying(255) not null,
    "description" text,
    "icon" character varying(255),
    "price" numeric(10,2),
    "benefits" text[],
    "min_group_size" integer,
    "max_group_size" integer,
    "for_who" character varying(255),
    "is_for_business" boolean default false
);


alter table "public"."deals" enable row level security;

create table "public"."reservation_tags" (
    "id" integer not null default nextval('reservation_tags_id_seq'::regclass),
    "reservation_id" integer,
    "tag_id" integer
);


alter table "public"."reservation_tags" enable row level security;

create table "public"."tags" (
    "id" integer not null default nextval('tags_id_seq'::regclass),
    "name" character varying(100) not null,
    "description" text
);


alter table "public"."tags" enable row level security;

alter sequence "public"."deal_tags_id_seq" owned by "public"."deal_tags"."id";

alter sequence "public"."deals_id_seq" owned by "public"."deals"."id";

alter sequence "public"."reservation_tags_id_seq" owned by "public"."reservation_tags"."id";

alter sequence "public"."tags_id_seq" owned by "public"."tags"."id";

CREATE UNIQUE INDEX deal_tags_pkey ON public.deal_tags USING btree (id);

CREATE UNIQUE INDEX deals_pkey ON public.deals USING btree (id);

CREATE UNIQUE INDEX reservation_tags_pkey ON public.reservation_tags USING btree (id);

CREATE UNIQUE INDEX tags_name_key ON public.tags USING btree (name);

CREATE UNIQUE INDEX tags_pkey ON public.tags USING btree (id);

alter table "public"."deal_tags" add constraint "deal_tags_pkey" PRIMARY KEY using index "deal_tags_pkey";

alter table "public"."deals" add constraint "deals_pkey" PRIMARY KEY using index "deals_pkey";

alter table "public"."reservation_tags" add constraint "reservation_tags_pkey" PRIMARY KEY using index "reservation_tags_pkey";

alter table "public"."tags" add constraint "tags_pkey" PRIMARY KEY using index "tags_pkey";

alter table "public"."deal_tags" add constraint "deal_tags_deal_id_fkey" FOREIGN KEY (deal_id) REFERENCES deals(id) ON DELETE CASCADE not valid;

alter table "public"."deal_tags" validate constraint "deal_tags_deal_id_fkey";

alter table "public"."deal_tags" add constraint "deal_tags_tag_id_fkey" FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE not valid;

alter table "public"."deal_tags" validate constraint "deal_tags_tag_id_fkey";

alter table "public"."reservation_tags" add constraint "reservation_tags_reservation_id_fkey" FOREIGN KEY (reservation_id) REFERENCES reservations(id) ON DELETE CASCADE not valid;

alter table "public"."reservation_tags" validate constraint "reservation_tags_reservation_id_fkey";

alter table "public"."reservation_tags" add constraint "reservation_tags_tag_id_fkey" FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE not valid;

alter table "public"."reservation_tags" validate constraint "reservation_tags_tag_id_fkey";

alter table "public"."tags" add constraint "tags_name_key" UNIQUE using index "tags_name_key";

grant delete on table "public"."deal_tags" to "anon";

grant insert on table "public"."deal_tags" to "anon";

grant references on table "public"."deal_tags" to "anon";

grant select on table "public"."deal_tags" to "anon";

grant trigger on table "public"."deal_tags" to "anon";

grant truncate on table "public"."deal_tags" to "anon";

grant update on table "public"."deal_tags" to "anon";

grant delete on table "public"."deal_tags" to "authenticated";

grant insert on table "public"."deal_tags" to "authenticated";

grant references on table "public"."deal_tags" to "authenticated";

grant select on table "public"."deal_tags" to "authenticated";

grant trigger on table "public"."deal_tags" to "authenticated";

grant truncate on table "public"."deal_tags" to "authenticated";

grant update on table "public"."deal_tags" to "authenticated";

grant delete on table "public"."deal_tags" to "service_role";

grant insert on table "public"."deal_tags" to "service_role";

grant references on table "public"."deal_tags" to "service_role";

grant select on table "public"."deal_tags" to "service_role";

grant trigger on table "public"."deal_tags" to "service_role";

grant truncate on table "public"."deal_tags" to "service_role";

grant update on table "public"."deal_tags" to "service_role";

grant delete on table "public"."deals" to "anon";

grant insert on table "public"."deals" to "anon";

grant references on table "public"."deals" to "anon";

grant select on table "public"."deals" to "anon";

grant trigger on table "public"."deals" to "anon";

grant truncate on table "public"."deals" to "anon";

grant update on table "public"."deals" to "anon";

grant delete on table "public"."deals" to "authenticated";

grant insert on table "public"."deals" to "authenticated";

grant references on table "public"."deals" to "authenticated";

grant select on table "public"."deals" to "authenticated";

grant trigger on table "public"."deals" to "authenticated";

grant truncate on table "public"."deals" to "authenticated";

grant update on table "public"."deals" to "authenticated";

grant delete on table "public"."deals" to "service_role";

grant insert on table "public"."deals" to "service_role";

grant references on table "public"."deals" to "service_role";

grant select on table "public"."deals" to "service_role";

grant trigger on table "public"."deals" to "service_role";

grant truncate on table "public"."deals" to "service_role";

grant update on table "public"."deals" to "service_role";

grant delete on table "public"."reservation_tags" to "anon";

grant insert on table "public"."reservation_tags" to "anon";

grant references on table "public"."reservation_tags" to "anon";

grant select on table "public"."reservation_tags" to "anon";

grant trigger on table "public"."reservation_tags" to "anon";

grant truncate on table "public"."reservation_tags" to "anon";

grant update on table "public"."reservation_tags" to "anon";

grant delete on table "public"."reservation_tags" to "authenticated";

grant insert on table "public"."reservation_tags" to "authenticated";

grant references on table "public"."reservation_tags" to "authenticated";

grant select on table "public"."reservation_tags" to "authenticated";

grant trigger on table "public"."reservation_tags" to "authenticated";

grant truncate on table "public"."reservation_tags" to "authenticated";

grant update on table "public"."reservation_tags" to "authenticated";

grant delete on table "public"."reservation_tags" to "service_role";

grant insert on table "public"."reservation_tags" to "service_role";

grant references on table "public"."reservation_tags" to "service_role";

grant select on table "public"."reservation_tags" to "service_role";

grant trigger on table "public"."reservation_tags" to "service_role";

grant truncate on table "public"."reservation_tags" to "service_role";

grant update on table "public"."reservation_tags" to "service_role";

grant delete on table "public"."tags" to "anon";

grant insert on table "public"."tags" to "anon";

grant references on table "public"."tags" to "anon";

grant select on table "public"."tags" to "anon";

grant trigger on table "public"."tags" to "anon";

grant truncate on table "public"."tags" to "anon";

grant update on table "public"."tags" to "anon";

grant delete on table "public"."tags" to "authenticated";

grant insert on table "public"."tags" to "authenticated";

grant references on table "public"."tags" to "authenticated";

grant select on table "public"."tags" to "authenticated";

grant trigger on table "public"."tags" to "authenticated";

grant truncate on table "public"."tags" to "authenticated";

grant update on table "public"."tags" to "authenticated";

grant delete on table "public"."tags" to "service_role";

grant insert on table "public"."tags" to "service_role";

grant references on table "public"."tags" to "service_role";

grant select on table "public"."tags" to "service_role";

grant trigger on table "public"."tags" to "service_role";

grant truncate on table "public"."tags" to "service_role";

grant update on table "public"."tags" to "service_role";

create policy "Allow admins to create deal_tags"
on "public"."deal_tags"
as permissive
for insert
to authenticated
with check ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow admins to delete deal_tags"
on "public"."deal_tags"
as permissive
for delete
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow admins to update deal_tags"
on "public"."deal_tags"
as permissive
for update
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))))
with check ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow all users to view deal_tags"
on "public"."deal_tags"
as permissive
for select
to authenticated, anon
using (true);


create policy "Allow admins to create deals"
on "public"."deals"
as permissive
for insert
to authenticated
with check ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow admins to delete deals"
on "public"."deals"
as permissive
for delete
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow admins to update deals"
on "public"."deals"
as permissive
for update
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))))
with check ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow all users to view deals"
on "public"."deals"
as permissive
for select
to authenticated, anon
using (true);


create policy "Allow admins and team members to view quizes"
on "public"."quizes"
as permissive
for select
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = ANY (ARRAY['admin'::text, 'team'::text]))))));


create policy "Allow admins to create reservation_tags"
on "public"."reservation_tags"
as permissive
for insert
to authenticated
with check ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow admins to delete reservation_tags"
on "public"."reservation_tags"
as permissive
for delete
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow admins to update reservation_tags"
on "public"."reservation_tags"
as permissive
for update
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))))
with check ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow all users to view reservation_tags"
on "public"."reservation_tags"
as permissive
for select
to authenticated, anon
using (true);


create policy "Allow admins and team members to delete reservations"
on "public"."reservations"
as permissive
for delete
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = ANY (ARRAY['admin'::text, 'team'::text]))))));


create policy "Allow admins and team members to update reservations"
on "public"."reservations"
as permissive
for update
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = ANY (ARRAY['admin'::text, 'team'::text]))))));


create policy "Allow admins to delete schedules"
on "public"."schedules"
as permissive
for delete
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow admins to insert schedules"
on "public"."schedules"
as permissive
for insert
to authenticated
with check ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow admins to select schedules"
on "public"."schedules"
as permissive
for select
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow admins to update schedules"
on "public"."schedules"
as permissive
for update
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))))
with check ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow admins to create tags"
on "public"."tags"
as permissive
for insert
to authenticated
with check ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow admins to delete tags"
on "public"."tags"
as permissive
for delete
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow admins to update tags"
on "public"."tags"
as permissive
for update
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))))
with check ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = 'admin'::text)))));


create policy "Allow all users to view tags"
on "public"."tags"
as permissive
for select
to authenticated, anon
using (true);


create policy "Allow admins and team members to delete tasks"
on "public"."tasks"
as permissive
for delete
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = ANY (ARRAY['admin'::text, 'team'::text]))))));


create policy "Allow admins and team members to insert tasks"
on "public"."tasks"
as permissive
for insert
to authenticated
with check ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = ANY (ARRAY['admin'::text, 'team'::text]))))));


create policy "Allow admins and team members to select tasks"
on "public"."tasks"
as permissive
for select
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = ANY (ARRAY['admin'::text, 'team'::text]))))));


create policy "Allow admins and team members to update tasks"
on "public"."tasks"
as permissive
for update
to authenticated
using ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = ANY (ARRAY['admin'::text, 'team'::text]))))))
with check ((EXISTS ( SELECT 1
   FROM user_roles
  WHERE ((user_roles.user_id = ( SELECT auth.uid() AS uid)) AND (user_roles.role = ANY (ARRAY['admin'::text, 'team'::text]))))));