-- ============================================================
-- 05_create_duas.sql
-- Tabel doa harian
-- Sumber: Muslim API (/v1/doa)
-- ============================================================

CREATE TABLE IF NOT EXISTS duas (
    id              SERIAL PRIMARY KEY,
    source_id       TEXT,                        -- _id dari API
    title           TEXT NOT NULL,                -- Judul doa
    arabic          TEXT NOT NULL,                -- Teks Arab
    translation     TEXT NOT NULL,                -- Terjemahan Indonesia
    source          TEXT,                         -- quran, hadits, harian, ibadah, haji, lainnya
    notes           TEXT,                         -- Catatan tambahan
    created_at      TIMESTAMPTZ DEFAULT NOW()
);

-- Index
CREATE INDEX IF NOT EXISTS idx_duas_source ON duas(source);

-- Full-text search
CREATE INDEX IF NOT EXISTS idx_duas_title_search 
    ON duas USING GIN (to_tsvector('indonesian', title));

-- RLS: semua boleh baca
ALTER TABLE duas ENABLE ROW LEVEL SECURITY;

CREATE POLICY "duas_read_all" ON duas
    FOR SELECT USING (true);
