-- Threaded comments on notes.

create table if not exists comments (
  id         uuid primary key default gen_random_uuid(),
  note_id    uuid not null references notes (id) on delete cascade,
  content    text not null default '',
  image_path text,
  created_at timestamptz not null default now()
);
create index if not exists comments_note_id_idx on comments (note_id);

alter table comments enable row level security;

drop policy if exists "authenticated full access" on comments;
create policy "authenticated full access" on comments
  for all to authenticated using (true) with check (true);

do $$ begin
  alter publication supabase_realtime add table comments;
exception when duplicate_object then null;
end $$;
