drop table if exists FLOW_PARAMS;
drop table if exists FLOWSTEPERRORREF;
drop table if exists FLOWREF_PARAMNAMES;
drop table if exists FLOWSTEPREF;
drop table if exists FLOWSTEP;
drop table if exists FLOWREF;
drop table if exists FLOW;

create table FLOW (id bigint not null auto_increment,idpetals varchar(255) NOT NULL unique, type int,PRIMARY KEY  (id)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
create table FLOWSTEP(id bigint not null auto_increment, endDate datetime, endpointName varchar(255),errorCode int,interfaceName varchar(255), meUUID varchar(255),serviceName varchar(255),startDate datetime, status int, flow_id varchar(255) NOT NULL,PRIMARY KEY  (id))ENGINE=InnoDB DEFAULT CHARSET=latin1;
create table FLOW_PARAMS (FLOWSTEP_id bigint NOT NULL,element varchar(255),idx int NOT NULL, PRIMARY KEY  (FLOWSTEP_id,idx)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
create table FLOWREF (id bigint NOT NULL auto_increment,creationDate datetime,name varchar(255) unique, type int unique, PRIMARY KEY  (id)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
create table  FLOWSTEPREF (id bigint NOT NULL auto_increment,defaultErrorMessage varchar(255), flowEndStep bit,flowStartStep bit,interfaceName varchar(255),name varchar(255),serviceName varchar(255),successMessage varchar(255),flowref_id bigint NOT NULL,PRIMARY KEY  (id)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
create table FLOWREF_PARAMNAMES (FLOWSTEPREF_id bigint NOT NULL,global bit NOT NULL,name varchar(255), idx int NOT NULL,PRIMARY KEY  (FLOWSTEPREF_id,idx)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
create table FLOWSTEPERRORREF (id bigint NOT NULL auto_increment,errorCode int,message varchar(255), flowstepref_id bigint,PRIMARY KEY  (id)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
alter table FLOWREF_PARAMNAMES add index FK_PARAMNAMES_id_FLOWREF (FLOWSTEPREF_id), add constraint FK_PARAMNAMES_id_FLOWREF foreign key (FLOWSTEPREF_id) references FLOWSTEPREF (id);
alter table FLOWSTEP add index FK_FLOW_id_FLOWSTEP_flow (flow_id), add constraint FK_FLOW_id_FLOWSTEP_flow foreign key (flow_id) references FLOW (idpetals);
alter table FLOWSTEPERRORREF add index FK_FLOWSTEPREF_id_FLOWSTEP (flowstepref_id), add constraint FK_FLOWSTEPREF_id_FLOWSTEP foreign key (flowstepref_id) references FLOWSTEPREF (id);
alter table FLOWSTEPREF add index FK_FLOWREF_id_FLOWSTEPREF_flowref (flowref_id), add constraint FK_FLOWREF_id_FLOWSTEPREF_flowref foreign key (flowref_id) references FLOWREF (id);
alter table FLOW_PARAMS add index FK_FLOWPARAMS_id_FLOW (FLOWSTEP_id), add constraint FK_FLOWPARAMS_id_FLOW foreign key (FLOWSTEP_id) references FLOWSTEP (id);
 




