ALTER TABLE `tblestimates` ADD `cc_sync` BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE `tblinvoices` ADD `cc_sync` BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE `tbljobs` ADD `cc_sync` BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE `tblchange_orders` ADD `cc_sync` BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE `tblpost_inspections` ADD `cc_sync` BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE `tblwork_orders` ADD `cc_sync` BOOLEAN NOT NULL DEFAULT FALSE;

CREATE TABLE `tbltenant_cc_sync_files`(
    `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
    `tenant_id` BIGINT(20) NOT NULL,
    `staff_id` BIGINT(20) NULL,
    `rel_id` BIGINT(20) NOT NULL,
    `rel_type` VARCHAR(100) NOT NULL,
    `task_id` BIGINT(20) NULL,
    `cc_module_type` VARCHAR(100) NOT NULL,
    `property_id` BIGINT(20) NOT NULL,
    `project_id` BIGINT(20) NOT NULL,
    `file_id` BIGINT(20) NOT NULL,
    `file_type` ENUM('attachment', 'photo') NOT NULL,
    `status` ENUM('pending', 'completed', 'failed') NOT NULL,
    `comment` TEXT NULL DEFAULT NULL,
    `added_on` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `completed_on` DATETIME NULL DEFAULT NULL,
    PRIMARY KEY(`id`),
    INDEX(`tenant_id`),
    INDEX(`rel_id`),
    INDEX(`task_id`),
    INDEX(`property_id`),
    INDEX(`project_id`),
    INDEX(`file_id`),
    INDEX(`file_type`)
) ENGINE = InnoDB;

ALTER TABLE `tbltenant_cc_sync_files` CHANGE `completed_on` `completed_on` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL;