-- 未对已有数据进行处理 --

-- order --
ALTER TABLE `order` ADD COLUMN `settlePlanned` bigint NOT NULL DEFAULT 0;
ALTER TABLE `order` MODIFY COLUMN `settled` bigint NULL DEFAULT 0;
UPDATE `order` SET `settled` = 0;

-- settlePlan --
CREATE TABLE `settlePlan`  (
  `when` bigint NULL DEFAULT NULL,
  `orderId` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `price` bigint NOT NULL,
  `iState` enum('unsettled','settled','closed') COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `$$seq$$` bigint NOT NULL AUTO_INCREMENT,
  `$$createAt$$` bigint NOT NULL,
  `$$updateAt$$` bigint NOT NULL,
  `$$deleteAt$$` bigint DEFAULT NULL,
  `$$triggerData$$` json DEFAULT NULL,
  `$$triggerUuid$$` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `$$seq$$`(`$$seq$$`),
  INDEX `settlePlan_create_at_auto_create`(`$$createAt$$`, `$$deleteAt$$`),
  INDEX `settlePlan_update_at_auto_create`(`$$updateAt$$`, `$$deleteAt$$`),
  INDEX `settlePlan_trigger_uuid`(`$$triggerUuid$$`, `$$deleteAt$$`),
  INDEX `settlePlan_fk_orderId_auto_create`(`orderId`, `$$deleteAt$$`)
) ENGINE = InnoDB AUTO_INCREMENT = 10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- settlement --
ALTER TABLE `settlement` ADD COLUMN `planId`char(36) COLLATE utf8mb4_general_ci NOT NULL;
ALTER TABLE `settlement` MODIFY COLUMN `iState` enum('unsettled','settled','closed') COLLATE utf8mb4_general_ci DEFAULT NULL;
ALTER TABLE `settlement` ADD COLUMN `settledAt` bigint NULL DEFAULT NULL;
ALTER TABLE `settlement` ADD COLUMN `closedAt` bigint NULL DEFAULT NULL;
ALTER TABLE `settlement` DROP COLUMN `orderId`;