SET FOREIGN_KEY_CHECKS=0;

ALTER TABLE `autocall_observation` ADD COLUMN `PaymentNotional` double NOT NULL DEFAULT 0 COMMENT '结算数量（累计期权用）' AFTER `PaymentAmount`;

ALTER TABLE `client_margin_template` ADD COLUMN `ClientLevel` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '客户等级' AFTER `OptDate`;

CREATE TABLE `clientbalancedaily_bs`  (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `ClientId` int NULL DEFAULT NULL COMMENT '客户信息',
  `ClientName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '客户名称',
  `ClientNumber` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '客户编号',
  `BalanceDate` date NOT NULL COMMENT '结算日期',
  `ToDayRemainFund` double NOT NULL COMMENT '当日资金余额',
  `LastDayRemainFund` double NOT NULL COMMENT '上日资金余额',
  `PositionPnl` double NOT NULL COMMENT '持仓盈亏',
  `Pv` double NOT NULL COMMENT '持仓市值',
  `PvSum` double NOT NULL COMMENT '持仓市值累计',
  `RoundedPv` double NOT NULL COMMENT '四舍五入后的持仓市值',
  `RoundedPvSum` double NOT NULL COMMENT '四舍五入后的持仓市值累计',
  `RoundedPositionPnl` double NOT NULL COMMENT '四舍五入后的持仓盈亏',
  `RoundedPositionPnlSum` double NOT NULL COMMENT '四舍五入后的持仓盈亏累计',
  `InFund` double NOT NULL COMMENT '当日入金',
  `InFundSum` double NOT NULL COMMENT '入金总和',
  `OutFund` double NOT NULL COMMENT '当日出金',
  `OutFundSum` double NOT NULL COMMENT '出金总和',
  `OptionPremium` double NOT NULL COMMENT '期权费收支(权利金收支)',
  `OptionPremiumSum` double NOT NULL COMMENT '期权费收支(权利金收支)累计',
  `PosiPremium` double NOT NULL COMMENT '持仓权利金',
  `PosiPremiumSum` double NOT NULL COMMENT '持仓权利金累计',
  `Coupon` double NOT NULL COMMENT '票息',
  `CouponSum` double NOT NULL COMMENT '票息总和',
  `WinLoss` double NOT NULL COMMENT '实现盈亏',
  `WinLossSum` double NOT NULL COMMENT '实现盈亏累计',
  `OptId` int NULL DEFAULT NULL COMMENT '操作人ID',
  `OptDate` datetime NULL DEFAULT NULL COMMENT '创建日期',
  `IsBuy` bit(1) NOT NULL COMMENT '是否买权',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `clientbalancedaily_Index1`(`ClientId` ASC) USING BTREE,
  INDEX `clientbalancedaily_Index2`(`BalanceDate` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

ALTER TABLE `clientcashincashout_remove` ADD COLUMN `ApprovalProcess` int NOT NULL DEFAULT 0 COMMENT '审批进程，默认为0，已拒绝-1，已确认-2' AFTER `Deal`;

ALTER TABLE `eod_trade_risk_manual` ADD COLUMN `VolType` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '波动率类型' AFTER `FlatPrice`;

ALTER TABLE `eod_trade_risk_manual` ADD COLUMN `SettlementType` int NOT NULL DEFAULT 0 COMMENT '结算方式(0：收盘价，1：结算价，2：待定)' AFTER `VolType`;

ALTER TABLE `margin_template_detail` ADD COLUMN `UnderlyingType` int NOT NULL DEFAULT 0 COMMENT '标的类型' AFTER `OptDate`;

ALTER TABLE `margin_template_detail` ADD COLUMN `IsNeedCompare` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否需要比较大小' AFTER `UnderlyingType`;

ALTER TABLE `margin_template_detail` ADD COLUMN `IsUsePriceLimit` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否使用涨跌幅限制' AFTER `IsNeedCompare`;

ALTER TABLE `margin_template_detail` ADD COLUMN `ComparedInitialMarginRate` double(10, 6) NULL DEFAULT NULL COMMENT '初始预付金乘积额外系数' AFTER `IsUsePriceLimit`;

ALTER TABLE `margin_template_detail` ADD COLUMN `SpanConfigJson` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT 'Span涨跌幅字段' AFTER `ComparedInitialMarginRate`;

ALTER TABLE `margin_template_v2` ADD COLUMN `BuySellType` int NOT NULL DEFAULT 0 COMMENT '适用买卖方向' AFTER `OptDate`;

ALTER TABLE `margin_template_v2` ADD COLUMN `MarginScenarios` int NOT NULL COMMENT '适用预付金场景' AFTER `BuySellType`;

ALTER TABLE `margin_template_v2` ADD COLUMN `UnderlyingSeperateType` int NOT NULL COMMENT '是否按标的类型设置参数' AFTER `MarginScenarios`;

ALTER TABLE `margin_template_v2` ADD COLUMN `UnderlyingSeperateComments` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '按标的类型设置参数描述' AFTER `UnderlyingSeperateType`;

ALTER TABLE `margin_template_v2` ADD COLUMN `IsValid` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否生效' AFTER `UnderlyingSeperateComments`;

ALTER TABLE `margin_template_v2` ADD COLUMN `ValueDate` date NOT NULL COMMENT '生效日期' AFTER `IsValid`;

ALTER TABLE `trade_accumulator_option` ADD COLUMN `AccumulatorStructureType` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计类型（0:标准，1:三段式）' AFTER `KOBarrier`;

ALTER TABLE `trade_accumulator_option` ADD COLUMN `Strike2` double(18, 8) NULL DEFAULT NULL COMMENT '执行价格2' AFTER `ForwardPriceType`;

ALTER TABLE `trade_accumulator_option` ADD COLUMN `Multiplier` double(18, 8) NULL DEFAULT NULL COMMENT '乘数1' AFTER `Strike2`;

ALTER TABLE `trade_accumulator_option` ADD COLUMN `Multiplier2` double(18, 8) NULL DEFAULT NULL COMMENT '乘数2' AFTER `Multiplier`;

ALTER TABLE `trade_accumulator_option` ADD COLUMN `Coupon2` double(18, 8) NULL DEFAULT NULL COMMENT '票息2' AFTER `Multiplier2`;

ALTER TABLE `trade_accumulator_option` ADD COLUMN `SettlementMode2` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '结算方式2' AFTER `Coupon2`;

ALTER TABLE `trade_accumulator_option` ADD COLUMN `ForwardPriceType2` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '远期期初价格类型2' AFTER `SettlementMode2`;

ALTER TABLE `trade_accumulator_option` ADD COLUMN `ForwardDateType2` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '远期到期日类型2' AFTER `ForwardPriceType2`;

ALTER TABLE `trade_accumulator_option` ADD COLUMN `Strike3` double(18, 8) NULL DEFAULT NULL COMMENT '执行价格3' AFTER `ForwardDateType2`;

ALTER TABLE `trade_accumulator_option` ADD COLUMN `Multiplier3` double(18, 8) NULL DEFAULT NULL COMMENT '乘数3' AFTER `Strike3`;

ALTER TABLE `trade_accumulator_option` ADD COLUMN `SettlementMode3` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '结算方式3' AFTER `Multiplier3`;

ALTER TABLE `trade_accumulator_option` ADD COLUMN `ForwardPriceType3` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '远期期初价格类型3' AFTER `SettlementMode3`;

ALTER TABLE `trade_accumulator_option` ADD COLUMN `ForwardDateType3` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '远期到期日类型3' AFTER `ForwardPriceType3`;

ALTER TABLE `trade_accumulator_option` MODIFY COLUMN `ForwardDateType` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '远期到期日类型(标的到期日|期权到期日|标的交割月前一交易日)' AFTER `OriginalAccumuTradeAmount`;

ALTER TABLE `trade_snowball` ADD COLUMN `EnhancedParticipationRate` double(18, 6) NULL DEFAULT NULL COMMENT '增强参与率' AFTER `IsInitialKnockedIn`;

ALTER TABLE `trade_snowball` ADD COLUMN `KIParticipationRate` double(18, 6) NULL DEFAULT NULL COMMENT '敲入参与率' AFTER `EnhancedParticipationRate`;

ALTER TABLE `trade_snowball` ADD COLUMN `PrincipalProtectionRate` double(18, 6) NULL DEFAULT NULL COMMENT '保本比率' AFTER `KIParticipationRate`;

ALTER TABLE `trade_snowball` ADD COLUMN `PrepaymentUsed` bit(1) NOT NULL DEFAULT b'0' COMMENT '预付金是否参与定价' AFTER `PrincipalProtectionRate`;

ALTER TABLE `trade_snowball` ADD COLUMN `PrepaymentRatio` double(18, 6) NULL DEFAULT NULL COMMENT '预付金比例' AFTER `PrepaymentUsed`;

ALTER TABLE `trade_snowball` ADD COLUMN `PrepaymentInterestRate` double(18, 6) NULL DEFAULT NULL COMMENT '预付金返息率' AFTER `PrepaymentRatio`;

ALTER TABLE `trade_snowball` ADD COLUMN `PrepaymentAddedToPv` bit(1) NULL DEFAULT NULL COMMENT '预付金记入PV' AFTER `PrepaymentInterestRate`;

ALTER TABLE `trade_snowball` ADD COLUMN `CouponIncludeEndDate` bit(1) NULL DEFAULT NULL COMMENT '终日是否计息' AFTER `PrepaymentAddedToPv`;

ALTER TABLE `trade_snowball` ADD COLUMN `KIObservationType` int NOT NULL DEFAULT 0 COMMENT '敲入观察设置，0:手动，1:每日观察,2:仅到期日观察' AFTER `CouponIncludeEndDate`;

ALTER TABLE `trade_span` DROP INDEX `IX_trade_span_tid`;

ALTER TABLE `trade_span` ADD UNIQUE INDEX `IX_trade_span_tid1`(`ValueDate` ASC, `TradeId` ASC) USING BTREE;

ALTER TABLE `trade_span` ADD INDEX `IX_trade_span_tid`(`TradeId` ASC) USING BTREE;

ALTER TABLE `underlying_manager` ADD INDEX `test1`(`MaturityDate` ASC, `UnderlyingInstrumentType` ASC) USING BTREE;

CREATE TABLE `underlying_span_two`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `ValueDate` date NULL DEFAULT NULL COMMENT '赋值日期',
  `UnderlyingId` int NOT NULL COMMENT '标的ID',
  `SpanRate` double(10, 4) NULL DEFAULT NULL COMMENT 'Span涨跌幅2',
  `OptId` int NULL DEFAULT NULL COMMENT '操作人ID',
  `OptName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '操作人名称',
  `OptDate` datetime NULL DEFAULT NULL COMMENT '操作时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `ix_underlying_span2`(`UnderlyingId` ASC, `ValueDate` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '标的分红率数据表' ROW_FORMAT = Dynamic;

ALTER TABLE `valuedate` ADD COLUMN `TwoSideMarginValueDate` date NULL DEFAULT NULL COMMENT '国君权益类双向预付金生效日期' AFTER `UnwindAmountAngle`;

ALTER TABLE `clientbalancedaily` ADD COLUMN `PrepaymentAmount` double NULL DEFAULT NULL COMMENT '持仓交易预付金总和' AFTER `EndPremiumSum`;

ALTER TABLE `eod_pnl` ADD UNIQUE INDEX `queryindex`(`ValueDate` ASC, `TradeId` ASC, `HedgeUniqueCode` ASC) USING BTREE;

ALTER TABLE `eod_pnl_extend` ADD UNIQUE INDEX `queryindex`(`ValueDate` ASC, `TradeId` ASC, `HedgeUniqueCode` ASC) USING BTREE;

ALTER TABLE `eod_pnl_extend_s` ADD UNIQUE INDEX `queryindex`(`ValueDate` ASC, `TradeId` ASC, `HedgeUniqueCode` ASC) USING BTREE;

ALTER TABLE `eod_pnl_hedgevol` ADD UNIQUE INDEX `queryindex`(`ValueDate` ASC, `TradeId` ASC, `HedgeUniqueCode` ASC) USING BTREE;

ALTER TABLE `eod_pnl_hedgevol_s` ADD UNIQUE INDEX `queryindex`(`ValueDate` ASC, `TradeId` ASC, `HedgeUniqueCode` ASC) USING BTREE;

ALTER TABLE `eod_pnl_openvol` ADD UNIQUE INDEX `queryindex`(`ValueDate` ASC, `TradeId` ASC, `HedgeUniqueCode` ASC) USING BTREE;

ALTER TABLE `eod_pnl_openvol_s` ADD UNIQUE INDEX `queryindex`(`ValueDate` ASC, `TradeId` ASC, `HedgeUniqueCode` ASC) USING BTREE;

ALTER TABLE `eod_pnl_s` ADD UNIQUE INDEX `queryindex`(`ValueDate` ASC, `TradeId` ASC, `HedgeUniqueCode` ASC) USING BTREE;

ALTER TABLE `task_event` MODIFY COLUMN `OptDate` datetime NULL DEFAULT NULL COMMENT '操作时间' AFTER `OptName`;

ALTER TABLE `trade_meta` MODIFY COLUMN `MetaValue` varchar(2048) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '元数据' AFTER `MetaKey`;

SET FOREIGN_KEY_CHECKS=1;