mirror of
https://github.com/Hackdex-App/hackdex-website.git
synced 2026-08-28 19:45:06 -05:00
Add hack_patcher_patches table
This commit is contained in:
@@ -66,6 +66,42 @@ export type Database = {
|
||||
},
|
||||
]
|
||||
}
|
||||
hack_patcher_patches: {
|
||||
Row: {
|
||||
created_at: string
|
||||
hack_slug: string
|
||||
patch_id: number
|
||||
sort_order: number
|
||||
}
|
||||
Insert: {
|
||||
created_at?: string
|
||||
hack_slug: string
|
||||
patch_id: number
|
||||
sort_order: number
|
||||
}
|
||||
Update: {
|
||||
created_at?: string
|
||||
hack_slug?: string
|
||||
patch_id?: number
|
||||
sort_order?: number
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "hack_patcher_patches_hack_slug_fkey"
|
||||
columns: ["hack_slug"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "hacks"
|
||||
referencedColumns: ["slug"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "hack_patcher_patches_patch_id_fkey"
|
||||
columns: ["patch_id"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "patches"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
}
|
||||
hack_tags: {
|
||||
Row: {
|
||||
hack_slug: string
|
||||
|
||||
61
supabase/migrations/20260526035050_hack_patcher_patches.sql
Normal file
61
supabase/migrations/20260526035050_hack_patcher_patches.sql
Normal file
@@ -0,0 +1,61 @@
|
||||
create table if not exists public.hack_patcher_patches (
|
||||
hack_slug text not null references public.hacks(slug) on update cascade on delete cascade,
|
||||
patch_id bigint not null references public.patches(id) on update cascade on delete cascade,
|
||||
sort_order integer not null,
|
||||
created_at timestamptz not null default now(),
|
||||
primary key (hack_slug, patch_id)
|
||||
);
|
||||
|
||||
create index hack_patcher_patches_hack_slug_idx
|
||||
on public.hack_patcher_patches (hack_slug);
|
||||
|
||||
create index hack_patcher_patches_patch_id_idx
|
||||
on public.hack_patcher_patches (patch_id);
|
||||
|
||||
alter table public.hack_patcher_patches enable row level security;
|
||||
|
||||
-- Public read (same as patch_groups)
|
||||
create policy "Patcher patches are viewable by everyone"
|
||||
on public.hack_patcher_patches for select using (true);
|
||||
|
||||
-- Insert / update / delete: creator, admin, archiver.
|
||||
create policy "Users can insert patcher patches for own hacks"
|
||||
on public.hack_patcher_patches for insert
|
||||
with check (
|
||||
public.is_admin() OR
|
||||
(public.is_archiver() AND public.is_archive_hack_for_archiver(hack_slug)) OR
|
||||
exists (
|
||||
select 1 from public.hacks h
|
||||
where h.slug = hack_patcher_patches.hack_slug and h.created_by = auth.uid()
|
||||
)
|
||||
);
|
||||
|
||||
create policy "Users can update patcher patches for own hacks"
|
||||
on public.hack_patcher_patches for update
|
||||
using (
|
||||
public.is_admin() OR
|
||||
(public.is_archiver() AND public.is_archive_hack_for_archiver(hack_slug)) OR
|
||||
exists (
|
||||
select 1 from public.hacks h
|
||||
where h.slug = hack_patcher_patches.hack_slug and h.created_by = auth.uid()
|
||||
)
|
||||
)
|
||||
with check (
|
||||
public.is_admin() OR
|
||||
(public.is_archiver() AND public.is_archive_hack_for_archiver(hack_slug)) OR
|
||||
exists (
|
||||
select 1 from public.hacks h
|
||||
where h.slug = hack_patcher_patches.hack_slug and h.created_by = auth.uid()
|
||||
)
|
||||
);
|
||||
|
||||
create policy "Users can delete patcher patches for own hacks"
|
||||
on public.hack_patcher_patches for delete
|
||||
using (
|
||||
public.is_admin() OR
|
||||
(public.is_archiver() AND public.is_archive_hack_for_archiver(hack_slug)) OR
|
||||
exists (
|
||||
select 1 from public.hacks h
|
||||
where h.slug = hack_patcher_patches.hack_slug and h.created_by = auth.uid()
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user