-- liquibase formatted sql
-- changeset cyril:update_qc_id_with_auto

ALTER TABLE `item_category`
    DROP FOREIGN KEY `FK_ITEM_CATEGORY_ON_QC_CATEGORY_ID`;

ALTER TABLE `qc_item_category`
    DROP FOREIGN KEY `FK_QC_ITEM_CATEGORY_ON_QCCATEGORYID`;
ALTER TABLE `qc_item_category`
    CHANGE COLUMN `id` `id` INT NOT NULL AUTO_INCREMENT ,
    ADD INDEX `FK_QC_ITEM_CATEGORY_ON_QCCATEGORYID` (`qcCategoryId` ASC) VISIBLE,
    DROP INDEX `FK_QC_ITEM_CATEGORY_ON_QCCATEGORYID` ;

ALTER TABLE `items`
    DROP FOREIGN KEY `FK_ITEM_ON_QCCATEGORYID`;

ALTER TABLE `qc_category`
    CHANGE COLUMN `id` `id` INT NOT NULL AUTO_INCREMENT ;

ALTER TABLE `item_category` ALTER INDEX `FK_ITEM_CATEGORY_ON_QC_CATEGORY_ID` VISIBLE;
ALTER TABLE `item_category`
    ADD CONSTRAINT `FK_ITEM_CATEGORY_ON_QC_CATEGORY_ID`
        FOREIGN KEY (`qcCategoryId`)
            REFERENCES `qc_category` (`id`)
            ON DELETE RESTRICT
            ON UPDATE RESTRICT;

ALTER TABLE `qc_item_category`
    ADD CONSTRAINT `FK_QC_ITEM_CATEGORY_ON_QCCATEGORYID`
        FOREIGN KEY (`qcCategoryId`)
            REFERENCES `qc_category` (`id`)
            ON DELETE RESTRICT
            ON UPDATE RESTRICT;

ALTER TABLE `items` ALTER INDEX `FK_ITEM_ON_QCCATEGORYID` VISIBLE;
ALTER TABLE `items`
    ADD CONSTRAINT `FK_ITEM_ON_QCCATEGORYID`
        FOREIGN KEY (`qcCategoryId`)
            REFERENCES `qc_category` (`id`)
            ON DELETE RESTRICT
            ON UPDATE RESTRICT;