-- Deploy gaia:api_2016_10_25_create_table_seckill_button_servicereg_alter_seckillservice to mysql

BEGIN;

CREATE TABLE `api_specialseckillbutton` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `button_document` varchar(100) NOT NULL,
    `start_show_time` datetime(6) NOT NULL,
    `end_show_time` datetime(6) NOT NULL,
    `start_sell_time` datetime(6) NOT NULL,
    `end_sell_time` datetime(6) NOT NULL,
    `button_prefix` varchar(100) NOT NULL,
    `content` longtext NOT NULL
)
;
CREATE TABLE `api_doctorseckillapply` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `service_item_id` integer NOT NULL,
    `seckill_price` integer NOT NULL,
    `stock` integer NOT NULL,
    `seckill_button_id` integer NOT NULL,
    UNIQUE (`service_item_id`, `seckill_button_id`)
)
;
ALTER TABLE `api_doctorseckillapply` ADD CONSTRAINT `seckill_button_id_refs_id_ff0459ad` FOREIGN KEY (`seckill_button_id`) REFERENCES `api_specialseckillbutton` (`id`);
ALTER TABLE `api_doctorseckillapply` ADD CONSTRAINT `service_item_id_refs_id_5da629eb` FOREIGN KEY (`service_item_id`) REFERENCES `api_serviceitem` (`id`);

ALTER TABLE `api_specialseckillservice` ADD COLUMN `service_item_id` INTEGER;
ALTER TABLE `api_specialseckillservice` ADD CONSTRAINT `service_item_id_refs_id_30469ee4` FOREIGN KEY (`service_item_id`) REFERENCES `api_serviceitem` (`id`);

ALTER TABLE `api_specialseckillservice` ADD COLUMN `seckill_apply_id` INTEGER;
ALTER TABLE `api_specialseckillservice` ADD CONSTRAINT `seckill_apply_id_refs_id_133d0fa8` FOREIGN KEY (`seckill_apply_id`) REFERENCES `api_doctorseckillapply` (`id`);

ALTER TABLE `api_specialseckillservice` ADD COLUMN `rank` INTEGER;

alter table `api_specialseckillservice` drop index `service_id`, add unique key `service_id` (`service_id`, `service_item_id`, `special_id`);

COMMIT;
