-- Deploy gaia:api_20160802_addtable_api_extendtips_api_advertisemanagement to mysql

BEGIN;

-- XXX Add DDLs here.

CREATE TABLE `api_extendtips` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `tip_name` varchar(4) NOT NULL
)
;
CREATE TABLE `api_advertisemanagement_show_city` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `advertisemanagement_id` integer NOT NULL,
    `city_id` varchar(40) NOT NULL,
    UNIQUE (`advertisemanagement_id`, `city_id`)
)
;
ALTER TABLE `api_advertisemanagement_show_city` ADD CONSTRAINT `city_id_refs_id_4def247c` FOREIGN KEY (`city_id`) REFERENCES `api_city` (`id`);
CREATE TABLE `api_advertisemanagement` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `service_id` integer NOT NULL,
    `show_position` varchar(20),
    `show_days` integer NOT NULL,
    `start_time` datetime(6),
    `end_time` datetime(6),
    `extend_tip_id` integer NOT NULL,
    `is_online` bool NOT NULL
)
;
ALTER TABLE `api_advertisemanagement` ADD CONSTRAINT `extend_tip_id_refs_id_3d23593a` FOREIGN KEY (`extend_tip_id`) REFERENCES `api_extendtips` (`id`);
ALTER TABLE `api_advertisemanagement` ADD CONSTRAINT `service_id_refs_id_e93154e7` FOREIGN KEY (`service_id`) REFERENCES `api_service` (`id`);
ALTER TABLE `api_advertisemanagement_show_city` ADD CONSTRAINT `advertisemanagement_id_refs_id_4427b3fe` FOREIGN KEY (`advertisemanagement_id`) REFERENCES `api_advertisemanagement` (`id`);

COMMIT;
