diff --git a/src/db/migration/V20190820_1444__mantis15267.sql b/src/db/migration/V20190820_1444__mantis15267.sql new file mode 100644 index 000000000..c68ce6115 --- /dev/null +++ b/src/db/migration/V20190820_1444__mantis15267.sql @@ -0,0 +1,7 @@ +declare + column_exists exception; + pragma exception_init (column_exists , -01430); +begin + execute immediate 'ALTER TABLE BPE_CTRL_DISPONIBILIDADE ADD (TIPO_VENDA VARCHAR(20))'; + exception when column_exists then null; +end; \ No newline at end of file diff --git a/src/db/migration/V20190820_1445__mantis15267.sql b/src/db/migration/V20190820_1445__mantis15267.sql new file mode 100644 index 000000000..48beeec48 --- /dev/null +++ b/src/db/migration/V20190820_1445__mantis15267.sql @@ -0,0 +1,39 @@ +declare + object_exists exception; + pragma exception_init (object_exists , -00001); +begin + execute immediate 'merge into bpe_ctrl_disponibilidade cd1 + using + ( + select b.tipoventa_id, cd.bpectrldisp_id, cd.tipo_venda + from bpe_ctrl_disponibilidade cd + join bpe bpe on bpe.bpe_id = cd.bpe_rejeitado_id + left join boleto b on b.boleto_id = bpe.boleto_id + where cd.activo = 1 + and b.tipoventa_id = 99 + and cd.tipo_venda is null + ) t on (cd1.bpectrldisp_id = t.bpectrldisp_id) + WHEN MATCHED THEN UPDATE SET cd1.tipo_venda = ''EMBARCADA'' + '; + exception when object_exists then null; +end; +/ +declare + object_exists exception; + pragma exception_init (object_exists , -00001); +begin + execute immediate 'merge into bpe_ctrl_disponibilidade cd1 + using + ( + select b.tipoventa_id, cd.bpectrldisp_id, cd.tipo_venda + from bpe_ctrl_disponibilidade cd + join bpe bpe on bpe.bpe_id = cd.bpe_rejeitado_id + left join boleto b on b.boleto_id = bpe.boleto_id + where cd.activo = 1 + and b.tipoventa_id <> 99 + and cd.tipo_venda is null + ) t on (cd1.bpectrldisp_id = t.bpectrldisp_id) + WHEN MATCHED THEN UPDATE SET cd1.tipo_venda = ''TOTALBUS'' + '; + exception when object_exists then null; +end; \ No newline at end of file diff --git a/src/db/postgresql/migration/V20190820_1444__mantis15267.sql b/src/db/postgresql/migration/V20190820_1444__mantis15267.sql new file mode 100644 index 000000000..bbc5c74f5 --- /dev/null +++ b/src/db/postgresql/migration/V20190820_1444__mantis15267.sql @@ -0,0 +1,6 @@ +DO $$ +BEGIN + ALTER TABLE BPE_CTRL_DISPONIBILIDADE ADD (TIPO_VENDA VARCHAR(20)); + EXCEPTION WHEN duplicate_column THEN NULL; +END +$$; \ No newline at end of file