ALTER TABLE daily_activities ADD COLUMN IF NOT EXISTS activity_date DATE NULL;
ALTER TABLE daily_activities ADD COLUMN IF NOT EXISTS job_title VARCHAR(180) NULL;
ALTER TABLE daily_activities ADD COLUMN IF NOT EXISTS unit_id INT NULL;
ALTER TABLE daily_activities ADD COLUMN IF NOT EXISTS unit_name VARCHAR(180) NULL;
ALTER TABLE daily_activities ADD COLUMN IF NOT EXISTS activity_type VARCHAR(120) NULL;
ALTER TABLE daily_activities ADD COLUMN IF NOT EXISTS activity_text TEXT NULL;
ALTER TABLE daily_activities ADD COLUMN IF NOT EXISTS start_time TIME NULL;
ALTER TABLE daily_activities ADD COLUMN IF NOT EXISTS end_time TIME NULL;
ALTER TABLE daily_activities ADD COLUMN IF NOT EXISTS result_note TEXT NULL;
UPDATE daily_activities da LEFT JOIN units u ON u.id = da.unit_id SET da.unit_name = u.name WHERE (da.unit_name IS NULL OR da.unit_name = '') AND da.unit_id IS NOT NULL AND da.unit_id > 0 AND u.name IS NOT NULL;
