-- Deploy gaia:api_2016_05_17_create_table_for_api_zone to mysql

BEGIN;

-- XXX Add DDLs here.

CREATE TABLE `api_zone` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `tag_id` integer NOT NULL UNIQUE,
    `is_communityhome` bool NOT NULL,
    `home_rank` integer NOT NULL,
    `circle_rank` integer NOT NULL,
    `icon_image` varchar(400) NOT NULL,
    `banner_image` varchar(400) NOT NULL,
    `sentence_descr` varchar(100) NOT NULL,
    `is_openrelated` bool NOT NULL,
    `campaign_banner` varchar(400) NOT NULL,
    `title` varchar(400) NOT NULL,
    `campaign_descr` longtext NOT NULL,
    `is_online` bool NOT NULL,
    `created_time` datetime(6) NOT NULL
)
;
ALTER TABLE `api_zone` ADD CONSTRAINT `tag_id_refs_id_aa70556b` FOREIGN KEY (`tag_id`) REFERENCES `api_tag` (`id`);
CREATE TABLE `api_overheadtopic` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `zone_id` integer NOT NULL,
    `topic_id` integer NOT NULL,
    `title` varchar(400) NOT NULL,
    `rank` integer NOT NULL,
    `created_time` datetime(6) NOT NULL
)
;
ALTER TABLE `api_overheadtopic` ADD CONSTRAINT `topic_id_refs_id_fdb33a34` FOREIGN KEY (`topic_id`) REFERENCES `api_problem` (`id`);
ALTER TABLE `api_overheadtopic` ADD CONSTRAINT `zone_id_refs_id_e6abfa1c` FOREIGN KEY (`zone_id`) REFERENCES `api_zone` (`id`);
CREATE TABLE `api_tag_related_tag` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `zone_id` integer NOT NULL,
    `relatedzone_id` integer NOT NULL,
    `rank` integer NOT NULL,
    `created_time` datetime(6) NOT NULL
)
;
ALTER TABLE `api_tag_related_tag` ADD CONSTRAINT `zone_id_refs_id_55aabc17` FOREIGN KEY (`zone_id`) REFERENCES `api_zone` (`id`);
ALTER TABLE `api_tag_related_tag` ADD CONSTRAINT `relatedzone_id_refs_id_55aabc17` FOREIGN KEY (`relatedzone_id`) REFERENCES `api_zone` (`id`);


COMMIT;
