ALTER TABLE `digital_operation_ac`.`cube_data`
    ADD COLUMN `cube_id` varchar(255) NULL AFTER `id`;
UPDATE cube_data SET cube_id = id;

ALTER TABLE `digital_operation_ac`.`report_datasource`
    ADD COLUMN `ds_id` bigint NULL DEFAULT NULL COMMENT '主键自增' AFTER `id`;

UPDATE report_datasource SET ds_id = id;


ALTER TABLE `digital_operation_ac`.`cube_data_permission`
    MODIFY COLUMN `cube_data_id` bigint NOT NULL COMMENT '数据集ID' AFTER `cube_workspace_id`,
    DROP PRIMARY KEY,
    ADD PRIMARY KEY (`id`, `cube_data_id`) USING BTREE;

ALTER TABLE `digital_operation_ac`.`cube_table_column`
    MODIFY COLUMN `cube_data_id` bigint NOT NULL COMMENT '数据集ID' AFTER `id`,
    DROP PRIMARY KEY,
    ADD PRIMARY KEY (`id`, `cube_data_id`) USING BTREE;

ALTER TABLE `digital_operation_ac`.`cube_table_static`
    MODIFY COLUMN `datasource_id` bigint NOT NULL COMMENT '数据源ID' AFTER `id`,
    MODIFY COLUMN `cube_data_id` bigint NOT NULL COMMENT '数据集ID' AFTER `datasource_id`,
    DROP PRIMARY KEY,
    ADD PRIMARY KEY (`id`, `datasource_id`, `cube_data_id`) USING BTREE;

ALTER TABLE `digital_operation_ac`.`cube_data`
    MODIFY COLUMN `datasource_id` bigint NOT NULL COMMENT '数据源ID' AFTER `workspace_id`,
    DROP PRIMARY KEY,
    ADD PRIMARY KEY (`id`, `datasource_id`) USING BTREE;

ALTER TABLE `digital_operation_ac`.`cube_data`
    ADD UNIQUE INDEX `cube_id`(`cube_id`, `app_id`);

ALTER TABLE `digital_operation_ac`.`report_datasource`
    ADD UNIQUE INDEX `ds_id`(`ds_id`, `app_id`);


ALTER TABLE `digital_operation_ac`.`report_datasource_permission`
    ADD COLUMN `tenant_id` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '租户id' AFTER `create_user_id`,
    ADD COLUMN `app_id` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL DEFAULT '000000' COMMENT '应用id' AFTER `tenant_id`;

ALTER TABLE `digital_operation_ac`.`cube_data_permission`
    ADD COLUMN `tenant_id` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '租户id' AFTER `exclude_column_ids`,
    ADD COLUMN `app_id` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL DEFAULT '000000' COMMENT '应用id' AFTER `tenant_id`;

ALTER TABLE `digital_operation_ac`.`data_api`
    DROP INDEX `api_key`,
    ADD UNIQUE INDEX `api_key`(`api_key` ASC, `app_id`) USING BTREE;

ALTER TABLE `digital_operation_ac`.`report_datasource_permission`
    DROP INDEX `ds_id`,
    ADD UNIQUE INDEX `ds_id`(`datasource_id` ASC, `data_perm_id` ASC, `app_id`) USING BTREE;