CREATE TABLE MT_REPOSITORIO (
  ID               	NUMBER(10) 	 	NOT 	    NULL,
  NMREPOSITORIO    	VARCHAR2(500) 		NOT         NULL,
  DSURLREPOSITORIO 	VARCHAR2(500) 		NOT 	    NULL,
  NRORG            	NUMBER 		 	DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
  DTINCLUSAO       	DATE          		            NULL,
  DTULTATU         	DATE          		    	    NULL,
  NRORGINCLUSAO    	NUMBER        		DEFAULT 1   NULL,
  NRORGULTATU      	NUMBER        		DEFAULT 1   NULL,
  CDOPERINCLUSAO    	VARCHAR2(12)  		DEFAULT '1' NULL,
  CDOPERULTATU        	VARCHAR2(12)  		DEFAULT '1',
  IDATIVO          	VARCHAR2(1)   		DEFAULT 'S' NOT NULL
	CONSTRAINT CKC_IDATIVO_MT_REPOSITORIO CHECK (IDATIVO IN ('S','N')),
	CONSTRAINT PK_MT_REPOSITORIO PRIMARY KEY(ID)
)
/
CREATE TABLE MT_REPOSITORIO_OPERADOR (
  ID               		NUMBER(10)    	NOT NULL,
  REPOSITORIO_ID   		NUMBER(10)    	NOT NULL,
  CDOPERADOR       		VARCHAR2(12)  	NOT NULL,
  DSDIRREPOSITORIO 		VARCHAR2(500) 	NOT NULL,
  NRORG            		NUMBER 		 DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
  DTINCLUSAO       		DATE          		  NULL,
  DTULTATU         		DATE          		  NULL,
  NRORGINCLUSAO    		NUMBER        	DEFAULT 1 NULL,
  NRORGULTATU      		NUMBER        	DEFAULT 1 NULL,
  CDOPERINCLUSAO    		VARCHAR2(12)  	DEFAULT '1' NULL,
  CDOPERULTATU        		VARCHAR2(12)  	DEFAULT '1',
  IDATIVO          		VARCHAR2(1)   	DEFAULT 'S' NOT NULL
	CONSTRAINT CKC_IDATIVO_MT_REP_OPE     CHECK (IDATIVO IN ('S','N')),
	CONSTRAINT PK_MT_REPOSITORIO_OPERADOR PRIMARY KEY(ID)
)
/
CREATE INDEX MT00001_FK ON MT_REPOSITORIO_OPERADOR (CDOPERADOR ASC)
/
ALTER TABLE MT_REPOSITORIO_OPERADOR ADD CONSTRAINT FKMT00001REP_OPE_OPE FOREIGN KEY (CDOPERADOR) REFERENCES OPERADOR (CDOPERADOR)
/
CREATE INDEX MT00002_FK ON MT_REPOSITORIO_OPERADOR (REPOSITORIO_ID ASC)
/
ALTER TABLE MT_REPOSITORIO_OPERADOR ADD CONSTRAINT FKMT00002REP_OPE_REPO FOREIGN KEY (REPOSITORIO_ID) REFERENCES MT_REPOSITORIO (ID)
/
CREATE TABLE MT_DESIGN_ESTRUTURA (
  ID               	   NUMBER(10) 	 	 NOT NULL,
  SCRIPT 		   CLOB 		 NOT NULL,
  SCRIPT_SUC 	   	   CLOB 		 NOT NULL,
  SCRIPT_ERR 	   	   CLOB 		 NOT NULL,
  NRSCRIPT		   NUMBER(10)    	 NOT NULL,	
  DSDESESTRUTURA   	   VARCHAR2(500) 	     NULL,
  DSDIRLOG 		   VARCHAR2(500) 	 NOT NULL,
  IDRESULTSCRIPT           VARCHAR2(1)   	 DEFAULT 'P' NOT NULL,
  REPOSITORIO_ID   	   NUMBER(10)    	 NOT NULL,
  NRORG            	   NUMBER 		 DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
  DTINCLUSAO       	   DATE          	 NULL,
  DTULTATU         	   DATE          	 NULL,
  NRORGINCLUSAO    	   NUMBER        	 DEFAULT 1 NULL,
  NRORGULTATU      	   NUMBER        	 DEFAULT 1 NULL,
  CDOPERINCLUSAO    	   VARCHAR2(12)  	 DEFAULT '1' NULL,
  CDOPERULTATU             VARCHAR2(12)  	 DEFAULT '1',
  IDATIVO                  VARCHAR2(1)   	 DEFAULT 'S' NOT NULL
	CONSTRAINT CKC_IDATIVO_MT_DES_EST CHECK (IDATIVO IN ('S','N')),
	CONSTRAINT PK_MT_DESIGN_ESTRUTURA PRIMARY KEY(ID)
)
/
CREATE INDEX MT00003_FK ON MT_DESIGN_ESTRUTURA (REPOSITORIO_ID ASC)
/
ALTER TABLE MT_DESIGN_ESTRUTURA ADD CONSTRAINT FKMT00003DES_EST_REPO FOREIGN KEY (REPOSITORIO_ID) REFERENCES MT_REPOSITORIO (ID)