-- Deploy gaia:2017_11_08_create_searchkeyword_city_region to mysql

BEGIN;

CREATE TABLE `api_searchkeyword_regions` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `searchkeyword_id` integer NOT NULL,
    `region_id` integer NOT NULL,
    UNIQUE (`searchkeyword_id`, `region_id`)
)
;
ALTER TABLE `api_searchkeyword_regions` ADD CONSTRAINT `region_id_refs_id_737b5b56` FOREIGN KEY (`region_id`) REFERENCES `api_region` (`id`);
CREATE TABLE `api_searchkeyword_cities` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `searchkeyword_id` integer NOT NULL,
    `city_id` varchar(40) NOT NULL,
    UNIQUE (`searchkeyword_id`, `city_id`)
)
;
ALTER TABLE `api_searchkeyword_cities` ADD CONSTRAINT `city_id_refs_id_f42ce731` FOREIGN KEY (`city_id`) REFERENCES `api_city` (`id`);
ALTER TABLE `api_searchkeyword_regions` ADD CONSTRAINT `searchkeyword_id_refs_id_37134845` FOREIGN KEY (`searchkeyword_id`) REFERENCES `api_searchkeyword` (`id`);
ALTER TABLE `api_searchkeyword_cities` ADD CONSTRAINT `searchkeyword_id_refs_id_270447f4` FOREIGN KEY (`searchkeyword_id`) REFERENCES `api_searchkeyword` (`id`);

ALTER TABLE `api_searchkeyword` ADD COLUMN `position` integer NOT NULL DEFAULT 0;

COMMIT;