cartodb/script/ci/cleaner.sh

52 lines
1.8 KiB
Bash
Raw Normal View History

2020-06-15 10:58:47 +08:00
#!/bin/bash
# Kill redis
killall redis-server
# Drop all databases
databases=$(psql -U postgres -t -c "select datname from pg_database where datname like 'carto_db_test_%'")
touch parallel_tests/databases.log
echo $databases >> parallel_tests/databases.log
touch parallel_tests/databases_new.log
sed -e 's/\s\+/\n/g' parallel_tests/databases.log > parallel_tests/databases_new.log
while read -r line
do
psql -U postgres -t -c "drop database $line" >> parallel_tests/cleaner.log
done < parallel_tests/databases_new.log
# Drop all user databases
databases=$(psql -U postgres -t -c "select datname from pg_database where datname like 'cartodb_test_user_%'")
touch parallel_tests/user_databases.log
echo $databases >> parallel_tests/user_databases.log
touch parallel_tests/user_databases_new.log
sed -e 's/\s\+/\n/g' parallel_tests/user_databases.log > parallel_tests/user_databases_new.log
while read -r line
do
psql -U postgres -t -c "drop database \"$line\"" >> parallel_tests/cleaner.log
done < parallel_tests/user_databases_new.log
rm parallel_tests/user_databases.log
rm parallel_tests/users_databases_new.log
# Drop all testing databases
databases=$(psql -U postgres -t -c "select datname from pg_database where datname like 'cartodb_user_%'")
touch parallel_tests/user_databases.log
echo $databases >> parallel_tests/user_databases.log
touch parallel_tests/user_databases_new.log
sed -e 's/\s\+/\n/g' parallel_tests/user_databases.log > parallel_tests/user_databases_new.log
while read -r line
do
psql -U postgres -t -c "drop database \"$line\"" >> parallel_tests/cleaner.log
done < parallel_tests/user_databases_new.log
# Cleanup
rm parallel_tests/databases.log
rm parallel_tests/databases_new.log
rm parallel_tests/user_databases.log
rm parallel_tests/users_databases_new.log
echo "# Cleaner finished"