-- Deploy gaia:api_2015_11_20_create_table_servicemonitor to mysql

BEGIN;

CREATE TABLE `api_servicemonitor` (
      `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
      `handle_at` datetime(6) NOT NULL,
      `status` integer NOT NULL,
      `refund_num` integer NOT NULL,
      `settled_num` integer NOT NULL,
      `service_id` integer NOT NULL UNIQUE
      );
CREATE TABLE `api_servicemonitoroperation` (
      `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
      `handle_at` datetime(6) NOT NULL,
      `optype` integer NOT NULL,
      `monitor_id` integer NOT NULL,
      `operator_id` char(32) NOT NULL,
      `reason` longtext NOT NULL
      );
ALTER TABLE `api_servicemonitor`
ADD CONSTRAINT `api_servicemonitor_service_id_5b9208c8af1dc41c_fk_api_service_id`
FOREIGN KEY (`service_id`) REFERENCES `api_service` (`id`);
ALTER TABLE `api_servicemonitoroperation`
ADD CONSTRAINT `api_service_monitor_id_1f8b9ee521f0aee5_fk_api_servicemonitor_id`
FOREIGN KEY (`monitor_id`) REFERENCES `api_servicemonitor` (`id`);
ALTER TABLE `api_servicemonitoroperation`
ADD CONSTRAINT `api_servicemonitor_operator_id_41bf868fa4336df0_fk_api_person_id`
FOREIGN KEY (`operator_id`) REFERENCES `api_person` (`id`);

COMMIT;
