CREATE TABLE STRUCTURE_TYPE
(
	ID            		NUMBER NOT NULL,     
	ORGANIZATION  		NUMBER NOT NULL,    
	CONTROL       		VARCHAR2(255), 
	CREATED_BY    		NUMBER,        
	CREATED_AT    		DATE NOT NULL,    
	UPDATED_BY    		NUMBER,       
	UPDATED_AT    		DATE NOT NULL,     
	LABEL         		VARCHAR2(255), 
	NRORG         		NUMBER 	     		DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO       		VARCHAR2(1)     	DEFAULT 'S' 					NOT NULL
		CONSTRAINT CKC_IDATIVO_STRUCTURE_TYPE CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        	DATE                  						NULL,
    DTULTATU          	DATE                  						NULL,
    NRORGINCLUSAO     	NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
    CDOPERINCLUSAO    	VARCHAR2(12)    DEFAULT '1' 					NULL,
    NRORGULTATU       	NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
    CDOPERULTATU      	VARCHAR2(12)    DEFAULT '1',
		CONSTRAINT PK_STRUCTURE_TYPE PRIMARY KEY (ID)
)
/

 CREATE TABLE SLACLIENTE 
   (	
	CDCLIENTE 		VARCHAR2(21) 	NOT NULL, 
	CDGRUPFASE 		VARCHAR2(2) 	NOT NULL, 
	CDASSUNTO 		VARCHAR2(5) 	NOT NULL, 
	CDCOMPLEXID 	VARCHAR2(2) 	NOT NULL, 
	QTDIASSLA 		FLOAT 			NOT NULL, 
	QTEXTRASLA 		FLOAT, 
	IDPRAZOSLA 		VARCHAR2(1), 
	QTDIASSLA2 		FLOAT, 
	QTDIASSLA3 		FLOAT, 
	NRORG 			NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL, 
	DTINCLUSAO 		DATE, 
	DTULTATU 		DATE, 
	NRORGINCLUSAO 	NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL, 
	CDOPERINCLUSAO 	VARCHAR2(12), 
	NRORGULTATU 	NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL, 
	CDOPERULTATU 	VARCHAR2(12), 
	IDATIVO 		VARCHAR2(1) DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_SLACLIENTE CHECK (IDATIVO IN ('S','N')), 
		CONSTRAINT PK_SLACLIENTE PRIMARY KEY (CDCLIENTE, CDGRUPFASE, CDASSUNTO, CDCOMPLEXID),
		CONSTRAINT CKC_IDPRAZOSLA CHECK (IDPRAZOSLA IS NULL OR (IDPRAZOSLA IN ('1','2'))), 
		CONSTRAINT FKGEP00185GRUPFASE FOREIGN KEY (CDGRUPFASE)
			REFERENCES GRUPFASE (CDGRUPFASE)
)
/

CREATE INDEX GEP00184_FK ON SLACLIENTE (CDCLIENTE) 
/

CREATE INDEX GEP00185_FK ON SLACLIENTE (CDGRUPFASE) 
/

CREATE INDEX GEP00186_FK ON SLACLIENTE (CDASSUNTO) 
/

CREATE INDEX GEP00187_FK ON SLACLIENTE (CDCOMPLEXID) 
/

ALTER TABLE SLACLIENTE ADD DTINICIOSLA DATE
/

ALTER TABLE SLACLIENTE_ALERT ADD CONSTRAINT FK_SLACLI_SLACLI_ALERT FOREIGN KEY (CDCLIENTE, CDGRUPFASE, CDASSUNTO, CDCOMPLEXID)
		REFERENCES SLACLIENTE (CDCLIENTE, CDGRUPFASE, CDASSUNTO, CDCOMPLEXID)
/
    
ALTER TABLE SLACLIENTE_ALERT ADD CONSTRAINT FK_STRUCT_TYPE_SLACLI_ALERT FOREIGN KEY (STRUCTURE_TYPE_ID)
		REFERENCES STRUCTURE_TYPE (ID) 
/

ALTER TABLE OM_ATUALIZACAO_ESTRUTURA ADD CD_SYSTEM_TICKET VARCHAR2(2)
/