ALTER TABLE `email_templates`
  ADD COLUMN `editor_mode` varchar(32) NOT NULL DEFAULT 'code' AFTER `subject`,
  ADD COLUMN `source_format` varchar(32) NOT NULL DEFAULT 'html' AFTER `editor_mode`,
  ADD COLUMN `builder_schema_version` smallint(5) unsigned NOT NULL DEFAULT 1 AFTER `source_format`,
  ADD COLUMN `source_content` longtext DEFAULT NULL AFTER `body_html`,
  ADD COLUMN `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() AFTER `created_at`;

UPDATE `email_templates`
SET
  `source_format` = 'html',
  `source_content` = `body_html`
WHERE `source_content` IS NULL OR `source_content` = '';
