ALTER TABLE webhook_events
ADD COLUMN event_id TEXT,
ADD COLUMN sender_phone TEXT,
ADD COLUMN recipient_phone TEXT,
ADD COLUMN external_message_id TEXT,
ADD COLUMN event_timestamp TIMESTAMP,
ADD COLUMN verified BOOLEAN NOT NULL DEFAULT FALSE,
ADD COLUMN processing_notes TEXT,
ADD COLUMN updated_at TIMESTAMP NOT NULL DEFAULT NOW();

UPDATE webhook_events
SET event_id = id::text,
    event_timestamp = created_at
WHERE event_id IS NULL
   OR event_timestamp IS NULL;

ALTER TABLE webhook_events
ALTER COLUMN event_id SET NOT NULL,
ALTER COLUMN event_timestamp SET NOT NULL;

CREATE UNIQUE INDEX webhook_events_event_id_key ON webhook_events(event_id);
