-- Deploy gaia:api_2016_04_22_create_table_freecustoms to mysql

BEGIN;

  CREATE TABLE `api_freecustom` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `user_id` char(32) NOT NULL,
    `phone` varchar(100) NOT NULL,
    `create_time` datetime(6) NOT NULL,
    `feedback_time` datetime(6),
    `plan_type` varchar(1) NOT NULL,
    `comments` varchar(200),
    `kefu_comments` varchar(200),
    `operation_type` varchar(1) NOT NULL,
    `recover_time` varchar(1) NOT NULL
  )
  ;
  ALTER TABLE `api_freecustom` ADD CONSTRAINT `user_id_refs_id_267386b1` FOREIGN KEY (`user_id`) REFERENCES `api_person` (`id`);
  CREATE TABLE `api_freecustomtag` (
      `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
      `freecustom_id` integer NOT NULL,
      `tag_id` integer NOT NULL
  )
  ;
  ALTER TABLE `api_freecustomtag` ADD CONSTRAINT `freecustom_id_refs_id_bddf25f5` FOREIGN KEY (`freecustom_id`) REFERENCES `api_freecustom` (`id`);
  ALTER TABLE `api_freecustomtag` ADD CONSTRAINT `tag_id_refs_id_354d6443` FOREIGN KEY (`tag_id`) REFERENCES `api_tag` (`id`);
  CREATE TABLE `api_freecustomimage` (
      `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
      `freecustom_id` integer NOT NULL,
      `image_url` varchar(300) NOT NULL
  )
  ;
  ALTER TABLE `api_freecustomimage` ADD CONSTRAINT `freecustom_id_refs_id_33f00ce5` FOREIGN KEY (`freecustom_id`) REFERENCES `api_freecustom` (`id`);

COMMIT;
