-- Deploy gaia:2017_03_14_doctor_coupon to mysql

BEGIN;

    ALTER TABLE `api_coupon` ADD COLUMN `coupon_type` INTEGER NOT NULL DEFAULT 1, ADD COLUMN `distribution_status` INTEGER NOT NULL DEFAULT 1;

    ALTER TABLE `pay_servicesnapshot` ADD COLUMN `coupon_type` INTEGER NOT NULL DEFAULT 1, ADD COLUMN `coupon_info` longtext NULL DEFAULT NULL;

    CREATE TABLE `api_couponskurestrict` (
        `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
        `coupon_id` integer NOT NULL,
        `sku_id` integer NOT NULL,
        UNIQUE (`coupon_id`, `sku_id`)
    )
    ;
    ALTER TABLE `api_couponskurestrict` ADD CONSTRAINT `sku_id_refs_id_5043dc47` FOREIGN KEY (`sku_id`) REFERENCES `api_serviceitem` (`id`);
    ALTER TABLE `api_couponskurestrict` ADD CONSTRAINT `coupon_id_refs_id_8dfaefe8` FOREIGN KEY (`coupon_id`) REFERENCES `api_coupon` (`id`);
    CREATE INDEX `api_couponskurestrict_606a82fc` ON `api_couponskurestrict` (`coupon_id`);
    CREATE INDEX `api_couponskurestrict_b2b8005a` ON `api_couponskurestrict` (`sku_id`);

    ALTER TABLE `api_coupongift` ADD COLUMN `gift_type` INTEGER NOT NULL DEFAULT 1;
    ALTER TABLE `api_gifttocoupon` ADD COLUMN `coupon_enable` BOOL NOT NULL DEFAULT 1;

    ALTER TABLE `api_channelgift` ADD COLUMN `gift_enable` BOOL NOT NULL DEFAULT 1, ADD COLUMN `displayable` BOOL NOT NULL DEFAULT 0;

COMMIT;
