-- Deploy gaia:api_2017_03_01_create_doctorgroups to mysql

BEGIN;

CREATE TABLE `api_doctorgroup` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `name` varchar(64) NOT NULL
);
CREATE TABLE `api_doctor_related_doctorgroup` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `doctor_id` varchar(100),
    `doctorgroup_id` integer
);
CREATE TABLE `api_user_related_doctorgroup` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `person_id` char(32),
    `doctorgroup_id` integer
);
ALTER TABLE `api_doctor_related_doctorgroup` ADD CONSTRAINT `doctorgroup_id_refs_id_87fb2aa4` FOREIGN KEY (`doctorgroup_id`) REFERENCES `api_doctorgroup` (`id`);
ALTER TABLE `api_doctor_related_doctorgroup` ADD CONSTRAINT `doctor_id_refs_id_b11d4d74` FOREIGN KEY (`doctor_id`) REFERENCES `api_doctor` (`id`);
ALTER TABLE `api_user_related_doctorgroup` ADD CONSTRAINT `doctorgroup_id_refs_id_91f8f2b9` FOREIGN KEY (`doctorgroup_id`) REFERENCES `api_doctorgroup` (`id`);
ALTER TABLE `api_user_related_doctorgroup` ADD CONSTRAINT `person_id_refs_id_33b5f107` FOREIGN KEY (`person_id`) REFERENCES `api_person` (`id`);

COMMIT;
