-- Deploy mimas-talos:2018_10_25_doctor_diary_question_push to mysql

BEGIN;

CREATE TABLE `api_doctor_question_diary` (
	`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
	`user_id` integer NOT NULL,
	`doctor_id` varchar(100) NULL,
	`created_time` datetime(6) NOT NULL,
	`is_online` bool NOT NULL,
	`process_status` varchar(1) NOT NULL,
	`diary_id` integer NULL,
	`question_id` integer NULL
);

ALTER TABLE `api_doctor_question_diary` ADD COLUMN `topic_id` integer NULL;
ALTER TABLE `api_doctor_question_diary` ALTER COLUMN `topic_id` DROP DEFAULT;

ALTER TABLE `api_doctor_question_diary` ADD CONSTRAINT `api_doctor_question_diary_diary_id_adc30282_fk_api_diary_id` FOREIGN KEY (`diary_id`) REFERENCES `api_diary` (`id`);
ALTER TABLE `api_doctor_question_diary` ADD CONSTRAINT `api_doctor_question_diar_question_id_7b63062a_fk_api_question_id` FOREIGN KEY (`question_id`) REFERENCES `api_question` (`id`);
CREATE INDEX `api_doctor_question_diary_bb5855f0` ON `api_doctor_question_diary` (`created_time`);
CREATE INDEX `api_doctor_question_diary_19b4d727` ON `api_doctor_question_diary` (`topic_id`);
ALTER TABLE `api_doctor_question_diary` ADD CONSTRAINT `api_doctor_question_diary_topic_id_13f630d6_fk_api_problem_id` FOREIGN KEY (`topic_id`) REFERENCES `api_problem` (`id`);

COMMIT;
