
CREATE TABLE `was_hub_milestone_type` (
  `milestone_type_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
  `type_slug` varchar(64) NOT NULL,
  `type_name` varchar(64) NOT NULL,
  `insert_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `update_timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`milestone_type_id`),
  KEY `idx_type_slug` (`type_slug`)
) ENGINE=InnoDB COMMENT='stores milestone types';

CREATE TRIGGER `was_hub_milestone_type_insert_timestamp` BEFORE INSERT ON `was_hub_milestone_type`
FOR EACH ROW SET NEW.insert_timestamp = NOW();

INSERT INTO was_hub_milestone_type(`type_slug`, `type_name`)
VALUES
('niche', 'Own Niche Core Training'),
('bootcamp', 'WealthyAffiliate Core Training'),
('traffic', 'Traffic Training');


ALTER TABLE was_hub_milestone_group
ADD COLUMN  `milestone_type_id` tinyint(3) unsigned NOT NULL AFTER `business_type_id`,
ADD KEY `idx_milestone_type_id` (`milestone_type_id`,`group_order`);

UPDATE was_hub_milestone_group
SET milestone_type_id = 1
WHERE business_type_id = 1;

UPDATE was_hub_milestone_group
SET milestone_type_id = 2
WHERE business_type_id = 2;


ALTER TABLE `was_hub_milestone_group` DROP `business_type_id`;

ALTER TABLE `was_hub_milestone` DROP `business_type_id`;

ALTER TABLE `was_hub_milestone_group` ADD COLUMN `group_icon` varchar(64) DEFAULT NULL AFTER `group_title`;


ALTER TABLE was_hub_milestone_group
ADD COLUMN  `group_type` ENUM('CLASS', 'BLOG') DEFAULT NULL AFTER `milestone_type_id`,
ADD COLUMN  `group_type_id` int(11) unsigned DEFAULT NULL AFTER `group_type`,
ADD KEY `idx_group_type` (`group_type`,`group_type_id`);


ALTER TABLE `was_hub_milestone` CHANGE `title` `title` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;