
CREATE TABLE `was_hub_business_type` (
  `business_type_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `type_slug` varchar(32) NOT NULL,
  `type_name` varchar(64) NOT NULL,
  `type_description` text 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 (`business_type_id`),
  UNIQUE KEY `unq_type_slug` (`type_slug`)
) ENGINE=InnoDB COMMENT='stores business hub types';

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


CREATE TABLE `was_hub_business_type_resource` (
  `business_type_resource_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `business_type_id` int(11) unsigned NOT NULL,
  `resource_id` int(11) unsigned NOT NULL,
  `resource_order` tinyint(3) unsigned 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 (`business_type_resource_id`),
  KEY `idx_business_type_id` (`business_type_id`),
  KEY `idx_resource_id` (`resource_id`) 
) ENGINE=InnoDB COMMENT='stores resources related to a type';

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


ALTER TABLE `was_hub_business`
  ADD COLUMN `business_type_id` int(11) unsigned NOT NULL AFTER `business_id`,
  ADD KEY `idx_business_type_id` (`business_type_id`);


INSERT INTO `was_hub_business_type` (`type_slug`, `type_name`, `type_description`)
VALUES 
('own-niche', 'My Own Niche', 'Hub created to promote a users own niche choice'),
('wealthyaffiliate', 'Promote Wealthy Affiliate', 'Hub created to promote WA');
