标签:需要 after dev util delete sed before collate 一个
CREATE TABLE `capacity_pm` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT ‘自增主键‘,
`pool_id` char(36) CHARACTER SET utf8 DEFAULT NULL COMMENT ‘资源池ID‘,
`cluster_lv1` varchar(255) CHARACTER SET utf8 DEFAULT NULL COMMENT ‘集群分类‘,
`cluster_lv2` varchar(255) CHARACTER SET utf8 DEFAULT NULL COMMENT ‘集群2级分类‘,
`update_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT ‘更新或创建时间‘,
`templete_id` varchar(255) CHARACTER SET utf8 NOT NULL COMMENT ‘模板ID‘,
`templete_name` varchar(255) CHARACTER SET utf8 DEFAULT NULL COMMENT ‘模板名称‘,
`templete_cpu_core` int(10) unsigned zerofill NOT NULL COMMENT ‘模板CPU核数‘,
`templete_mem_size` double NOT NULL COMMENT ‘模板内存大小‘,
`templete_disk_size` double NOT NULL COMMENT ‘模板磁盘大小‘,
`host_total` int(11) unsigned zerofill DEFAULT NULL COMMENT ‘主机总数‘,
`host_used` int(11) unsigned zerofill DEFAULT NULL COMMENT ‘主机已分配数量‘,
`cpu_core_total` int(11) unsigned zerofill DEFAULT NULL COMMENT ‘cpu总核数‘,
`cpu_core_free` int(11) DEFAULT NULL,
`cpu_core_used` int(11) DEFAULT NULL COMMENT ‘cpu已分配数量‘,
`cpu_core_util` double(10,3) DEFAULT NULL COMMENT ‘cpu核数使用占比‘,
`mem_total` double DEFAULT NULL COMMENT ‘内存总空间‘,
`mem_free` double DEFAULT NULL,
`mem_used` double DEFAULT NULL,
`mem_util` double DEFAULT NULL COMMENT ‘内存使用占比‘,
`disk_total` double DEFAULT NULL,
`disk_free` double DEFAULT NULL,
`disk_used` double DEFAULT NULL,
`disk_util` double DEFAULT NULL COMMENT ‘磁盘使用占比‘,
PRIMARY KEY (`id`),
UNIQUE KEY `idx_templete_all` (`pool_id`,`templete_id`) USING BTREE COMMENT ‘模块ID做完整索引‘
) ENGINE=InnoDB AUTO_INCREMENT=101 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TRIGGER `pm_before_insert_trigger` BEFORE INSERT ON `capacity_pm` FOR EACH ROW begin
set new.cpu_core_total=new.host_total * new.templete_cpu_core;
set new.cpu_core_used=new.host_used * new.templete_cpu_core;
set new.cpu_core_free=new.cpu_core_total - new.cpu_core_used;
set new.cpu_core_util=new.cpu_core_used / new.cpu_core_total;
end;
CREATE TRIGGER `pm_before_update_trigger` BEFORE UPDATE ON `capacity_pm` FOR EACH ROW begin
set new.cpu_core_total=new.host_total * old.templete_cpu_core;
set new.cpu_core_used=new.host_used * old.templete_cpu_core;
set new.cpu_core_free=new.cpu_core_total - new.cpu_core_used;
set new.cpu_core_util=new.cpu_core_used / new.cpu_core_total;
end;
CREATE TRIGGER `pm_before_insert_trigger` BEFORE INSERT ON `capacity_pm` FOR EACH ROW begin
set new.cpu_core_total=new.host_total * new.templete_cpu_core;
set new.cpu_core_used=new.host_used * new.templete_cpu_core;
set new.cpu_core_free=new.cpu_core_total - new.cpu_core_used;
set new.cpu_core_util=new.cpu_core_used / new.cpu_core_total;
end;
CREATE TRIGGER `pm_before_update_trigger` BEFORE UPDATE ON `capacity_pm` FOR EACH ROW begin
set new.cpu_core_total=new.host_total * old.templete_cpu_core;
set new.cpu_core_used=new.host_used * old.templete_cpu_core;
set new.cpu_core_free=new.cpu_core_total - new.cpu_core_used;
set new.cpu_core_util=new.cpu_core_used / new.cpu_core_total;
end;
标签:需要 after dev util delete sed before collate 一个
原文地址:https://www.cnblogs.com/ssslinppp/p/8806635.html