-- Deploy gaia:advertise_2016_04_05_create_table_for_advertise.sql to mysql

BEGIN;

-- XXX Add DDLs here.

CREATE TABLE `api_advertisedoctor` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
     `doctor_id` VARCHAR(100) NOT NULL,
    `rank` integer NOT NULL,
    UNIQUE KEY rank_unique (rank)
    )
;
ALTER TABLE `api_advertisedoctor` ADD CONSTRAINT `doctor_id_refs_doctors` FOREIGN KEY (`doctor_id`) REFERENCES `api_doctor` (`id`);

CREATE TABLE `api_advertisehospital` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
     `hospital_id` VARCHAR(100) NOT NULL,
    `rank` integer NOT NULL,
    `portrait` VARCHAR(120) NOT NULL,
    UNIQUE KEY rank_unique (rank)
    )
;
ALTER TABLE `api_advertisehospital` ADD CONSTRAINT `hospital_id_refs_hospital` FOREIGN KEY (`hospital_id`) REFERENCES `api_hospital` (`id`);

CREATE TABLE `api_advertiseservice` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
     `service_id` integer NOT NULL,
    `rank` integer NOT NULL,
    `advertise_type` integer(2) NOT NULL,
    CONSTRAINT rank_unique_type UNIQUE  (rank,advertise_type)
    )
;
ALTER TABLE `api_advertiseservice` ADD CONSTRAINT `advertiseservice_id_refs_service` FOREIGN KEY (`service_id`) REFERENCES `api_service` (`id`);

COMMIT;
