File tree Expand file tree Collapse file tree 2 files changed +37
-7
lines changed
.github/actions/run-tests Expand file tree Collapse file tree 2 files changed +37
-7
lines changed Original file line number Diff line number Diff line change 1- #! /bin/sh -e
1+ #! /bin/bash -e
22
33BACKUP=" $1 "
44
@@ -13,8 +13,30 @@ case "$INPUT_DB" in
1313 mysql -u root -p" $MYSQL_ROOT_PASSWORD " -h mysql < " /dumps/$BACKUP /sql/dump.sql"
1414 ;;
1515 pgsql)
16+ echo ' Dropping old data'
1617 PGPASSWORD=" $POSTGRES_PASSWORD " \
17- psql -d " $POSTGRES_DB " -h postgres -U " $POSTGRES_USER " < " /dumps/$BACKUP /sql/dump.sql"
18+ psql -d " $POSTGRES_DB " -h postgres -U " $POSTGRES_USER " -v ' ON_ERROR_STOP=1' << - EOF || exit 1
19+ DROP SCHEMA public CASCADE;
20+ CREATE SCHEMA public;
21+ GRANT ALL ON SCHEMA public TO $POSTGRES_USER ;
22+ GRANT ALL ON SCHEMA public TO public;
23+ EOF
24+
25+ # PGPASSWORD="$POSTGRES_PASSWORD" \
26+ # psql -d "$POSTGRES_DB" -h postgres -U "$POSTGRES_USER" <<- EOF
27+ # \l
28+ # \d
29+ # SELECT * FROM oc_preferences WHERE appid='cookbook';
30+ # EOF
31+
32+ echo ' Inserting dump data'
33+ PGPASSWORD=" $POSTGRES_PASSWORD " \
34+ psql -d " $POSTGRES_DB " -h postgres -U " $POSTGRES_USER " -f " /dumps/$BACKUP /sql/dump.sql" -v ' ON_ERROR_STOP=1' || exit 1
35+
36+ # PGPASSWORD="$POSTGRES_PASSWORD" \
37+ # psql -d "$POSTGRES_DB" -h postgres -U "$POSTGRES_USER" <<- EOF
38+ # SELECT * FROM oc_preferences WHERE appid='cookbook';
39+ # EOF
1840 ;;
1941 sqlite)
2042 echo " Doing nothing as it was already restored during data restoration."
Original file line number Diff line number Diff line change @@ -274,10 +274,12 @@ drop_environment(){
274274 fi
275275 ;;
276276 pgsql)
277- local tables=$( echo " SELECT tablename FROM pg_tables WHERE schemaname = 'public';" | call_postgres | head -n -1 )
278- if [ -n " $tables " ]; then
279- echo " $tables " | sed ' s@.*@DROP TABLE \0;@' | call_postgres
280- fi
277+ call_postgres << - EOF
278+ DROP SCHEMA public CASCADE;
279+ CREATE SCHEMA public;
280+ GRANT ALL ON SCHEMA public TO $POSTGRES_USER ;
281+ GRANT ALL ON SCHEMA public TO public;
282+ EOF
281283 ;;
282284 esac
283285
@@ -337,6 +339,12 @@ restore_env_dump() {
337339 ;;
338340 pgsql)
339341 echo " Restoring Postgres database from dump"
342+ call_postgres << - EOF
343+ DROP SCHEMA public CASCADE;
344+ CREATE SCHEMA public;
345+ GRANT ALL ON SCHEMA public TO $POSTGRES_USER ;
346+ GRANT ALL ON SCHEMA public TO public;
347+ EOF
340348 cat " volumes/dumps/$ENV_DUMP_PATH /sql/dump.sql" | call_postgres
341349 ;;
342350 sqlite)
@@ -424,7 +432,7 @@ function call_mysql() {
424432
425433function call_postgres() {
426434 # docker-compose exec -T postgres psql -t nc_test tester
427- docker-compose exec -T postgres psql -U " $POSTGRES_USER " " $POSTGRES_DB "
435+ docker-compose exec -T postgres psql -U " $POSTGRES_USER " " $POSTGRES_DB " -v ' ON_ERROR_STOP=1 ' --quiet " $@ "
428436}
429437
430438# #### Parameters as extracted from the CLI
You can’t perform that action at this time.
0 commit comments