use cnfm;

CREATE TABLE IF NOT EXISTS `JOB` (
  `JOB_ID` varchar(255) NOT NULL,
  `JOB_TYPE` varchar(255) NOT NULL,
  `JOB_ACTION` varchar(255) NOT NULL,
  `RESOURCE_ID` varchar(255) NOT NULL,
  `RESOURCE_NAME` varchar(255) DEFAULT NULL,
  `STATUS` varchar(255) NOT NULL,
  `START_TIME` DATETIME DEFAULT NULL,
  `END_TIME` DATETIME DEFAULT NULL,
  `PROCESS_INSTANCE_ID` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`JOB_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `JOB_STATUS` (
  `ID` INT NOT NULL AUTO_INCREMENT,
  `UPDATED_TIME` DATETIME NOT NULL,
  `DESCRIPTION` longtext DEFAULT NULL,
  `STATUS` varchar(255) NOT NULL,
  `JOB_ID` varchar(255) NOT NULL,
  PRIMARY KEY (`ID`),
  FOREIGN KEY (JOB_ID)
      REFERENCES JOB(JOB_ID)
      ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `AS_INST` (
  `AS_INST_ID` varchar(255) NOT NULL,
  `NAME` varchar(255) NOT NULL,
  `DESCRIPTION` longtext DEFAULT NULL,
  `AS_PACKAGE_ID` varchar(255) DEFAULT NULL,
  `ASD_ID` varchar(255) NOT NULL,
  `ASD_INVARIANT_ID` varchar(255) NOT NULL,
  `AS_PROVIDER` varchar(255) NOT NULL,
  `AS_APPLICATION_NAME` varchar(255) NOT NULL,
  `AS_APPLICATION_VERSION` varchar(255) NOT NULL,
  `SERVICE_INSTANCE_ID` varchar(255) NOT NULL,
  `SERVICE_INSTANCE_NAME` varchar(255) NOT NULL,
  `CLOUD_OWNER` varchar(255) NOT NULL,
  `CLOUD_REGION` varchar(255) NOT NULL,
  `TENANT_ID` varchar(255) NOT NULL,
  `STATUS` varchar(255) NOT NULL,
  `STATUS_UPDATED_TIME` DATETIME NOT NULL,
  PRIMARY KEY (`AS_INST_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `AS_DEPLOYMENT_ITEM` (
  `AS_DEP_ITEM_INST_ID` varchar(255) NOT NULL,
  `NAME` varchar(255) DEFAULT NULL,
  `ITEM_ID` varchar(255) DEFAULT NULL,
  `DEPLOYMENT_ORDER` int(11) DEFAULT NULL,
  `ARTIFACT_FILE_PATH` varchar(255) DEFAULT NULL,
  `STATUS` varchar(255) DEFAULT NULL,
  `AS_INST_ID` varchar(255) NOT NULL,
  `CREATE_TIME` DATETIME DEFAULT NULL,
  `LAST_UPDATE_TIME` DATETIME DEFAULT NULL,
  `RELEASE_NAME` varchar(255) NOT NULL,
  PRIMARY KEY (`AS_DEP_ITEM_INST_ID`),
  FOREIGN KEY (AS_INST_ID)
      REFERENCES AS_INST(AS_INST_ID)
	  ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `AS_LIFECYCLE_PARAM` (
  `AS_LCP_ID` INT NOT NULL AUTO_INCREMENT,
  `AS_DEP_ITEM_INST_ID` varchar(255) NOT NULL,
  `LIFECYCLE_PARAM` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`AS_LCP_ID`),
  FOREIGN KEY (AS_DEP_ITEM_INST_ID)
      REFERENCES AS_DEPLOYMENT_ITEM(AS_DEP_ITEM_INST_ID)
      ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `AS_LCM_OP_OCCS` (
  `ID` varchar(255) NOT NULL,
  `OPERATION_STATE` varchar(255) NOT NULL,
  `STATE_ENTERED_TIME` DATETIME DEFAULT NULL,
  `START_TIME` DATETIME DEFAULT NULL,
  `AS_INST_ID` varchar(255) NOT NULL,
  `OPERATION` varchar(255) NOT NULL,
  `IS_AUTO_INVOCATION` varchar(255) NOT NULL,
  `OPERATION_PARAMS` longtext NOT NULL,
  `IS_CANCEL_PENDING` varchar(255) NOT NULL,
  `CANCEL_MODE` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  FOREIGN KEY (AS_INST_ID)
      REFERENCES AS_INST(AS_INST_ID)
	  ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
