-- Migration: Add bantuan_terakhir column to lokasi and populate from last_assisted_at
-- Idempotent statements for MySQL

ALTER TABLE lokasi ADD COLUMN IF NOT EXISTS bantuan_terakhir DATETIME NULL;

-- Populate bantuan_terakhir for records that already have last_assisted_at
UPDATE lokasi
SET bantuan_terakhir = last_assisted_at
WHERE bantuan_terakhir IS NULL AND last_assisted_at IS NOT NULL;

-- Add index on assisted for performance (ignore error if exists)
CREATE INDEX idx_lokasi_assisted ON lokasi (assisted);
