diff --git a/src/db/migration/V20191001_1444__mantis15643.sql b/src/db/migration/V20191001_1444__mantis15643.sql new file mode 100644 index 000000000..fa4a13e58 --- /dev/null +++ b/src/db/migration/V20191001_1444__mantis15643.sql @@ -0,0 +1,52 @@ +declare + object_exists exception; + pragma exception_init (object_exists , -00955); +begin + execute immediate 'CREATE TABLE CONF_RESTRICAO_TRAMO ( + CONFRESTRICAOTRAMO_ID NUMBER(15,0) NOT NULL, + CONFRESTRICAOCANALVENTA_ID NUMBER(15,0), + TIPOPTOVTA_ID NUMBER(2), + ORIGEN_ID NUMBER(7), + DESTINO_ID NUMBER(7), + TEMPOPERMITIR DATE, + SEGUNDA NUMBER(1,0), + TERCA NUMBER(1,0), + QUARTA NUMBER(1,0), + QUINTA NUMBER(1,0), + SEXTA NUMBER(1,0), + SABADO NUMBER(1,0), + DOMINGO NUMBER(1,0), + USUARIO_ID NUMBER(7), + ACTIVO NUMBER(1,0), + FECMODIF DATE, + PRIMARY KEY (CONFRESTRICAOTRAMO_ID), + FOREIGN KEY (CONFRESTRICAOCANALVENTA_ID) REFERENCES CONF_RESTRICAO_CANALVENTA + )'; + exception when object_exists then null; +end; +/ +declare + object_exists exception; + pragma exception_init (object_exists , -00955); +begin + execute immediate + 'CREATE SEQUENCE "CONF_RESTRICAO_TRAMO_SEQ" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE'; + exception when object_exists then null; +end; +/ +declare + column_exists exception; + pragma exception_init (column_exists , -01430); +begin + execute immediate 'ALTER TABLE conf_restricao_ptovta ADD CONFRESTRICAOTRAMO_ID NUMBER(15,0) constraint CONFRESTRICAOPTOVTA_TRAMO_FK references CONF_RESTRICAO_TRAMO(CONFRESTRICAOTRAMO_ID) '; + exception when column_exists then null; +end; +/ +declare + column_exists exception; + pragma exception_init (column_exists , -01430); +begin + execute immediate 'ALTER TABLE conf_restricao_excecao ADD CONFRESTRICAOTRAMO_ID NUMBER(15,0) constraint CONFRESTRICAOEXCECAO_TRAMO_FK references CONF_RESTRICAO_TRAMO(CONFRESTRICAOTRAMO_ID) '; + exception when column_exists then null; +end; + diff --git a/src/db/migration/V20191002_1503__mantis15643.sql b/src/db/migration/V20191002_1503__mantis15643.sql new file mode 100644 index 000000000..c235e8736 --- /dev/null +++ b/src/db/migration/V20191002_1503__mantis15643.sql @@ -0,0 +1,77 @@ +DECLARE + sequencia NUMBER(15, 0); +BEGIN + FOR r IN ( + SELECT + confrestricaocanalventa_id, + tipoptovta_id, + origen_id, + destino_id, + tempopermitir, + segunda, + terca, + quarta, + quinta, + sexta, + sabado, + domingo, + usuario_id, + activo, + fecmodif + FROM + conf_restricao_canalventa + WHERE + fecfinvigencia >= SYSDATE + AND activo = 1 + ) LOOP + sequencia := conf_restricao_tramo_seq.nextval; + INSERT INTO conf_restricao_tramo ( + confrestricaotramo_id, + confrestricaocanalventa_id, + tipoptovta_id, + origen_id, + destino_id, + tempopermitir, + segunda, + terca, + quarta, + quinta, + sexta, + sabado, + domingo, + usuario_id, + activo, + fecmodif + ) VALUES ( + sequencia, + r.confrestricaocanalventa_id, + r.tipoptovta_id, + r.origen_id, + r.destino_id, + r.tempopermitir, + r.segunda, + r.terca, + r.quarta, + r.quinta, + r.sexta, + r.sabado, + r.domingo, + r.usuario_id, + r.activo, + r.fecmodif + ); + + UPDATE conf_restricao_excecao cre + SET + cre.confrestricaotramo_id = sequencia + WHERE + cre.confrestricaocanalventa_id = r.confrestricaocanalventa_id; + + UPDATE conf_restricao_ptovta crp + SET + crp.confrestricaotramo_id = sequencia + WHERE + crp.confrestricaocanalventa_id = r.confrestricaocanalventa_id; + + END LOOP; +END; \ No newline at end of file