-- -------------------------------------------- --
--  APM-3311 - AC, org level analysis, reports
-- -------------------------------------------- --
CREATE TABLE IF NOT EXISTS `sod_analysis_varbl` (
	`system` CHAR(3) COLLATE utf8mb4_unicode_ci NOT NULL,
	`client` CHAR(3) COLLATE utf8mb4_unicode_ci NOT NULL,
	`varbl` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
	`field_id` int,
PRIMARY KEY (`system`, `client`, `varbl`)
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE `sod_analysis_varbl` 
CHANGE COLUMN `field_id` `field_id` INT NOT NULL DEFAULT '-1',
DROP PRIMARY KEY,
ADD PRIMARY KEY (`system`, `client`, `varbl`, `field_id`);

ALTER TABLE `sod_analysis_varbl` 
ADD COLUMN `include_empty` TINYINT NOT NULL DEFAULT '0' AFTER `field_id`,
ADD COLUMN `analysis` TINYINT NOT NULL DEFAULT '0' AFTER `include_empty`,
ADD COLUMN `username` VARCHAR(18) NULL AFTER `analysis`,
ADD COLUMN `last_edit` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER `username`;
