Commit 04df8fe32a5e8d7111efb839a60742a0504fc848

Authored by Daniel Alves + Diego Araújo + Guilherme Rojas
Committed by Paulo Meireles
1 parent 61945fc5

[Mezuro] Changed script for kalibro database.

plugins/mezuro/script/kalibro_scripts.conf
1 # Definition of constants used in kalibro scripts. 1 # Definition of constants used in kalibro scripts.
2 2
  3 +KALIBRO_DIR=~/kalibro
  4 +PSQLFILE=$KALIBRO_DIR/KalibroCore/src/META-INF/PostgreSQL.sql
3 DATABASE="kalibro_test" 5 DATABASE="kalibro_test"
4 PASSWORD="kalibro" 6 PASSWORD="kalibro"
5 QUERYFILE=/tmp/query 7 QUERYFILE=/tmp/query
6 -EXCEPTION="sequences" 8 +
plugins/mezuro/script/prepare_kalibro_query_file.sh
@@ -2,8 +2,16 @@ @@ -2,8 +2,16 @@
2 2
3 source plugins/mezuro/script/kalibro_scripts.conf 3 source plugins/mezuro/script/kalibro_scripts.conf
4 4
5 -sudo su postgres -c "export PGPASSWORD=$PASSWORD &&  
6 - if [ -f $QUERYFILE ]  
7 - then rm $QUERYFILE  
8 - fi &&  
9 - psql -q -t -d $DATABASE -c \"SELECT 'DELETE FROM ' || n.nspname || '.' || c.relname || ' CASCADE;' FROM pg_catalog.pg_class AS c LEFT JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace WHERE relkind = 'r' AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND pg_catalog.pg_table_is_visible(c.oid)\" | sed '/$EXCEPTION/d' | sort > $QUERYFILE" 5 +DROPLIMIT="END OF DROP TABLES"
  6 +RANGE=$(grep -n "$DROPLIMIT" $PSQLFILE | cut -d":" -f1)
  7 +START=1
  8 +END=$(($RANGE - 1))
  9 +CUT=$START,$END\!d
  10 +REPLACE="s/DROP TABLE IF EXISTS sequences,/TRUNCATE/"
  11 +
  12 +if [ -f $QUERYFILE ]
  13 + then sudo rm $QUERYFILE
  14 +fi
  15 +
  16 +sed -e "$CUT" -e "$REPLACE" $PSQLFILE > $QUERYFILE
  17 +sudo chown postgres.postgres $QUERYFILE