-- Deploy gaia:bdtransfer_2020_05_28_add_bdtransfer_visit_record to mysql

BEGIN;

-- XXX Add DDLs here.
CREATE TABLE `api_bdtransfer_visitrecord` (
  `id` int NOT NULL AUTO_INCREMENT,
  `bdtransfer_id` int NOT NULL,
  `method` smallint NOT NULL default 0,
  `type` smallint NOT NULL default 0,
  `state` smallint default NULL,
  `status` tinyint(1) NOT NULL default 1,
  `creator_id` int NOT NULL,
  `assignor_id` int NOT NULL,
  `create_at` datetime(6) NOT NULL,
  `plan_at` datetime(6) NOT NULL,
  `visit_at` datetime(6) NULL,
  `remarks` varchar(500) not null default '',
  PRIMARY KEY (`id`),
  KEY `api_bdtransfer_visitrecord_0100880d_fk_api_bdtransfer` (`bdtransfer_id`),
  KEY `api_bdtransfer_visitrecord_0100880d_fk_auth_user` (`creator_id`),
  KEY `api_bdtransfer_visitrecord_0200880d_fk_auth_user` (`assignor_id`),
  CONSTRAINT `api_bdtransfer_visitrecord_ibfk_1` FOREIGN KEY (`bdtransfer_id`) REFERENCES `api_bdtransfer` (`id`),
  CONSTRAINT `api_bdtransfer_visitrecord_ibfk_2` FOREIGN KEY (`creator_id`) REFERENCES `auth_user` (`id`),
  CONSTRAINT `api_bdtransfer_visitrecord_ibfk_3` FOREIGN KEY (`assignor_id`) REFERENCES `auth_user` (`id`)
  );

ALTER TABLE `api_bdtransfer_communicationrecord` add `visit_record_id` int default NULL;
ALTER TABLE `api_bdtransfer_communicationrecord` add constraint api_bdtransfer_communicationrecord_ibfk_1 foreign key (`visit_record_id`) REFERENCES `api_bdtransfer_visitrecord`(`id`);


COMMIT;
