-- Slice 8b-4d · Close (GL post) — schema patch
-- closed_on already exists from 8b-4a. Add the JE link + who closed.

SET @sql := (SELECT IF(COUNT(*) = 0,
    'ALTER TABLE service_requisitions
        ADD COLUMN journal_entry_id INT NOT NULL DEFAULT 0            AFTER closed_on,
        ADD COLUMN closed_by        INT NOT NULL DEFAULT 0            AFTER journal_entry_id,
        ADD COLUMN closed_by_name   VARCHAR(120) NOT NULL DEFAULT ""  AFTER closed_by',
    'SELECT "service_requisitions.journal_entry_id already exists"'
) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'service_requisitions' AND column_name = 'journal_entry_id');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
