--
-- Create schema FlowWatch
--

CREATE DATABASE IF NOT EXISTS FlowWatch;
USE FlowWatch;

--
-- Definition of table `FlowWatch`.`FLOW`
--

DROP TABLE IF EXISTS `FlowWatch`.`FLOW`;
CREATE TABLE  `FlowWatch`.`FLOW` (
  `id` bigint(20) NOT NULL auto_increment,
  `idpetals` varchar(255) NOT NULL,
  `type` int(11) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `idpetals` (`idpetals`),
  UNIQUE KEY `idpetals_2` (`idpetals`)
) ENGINE=InnoDB AUTO_INCREMENT=2011 DEFAULT CHARSET=latin1;

--
-- Definition of table `FlowWatch`.`FLOWREF`
--

DROP TABLE IF EXISTS `FlowWatch`.`FLOWREF`;
CREATE TABLE  `FlowWatch`.`FLOWREF` (
  `id` bigint(20) NOT NULL auto_increment,
  `creationDate` datetime default NULL,
  `name` varchar(255) default NULL,
  `type` int(11) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `name` (`name`),
  UNIQUE KEY `type` (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Definition of table `FlowWatch`.`FLOWREF_PARAMNAMES`
--

DROP TABLE IF EXISTS `FlowWatch`.`FLOWREF_PARAMNAMES`;
CREATE TABLE  `FlowWatch`.`FLOWREF_PARAMNAMES` (
  `FLOWSTEPREF_id` bigint(20) NOT NULL,
  `global` bit(1) NOT NULL,
  `name` varchar(255) default NULL,
  `idx` int(11) NOT NULL,
  PRIMARY KEY  (`FLOWSTEPREF_id`,`idx`),
  KEY `FK_PARAMNAMES_id_FLOWREF` (`FLOWSTEPREF_id`),
  CONSTRAINT `FK_PARAMNAMES_id_FLOWREF` FOREIGN KEY (`FLOWSTEPREF_id`) REFERENCES `FLOWSTEPREF` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Definition of table `FlowWatch`.`FLOWSTEP`
--

DROP TABLE IF EXISTS `FlowWatch`.`FLOWSTEP`;
CREATE TABLE  `FlowWatch`.`FLOWSTEP` (
  `id` bigint(20) NOT NULL auto_increment,
  `endDate` datetime default NULL,
  `endpointName` varchar(255) default NULL,
  `errorCode` int(11) default NULL,
  `interfaceName` varchar(255) default NULL,
  `meUUID` varchar(255) NOT NULL,
  `serviceName` varchar(255) default NULL,
  `startDate` datetime default NULL,
  `status` int(11) default NULL,
  `flow_id` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `meUUID` (`meUUID`),
  KEY `FK_FLOW_id_FLOWSTEP_flow` (`flow_id`),
  CONSTRAINT `FK_FLOW_id_FLOWSTEP_flow` FOREIGN KEY (`flow_id`) REFERENCES `FLOW` (`idpetals`)
) ENGINE=InnoDB AUTO_INCREMENT=2011 DEFAULT CHARSET=latin1;

--
-- Definition of table `FlowWatch`.`FLOWSTEPERRORREF`
--

DROP TABLE IF EXISTS `FlowWatch`.`FLOWSTEPERRORREF`;
CREATE TABLE  `FlowWatch`.`FLOWSTEPERRORREF` (
  `id` bigint(20) NOT NULL auto_increment,
  `errorCode` int(11) default NULL,
  `message` varchar(255) default NULL,
  `flowstepref_id` bigint(20) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `flowstepref_id` (`flowstepref_id`,`errorCode`),
  KEY `FK_FLOWSTEPREF_id_FLOWSTEP` (`flowstepref_id`),
  CONSTRAINT `FK_FLOWSTEPREF_id_FLOWSTEP` FOREIGN KEY (`flowstepref_id`) REFERENCES `FLOWSTEPREF` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Definition of table `FlowWatch`.`FLOWSTEPREF`
--

DROP TABLE IF EXISTS `FlowWatch`.`FLOWSTEPREF`;
CREATE TABLE  `FlowWatch`.`FLOWSTEPREF` (
  `id` bigint(20) NOT NULL auto_increment,
  `defaultErrorMessage` varchar(255) default NULL,
  `flowEndStep` bit(1) default NULL,
  `flowStartStep` bit(1) default NULL,
  `interfaceName` varchar(255) default NULL,
  `name` varchar(255) default NULL,
  `serviceName` varchar(255) default NULL,
  `successMessage` varchar(255) default NULL,
  `flowref_id` bigint(20) NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `flowref_id` (`flowref_id`,`name`),
  UNIQUE KEY `flowref_id_2` (`flowref_id`,`interfaceName`,`serviceName`),
  KEY `FK_FLOWREF_id_FLOWSTEPREF_flowref` (`flowref_id`),
  CONSTRAINT `FK_FLOWREF_id_FLOWSTEPREF_flowref` FOREIGN KEY (`flowref_id`) REFERENCES `FLOWREF` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Definition of table `FlowWatch`.`FLOW_PARAMS`
--

DROP TABLE IF EXISTS `FlowWatch`.`FLOW_PARAMS`;
CREATE TABLE  `FlowWatch`.`FLOW_PARAMS` (
  `FLOWSTEP_id` bigint(20) NOT NULL,
  `element` varchar(255) default NULL,
  `idx` int(11) NOT NULL,
  PRIMARY KEY  (`FLOWSTEP_id`,`idx`),
  KEY `FK_FLOWPARAMS_id_FLOW` (`FLOWSTEP_id`),
  CONSTRAINT `FK_FLOWPARAMS_id_FLOW` FOREIGN KEY (`FLOWSTEP_id`) REFERENCES `FLOWSTEP` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
