-- Deploy gaia:api_2016_02_18_create_table_api_tagalert to mysql

BEGIN;

CREATE TABLE `api_tagalert` (
  `id` INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `tag_id` INTEGER NOT NULL,
  `is_online` BOOL,
  `type` INTEGER NOT NULL,
  `title` VARCHAR(256) NOT NULL,
  `service_tag_id` INTEGER NOT NULL,
  `days` INTEGER NOT NULL
);

ALTER TABLE `api_tagalert` ADD CONSTRAINT `tag_id_references_api_tag_id` FOREIGN KEY (`tag_id`) REFERENCES `api_tag` (`id`);
ALTER TABLE `api_tagalert` ADD CONSTRAINT `service_tag_id_references_api_tag_id` FOREIGN KEY (`service_tag_id`) REFERENCES `api_tag` (`id`);


CREATE TABLE `api_tagalertitem`(
  `id` INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `tagalert_id` INTEGER NOT NULL,
  `title` VARCHAR(256) NOT NULL,
  `image_url` VARCHAR(512) NOT NULL,
  `content` TEXT NOT NULL
);

ALTER TABLE `api_tagalertitem` ADD CONSTRAINT `tagalert_id_references_api_tagalert_id` FOREIGN KEY (`tagalert_id`) REFERENCES `api_tagalert` (`id`);

COMMIT;
