ALTER TABLE WIN_UPDATE MODIFY COLUMN LAST_DEPLOYMENT_TIME BIGINT NOT NULL;

ALTER TABLE WIN_UPDATE DROP COLUMN IS_DOWNLOADED;

ALTER TABLE WIN_UPDATE DROP COLUMN IS_INSTALLED;

ALTER TABLE WIN_DEVICE_UPDATE ADD COLUMN IS_INSTALLED BIT NOT NULL AFTER TENANT_ID;

ALTER TABLE WIN_DEVICE_UPDATE ADD COLUMN IS_DOWNLOADED BIT NOT NULL AFTER IS_INSTALLED;

ALTER TABLE WIN_DEVICE_UPDATE DROP PRIMARY KEY;

ALTER TABLE WIN_DEVICE_UPDATE ADD PRIMARY KEY (DEVICE_ID, WINDOWS_UPDATE_ID, TENANT_ID);

ALTER TABLE WIN_UPDATE DROP COLUMN CATEGORY;

CREATE TABLE IF NOT EXISTS `UPDATE_CATEGORY` (
    `CATEGORY_ID` VARCHAR(255) NOT NULL,
    `CATEGORY_NAME` VARCHAR(255) NOT NULL,
    `CATEGORY_TYPE` VARCHAR(100) NOT NULL,
    `CATEGORY_DESCRIPTION` TEXT NOT NULL,
    PRIMARY KEY (`CATEGORY_ID`))
    ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `WIN_UPDATE_TO_CATEGORY` (
    `WINDOWS_UPDATE_ID` VARCHAR(255) NOT NULL,
    `CATEGORY_ID` VARCHAR(255) NOT NULL,
    PRIMARY KEY (`WINDOWS_UPDATE_ID`, `CATEGORY_ID`),
    FOREIGN KEY (`WINDOWS_UPDATE_ID`) REFERENCES `WIN_UPDATE`(`WINDOWS_UPDATE_ID`) ON DELETE CASCADE ON UPDATE CASCADE,
    FOREIGN KEY (`CATEGORY_ID`) REFERENCES `UPDATE_CATEGORY`(`CATEGORY_ID`) ON DELETE CASCADE ON UPDATE CASCADE)
    ENGINE = InnoDB;

ALTER TABLE WIN_UPDATE
    MODIFY COLUMN IS_HIDDEN TINYINT(1) UNSIGNED NOT NULL,
    MODIFY COLUMN IS_MANDATORY TINYINT(1) UNSIGNED NOT NULL,
    MODIFY COLUMN IS_UNINSTALLABLE TINYINT(1) UNSIGNED NOT NULL;

ALTER TABLE WIN_DEVICE_UPDATE
    MODIFY COLUMN IS_INSTALLED TINYINT(1) UNSIGNED NOT NULL,
    MODIFY COLUMN IS_DOWNLOADED TINYINT(1) UNSIGNED NOT NULL;


