-- Builder tables (proposta)
-- Nota: este ficheiro é um draft para converter para Migrations CI4 mais tarde.

CREATE TABLE IF NOT EXISTS `mt_editions` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `key` VARCHAR(64) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `hosts_json` JSON NOT NULL,
  `brand_json` JSON NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_editions_key` (`key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `mt_homepage_layouts` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `edition_id` BIGINT UNSIGNED NOT NULL,
  `layout_json` JSON NOT NULL,
  `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_homepage_layouts_edition` (`edition_id`),
  CONSTRAINT `fk_mt_homepage_layouts_edition` FOREIGN KEY (`edition_id`) REFERENCES `mt_editions`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
