Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit a6c54dd

Browse files
authored
Merge pull request #58 from startupturbo/dmius-text-dump
dump as text + gz\bz2\sql file
2 parents 0dff1c6 + 85b7c45 commit a6c54dd

File tree

5 files changed

+77
-5
lines changed

5 files changed

+77
-5
lines changed

.circleci/test.dump.gz

130 Bytes
Binary file not shown.

.circleci/test.dump.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
create table t1 as
2+
select i as id, random() val
3+
from generate_series(1, 1000000) _(i);
4+
5+
alter table t1 add primary key (id);

nancy_run.sh

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,20 @@ function checkParams() {
387387
exit 1
388388
fi
389389

390-
[ ! -z ${DB_DUMP_PATH+x} ] && ! checkPath DB_DUMP_PATH \
391-
&& >&2 echo "ERROR: file $DB_DUMP_PATH given by db_dump_path not found" \
392-
&& exit 1
390+
if [ ! -z ${DB_DUMP_PATH+x} ]; then
391+
checkPath DB_DUMP_PATH
392+
if [ "$?" -ne "0" ]; then
393+
echo "$DB_DUMP_PATH" > $TMP_PATH/db_dump_tmp.sql
394+
DB_DUMP_PATH="$TMP_PATH/db_dump_tmp.sql"
395+
else
396+
[ "$DEBUG" -eq "1" ] && echo "DEBUG: Value given as db-dump-path will use as filename"
397+
fi
398+
DB_DUMP_FILENAME=$(basename $DB_DUMP_PATH)
399+
DB_DUMP_EXT=${DB_DUMP_FILENAME##*.}
400+
else
401+
echo "ERROR: file $DB_DUMP_PATH given by db_dump_path not found"
402+
exit 1
403+
fi
393404

394405
if [ -z ${PG_CONFIG+x} ]; then
395406
>&2 echo "WARNING: No DB config provided. Using default one."
@@ -775,9 +786,19 @@ function copyFile() {
775786
## Apply machine features
776787
# Dump
777788
sleep 2 # wait for postgres up&running
778-
DB_DUMP_FILENAME=$(basename $DB_DUMP_PATH)
789+
779790
echo "Restore database dump"
780-
docker_exec bash -c "bzcat $MACHINE_HOME/$DB_DUMP_FILENAME | psql -E --set ON_ERROR_STOP=on -U postgres test > /dev/null"
791+
case "$DB_DUMP_EXT" in
792+
sql)
793+
docker_exec bash -c "cat $MACHINE_HOME/$DB_DUMP_FILENAME | psql --set ON_ERROR_STOP=on -U postgres test"
794+
;;
795+
bz2)
796+
docker_exec bash -c "bzcat $MACHINE_HOME/$DB_DUMP_FILENAME | psql --set ON_ERROR_STOP=on -U postgres test"
797+
;;
798+
gz)
799+
docker_exec bash -c "zcat $MACHINE_HOME/$DB_DUMP_FILENAME | psql --set ON_ERROR_STOP=on -U postgres test"
800+
;;
801+
esac
781802
# After init database sql code apply
782803
echo "Apply sql code after db init"
783804
if ([ ! -z ${AFTER_DB_INIT_CODE+x} ] && [ "$AFTER_DB_INIT_CODE" != "" ])
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
thisDir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
4+
parentDir="$(dirname "$thisDir")"
5+
srcDir="$parentDir/.circleci"
6+
if [ ! -d "$srcDir/tmp" ]; then
7+
mkdir "$srcDir/tmp"
8+
fi
9+
nancyRun="$parentDir/nancy_run.sh"
10+
11+
output=$(
12+
$nancyRun --workload-custom-sql "file://$srcDir/custom.sql" \
13+
--db-dump-path "file://$srcDir/test.dump.gz" \
14+
--tmp-path $srcDir/tmp 2>&1
15+
)
16+
17+
if [[ $output =~ "Queries duration:" ]]; then
18+
echo -e "\e[36mOK\e[39m"
19+
else
20+
>&2 echo -e "\e[31mFAILED\e[39m"
21+
>&2 echo -e "Output: $output"
22+
exit 1
23+
fi
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
thisDir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
4+
parentDir="$(dirname "$thisDir")"
5+
srcDir="$parentDir/.circleci"
6+
if [ ! -d "$srcDir/tmp" ]; then
7+
mkdir "$srcDir/tmp"
8+
fi
9+
nancyRun="$parentDir/nancy_run.sh"
10+
11+
output=$(
12+
$nancyRun --workload-custom-sql "file://$srcDir/custom.sql" \
13+
--db-dump-path "file://$srcDir/test.dump.sql" \
14+
--tmp-path $srcDir/tmp 2>&1
15+
)
16+
17+
if [[ $output =~ "Queries duration:" ]]; then
18+
echo -e "\e[36mOK\e[39m"
19+
else
20+
>&2 echo -e "\e[31mFAILED\e[39m"
21+
>&2 echo -e "Output: $output"
22+
exit 1
23+
fi

0 commit comments

Comments
 (0)