-- Migration: 008_FixJournalEntryDraftColumns
-- Description: Fix column types for journal_entry_draft_read_models
-- - Change lines from jsonb to text (matches C# string serialization)
-- - Rename date to document_date if not already done

-- Fix lines column type (EventFlow may have created it as jsonb)
ALTER TABLE journal_entry_draft_read_models
    ALTER COLUMN lines TYPE text USING lines::text;

-- Ensure document_date column exists (rename from date if needed)
DO $$
BEGIN
    IF EXISTS (
        SELECT 1 FROM information_schema.columns
        WHERE table_name = 'journal_entry_draft_read_models'
        AND column_name = 'date'
    ) THEN
        ALTER TABLE journal_entry_draft_read_models RENAME COLUMN date TO document_date;
    END IF;
END $$;
