SET NAMES utf8;

SET FOREIGN_KEY_CHECKS=0;

CREATE TABLE IF NOT EXISTS `lacew_mi_prod`.`t_customer_given` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `givenKey` varchar(50) NOT NULL,
  `companyId` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `lacew_mi_prod`.`t_customer_visible` (
  `id` int(20) NOT NULL AUTO_INCREMENT,
  `userId` int(11) NOT NULL,
  `objectKey` varchar(50) NOT NULL,
  `companyId` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `userId` (`userId`,`objectKey`) USING BTREE,
  CONSTRAINT `t_customer_visible_ibfk_2` FOREIGN KEY (`userId`) REFERENCES `t_user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

ALTER TABLE `lacew_mi_prod`.`t_customer_visible` MODIFY COLUMN IF EXISTS `id` bigint(20) NOT NULL AUTO_INCREMENT FIRST;

ALTER TABLE `lacew_mi_prod`.`t_rule_new` ADD COLUMN IF NOT EXISTS `product_modular_public_see` tinyint(1) NULL DEFAULT 0 AFTER `documentary_modular_adjustment`;

ALTER TABLE `lacew_mi_prod`.`t_rule_new` ADD COLUMN IF NOT EXISTS `product_modular_private_see` tinyint(1) NULL DEFAULT 0 AFTER `product_modular_public_see`;

ALTER TABLE `lacew_mi_prod`.`t_rule_new` DROP COLUMN IF EXISTS `customer_modular_info`;

UPDATE `lacew_mi_prod`.`t_rule_new` SET `product_modular_public_see` = `product_modular_public`,`product_modular_private_see` = `product_modular_private`;

SET FOREIGN_KEY_CHECKS=1;