--ABS-75808 / ABS-77318

------------ DIALOGUSELOG ------------
CREATE SEQUENCE SEQ_DIALOGUSELOG START WITH 1 INCREMENT BY 1;

CREATE TABLE DIALOGUSELOG (
  DIALOGUSELOG_ID         NUMBER NOT NULL,
  PLANT_ID                NUMBER NULL,
  WORKSTATION_ID          NUMBER NULL,
  DIALOG_ID               NUMBER NOT NULL,
  OPENTIMESTAMP           DATE NOT NULL,
  CLOSETIMESTAMP          DATE NULL,
  LOGGEDDATE              DATE NOT NULL,
  SYSTEMUSER_ID           NUMBER DEFAULT 0 NOT NULL,
  TIMESTAMP               DATE DEFAULT SYSDATE NOT NULL
);

ALTER TABLE DIALOGUSELOG
  ADD CONSTRAINT PK_DIALOGUSELOG_ID PRIMARY KEY (DIALOGUSELOG_ID);

CREATE INDEX XIF1DIALOGUSELOG ON DIALOGUSELOG (PLANT_ID ASC);
CREATE INDEX XIF2DIALOGUSELOG ON DIALOGUSELOG (WORKSTATION_ID ASC);
CREATE INDEX XIF3DIALOGUSELOG ON DIALOGUSELOG (DIALOG_ID ASC);
CREATE INDEX XIE1DIALOGUSELOG ON DIALOGUSELOG (LOGGEDDATE ASC);
  
ALTER TABLE DIALOGUSELOG ADD CONSTRAINT FK_DIALOGUSELOG_PLANT_ID 
 FOREIGN KEY (PLANT_ID)  
 REFERENCES PLANT (PLANT_ID) ON DELETE CASCADE;
 
ALTER TABLE DIALOGUSELOG ADD CONSTRAINT FK_DIALOGUSELOG_WORKSTATION_ID 
 FOREIGN KEY (WORKSTATION_ID)  
 REFERENCES WORKSTATION (WORKSTATION_ID)  ON DELETE CASCADE;
 
ALTER TABLE DIALOGUSELOG ADD CONSTRAINT FK_DIALOGUSELOG_DIALOG_ID
 FOREIGN KEY (DIALOG_ID)  
 REFERENCES DIALOGS (DIALOG_ID)  ON DELETE CASCADE;