From e8e404f9bc1fd717713b41391059588f576a1666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Sconetto?= Date: Thu, 9 Nov 2017 18:21:59 -0200 Subject: [PATCH] =?UTF-8?q?Verifica=20a=20repeti=C3=A7=C3=A3o=20em=20mater?= =?UTF-8?q?ias?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/legacy/migration.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/sapl/legacy/migration.py b/sapl/legacy/migration.py index e72f50e45..8e2b5948d 100644 --- a/sapl/legacy/migration.py +++ b/sapl/legacy/migration.py @@ -200,6 +200,16 @@ def migra_autor(): SQL_DELETE_AUTOR_INATIVO = "delete from autor where cod_autor in ({});" + SQL_ENUMERA_AUTORIA_REPETIDOS = ''' + select cod_materia, COUNT(*) from autoria where cod_autor in ({}) + group by cod_materia + having 1 < COUNT(*); + ''' + + SQL_INFO_AUTORIA = ''' + select * from autoria where cod_materia = {} and cod_autor in ({}); + ''' + cursor = exec_legado(SQL_ENUMERA_REPETIDOS) all_authors = [] @@ -223,7 +233,7 @@ def migra_autor(): # tupl[8] = ind_excluido if tupl[8] == 1: inativ.append(tupl) - elif tupl[8] == 0:\ + elif tupl[8] == 0: ativ.append(tupl) tables = ['autoria', 'documento_administrativo', 'proposicao', 'protocolo'] @@ -232,6 +242,15 @@ def migra_autor(): ativId = ativ[0][0] inativIds = [u[0] for u in inativ] inativIds = (str(inativIds)).replace(']', '').replace('[', '') + + sql = SQL_ENUMERA_AUTORIA_REPETIDOS.format(ativId + ', ' + inativIds) + cursor = exec_legado(sql) + + for response in cursor: + sql = SQL_INFO_AUTORIA.format(response[0], ativId + ', ' + inativIds) + materias = exec_legado(sql) + + sql = SQL_UPDATE_TABLES_AUTOR.format(table, ativId, inativIds) exec_legado(sql)