From 65f095e8b831e02b50c775c0724bdcc926c82a85 Mon Sep 17 00:00:00 2001 From: emerson Date: Tue, 24 Jul 2018 17:39:28 +0000 Subject: [PATCH] fixes bug#0011649 dev: emerson qua: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implementação para garantir a integridade da tabela TARIFA, podendo existir apenas um registro ativo com os seguintes valores: TRAMO_ID, MARCA_ID, CLASESERVICIO_ID, MONEDA_ID, VIGENCIATARIFA_ID, ORGAOCONCEDENTE_ID e RUTA_ID. git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/BD/FlyWay/trunk@83599 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../migration/V20180724_1141__mantis11649.sql | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/db/migration/V20180724_1141__mantis11649.sql diff --git a/src/db/migration/V20180724_1141__mantis11649.sql b/src/db/migration/V20180724_1141__mantis11649.sql new file mode 100644 index 000000000..ae6835c24 --- /dev/null +++ b/src/db/migration/V20180724_1141__mantis11649.sql @@ -0,0 +1,35 @@ +declare +itemExists number; +instrucao varchar2(255); +begin + itemExists := 0; + + select count(constraint_name) into itemExists + from all_constraints + where upper(constraint_name) = upper('TARIFA_UNICA'); + + if itemExists > 0 then + execute immediate 'ALTER TABLE TARIFA DROP CONSTRAINT TARIFA_UNICA'; + end if; + + + select 'DROP INDEX '||OWNER||'.TARIFA_UNICA' into instrucao + from all_indexes + where upper(index_name) = upper('TARIFA_UNICA'); + + if instrucao is not null then + execute immediate instrucao; + end if; + +end;/ + +declare + column_exists exception; + pragma exception_init (column_exists , -00001); +begin + execute immediate 'CREATE UNIQUE INDEX UNQ_TARIFA ON TARIFA (CASE WHEN ACTIVO = 1 THEN + TRAMO_ID || MARCA_ID || CLASESERVICIO_ID || MONEDA_ID || VIGENCIATARIFA_ID || ORGAOCONCEDENTE_ID || RUTA_ID + ELSE NULL END)'; + exception when column_exists then null; +end; +/