ALTER TABLE proformas
  ADD COLUMN IF NOT EXISTS tax_mode VARCHAR(20) NOT NULL DEFAULT 'single',
  ADD COLUMN IF NOT EXISTS default_iva_code VARCHAR(64) NULL,
  ADD COLUMN IF NOT EXISTS uses_equivalence_surcharge TINYINT(1) NOT NULL DEFAULT 0,
  ADD COLUMN IF NOT EXISTS default_rec_code VARCHAR(64) NULL,
  ADD COLUMN IF NOT EXISTS uses_retention TINYINT(1) NOT NULL DEFAULT 0,
  ADD COLUMN IF NOT EXISTS default_retention_code VARCHAR(64) NULL;

UPDATE proformas
SET
  tax_mode = COALESCE(NULLIF(tax_mode, ''), 'single'),
  default_iva_code = COALESCE(default_iva_code, 'iva_21'),
  uses_equivalence_surcharge = COALESCE(uses_equivalence_surcharge, 0),
  uses_retention = COALESCE(uses_retention, 0)
WHERE 1 = 1;
