Browse Source

Arruma scripts de migração (#1479)

* Retira senhas hardcoded

Signed-off-by: Luciano Almeida <lucianoalmeida@interlegis.leg.br>

* Arruma ajuste de proposição

Signed-off-by: Luciano Almeida <lucianoalmeida@interlegis.leg.br>
pull/1490/head
Luciano Henrique Nunes de Almeida 7 years ago
committed by Edward
parent
commit
77f0f8c7bf
  1. 18
      sapl/legacy/migration.py
  2. 8
      sapl/legacy/scripts/migra_dbs.sh
  3. 37
      sapl/legacy/scripts/migra_um_db.sh
  4. 8
      sapl/legacy/scripts/recria_dbs_postgres.sh
  5. 1
      sapl/legacy/scripts/recria_um_db_postgres.sh

18
sapl/legacy/migration.py

@ -424,9 +424,12 @@ def adjust_mandato(new, old):
if old.dat_fim_mandato:
new.data_fim_mandato = old.dat_fim_mandato
if not new.data_fim_mandato:
new.data_fim_mandato = new.legislatura.data_fim
legislatura = Legislatura.objects.latest('data_fim')
new.data_fim_mandato = legislatura.data_fim
new.data_expedicao_diploma = legislatura.data_inicio
if not new.data_inicio_mandato:
new.data_inicio_mandato = new.legislatura.data_inicio
new.data_fim_mandato = new.legislatura.data_fim
def adjust_ordemdia_antes_salvar(new, old):
@ -556,11 +559,18 @@ def adjust_tipoafastamento(new, old):
def adjust_tipoproposicao(new, old):
if old.ind_mat_ou_doc == 'M':
new.tipo_conteudo_related = TipoMateriaLegislativa.objects.get(
tipo_materia = TipoMateriaLegislativa.objects.filter(
pk=old.tip_mat_ou_doc)
if tipo_materia:
new.tipo_conteudo_related = tipo_materia[0]
else:
raise ForeignKeyFaltando
elif old.ind_mat_ou_doc == 'D':
new.tipo_conteudo_related = TipoDocumento.objects.get(
pk=old.tip_mat_ou_doc)
tipo_documento = TipoDocumento.objects.filter(pk=old.tip_mat_ou_doc)
if tipo_documento:
new.tipo_conteudo_related = tipo_documento[0]
else:
raise ForeignKeyFaltando
def adjust_statustramitacao(new, old):

8
sapl/legacy/scripts/migra_dbs.sh

@ -2,4 +2,10 @@
# rodar esse script na raiz do projeto
parallel --verbose ./sapl/legacy/scripts/migra_um_db.sh :::: <(mysql -u root -padmin -e 'show databases;' | grep '^sapl_')
if [ $# -eq 2 ]; then
parallel -eta --verbose ./sapl/legacy/scripts/migra_um_db.sh :::: <(mysql -u $1 -p$2 -e 'show databases;' | grep '^sapl_' | grep -v '_copy$') ::: $1 ::: $2
else
echo "USO:"
echo " ./sapl/legacy/scripts/migra_dbs.sh [usuário mysql] [senha mysql]"
fi;

37
sapl/legacy/scripts/migra_um_db.sh

@ -1,20 +1,33 @@
#!/bin/bash
# rodar esse script na raiz do projeto
if [ $# -eq 3 ]; then
DIR=~/logs_migracao
mkdir -p $DIR
DIR=~/logs_migracao
mkdir -p $DIR
LOG="$DIR/$1.migracao.log"
rm -f $LOG
LOG="$DIR/$1.migracao.log"
rm -f $LOG
echo "########################################" | tee -a $LOG
echo "MIGRANDO BANCO $1" | tee -a $LOG
echo "########################################" | tee -a $LOG
echo >> $LOG
echo "########################################" | tee -a $LOG
echo "MIGRANDO BANCO $1" | tee -a $LOG
echo "########################################" | tee -a $LOG
echo >> $LOG
echo "--- CRIANDO BACKUP ---" | tee -a $LOG
echo >> $LOG
mysql -u $2 -p$3 -e "create database if not exists $1_copy;" && mysqldump -u $2 -p$3 $1 | mysql -u $2 -p$3 $1_copy;
echo >> $LOG
echo "--- DJANGO MIGRATE ---" | tee -a $LOG
echo >> $LOG
DATABASE_NAME=$1 ./manage.py migrate --settings sapl.legacy_migration_settings
echo >> $LOG
echo "--- MIGRACAO DE DADOS ---" | tee -a $LOG
echo >> $LOG
DATABASE_NAME=$1 ./manage.py migracao_25_31 -f --settings sapl.legacy_migration_settings |& tee -a $LOG
echo >> $LOG
echo "--- MIGRACAO DE DADOS ---" | tee -a $LOG
echo >> $LOG
DATABASE_NAME=$1 ./manage.py migracao_25_31 -f --settings sapl.legacy_migration_settings |& tee -a $LOG
echo >> $LOG
else
echo "USO:"
echo " ./sapl/legacy/scripts/migra_um_db.sh [nome_database] [usuário mysql] [senha mysql]"
fi;

8
sapl/legacy/scripts/recria_dbs_postgres.sh

@ -1,5 +1,11 @@
# (Re)cria todos os bancos postgres para migração
# cria um banco postgres (de mesmo nome) para cada banco mysql cujo nome começa com "sapl_"
mysql -u root -padmin -e 'show databases;' | grep '^sapl_' | xargs -I{} ./recria_um_db_postgres.sh {}
if [ $# -eq 2 ]; then
parallel --verbose ./recria_um_db_postgres.sh :::: <(mysql -u $1 -p$2 -e 'show databases;' | grep '^sapl_' | grep -v '_copy$')
else
echo "USO:"
echo " ./recria_dbs_postgres.sh [usuário mysql] [senha mysql]"
fi;

1
sapl/legacy/scripts/recria_um_db_postgres.sh

@ -1,5 +1,6 @@
# (Re)cria um db postgres
# uso: recria_um_db_postgres <NOME DO BANCO>
echo "Database $1"
sudo -u postgres psql -c "drop DATABASE if exists $1"
sudo -u postgres psql -c "CREATE DATABASE $1 WITH OWNER = sapl ENCODING = 'UTF8' TABLESPACE = pg_default LC_COLLATE = 'pt_BR.UTF-8' LC_CTYPE = 'pt_BR.UTF-8' CONNECTION LIMIT = -1 TEMPLATE template0;"

Loading…
Cancel
Save