-- Supabase schema for شَمْl / Diac save flow
-- Run in Supabase SQL Editor

-- 1) Storage bucket (create via Dashboard or API if not exists)
-- Name: audio-recordings
-- Public: optional (public URL used in audio_url column)

-- 2) Database table
create table if not exists public.diacritization_records (
  id uuid primary key default gen_random_uuid(),
  audio_path text not null,
  audio_url text not null,
  extracted_text text not null,
  edited_text text not null,
  diacritized_text text not null,
  created_at timestamptz not null default now()
);

-- Optional: index for recent records
create index if not exists diacritization_records_created_at_idx
  on public.diacritization_records (created_at desc);

-- 3) RLS (recommended for production)
-- Service role bypasses RLS; enable if you add client-side reads later.
alter table public.diacritization_records enable row level security;

-- Allow service role full access (default with service key)
-- No public policies needed when only backend uses service role.
