-- 015 - the school's town and country on the order.
--
-- Written when the Checkout session is created, so a pending or abandoned
-- order still records which school and which town it was for. Fulfilment
-- copies them onto the establishment it creates; before this, they only
-- existed in Stripe metadata and reached us at payment time.
--
-- Re-runnable: guarded on information_schema.

SET @has := (SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'orders' AND COLUMN_NAME = 'school_city');
SET @sql := IF(@has = 0,
  'ALTER TABLE `orders`
     ADD COLUMN `school_city` varchar(128) DEFAULT NULL AFTER `school_name`,
     ADD COLUMN `school_country` char(2) DEFAULT NULL AFTER `school_city`',
  'DO 0');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
