Commit 0597b88f authored by Lucas Fernandes de Oliveira's avatar Lucas Fernandes de Oliveira

Merge branch 'issue/9' into 'master'

Issue #9: Add load compacted data

See merge request c3sl/psql-manager!10
parents b1459867 59b37c15
Pipeline #20958 passed with stage
in 1 minute and 1 second
......@@ -20,7 +20,7 @@ run_test:
stage: test
script:
- apt-get update -q -y
- apt-get install wget gnupg -y
- apt-get install bzip2 wget gnupg -y
- echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" > /etc/apt/sources.list.d/pgdg.list
- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
- apt-get update -q -y
......
CREATE TABLE workercompact(
id SERIAL
, login TEXT
, password TEXT
);
CREATE TABLE taskcompact(
workerId INTEGER
, description TEXT
, identifier SERIAL
);
......@@ -10,18 +10,25 @@ fixtureDB() {
workspace="$ws/fixture"
cleanDB
# Get load files, and sort it
tables=$(ls $workspace | sort | cut -d'.' -f1)
# Create temporary workspace (utility function)
tmpWS=$(createTmpWorkspace)
# Create transactions files
echo "BEGIN;" > "$tmpWS/trans.sql"
i=0
tables=$(ls -1 $workspace | grep ".bz2" | rev | cut -f4- -d\. | rev)
for t in $tables; do
mkfifo $tmpWS/$t.csv
tar xjOf $workspace/$t.csv.tar.bz2 > $tmpWS/$t.csv &
cpyComand $t $tmpWS/$t.csv >> "$tmpWS/trans.sql"
done
tables=$(ls -1 $workspace | grep -v ".bz2" | rev | cut -f2- -d\. | rev)
for t in $tables; do
cpyComand $t $workspace/$t.csv >> "$tmpWS/trans.sql"
done
echo "COMMIT;" >> "$tmpWS/trans.sql"
# Performs schema creation. As is in a transaction if fails it will
......
......@@ -6,18 +6,23 @@ loadDB() {
ws=${1:-"./data"}
workspace="$ws/load"
# Get load files, and sort it
tables=$(ls $workspace | sort | cut -d'.' -f1)
# Create temporary workspace (utility function)
tmpWS=$(createTmpWorkspace)
# Create transactions files
echo "BEGIN;" > "$tmpWS/trans.sql"
i=0
tables=$(ls -1 $workspace | grep ".bz2" | rev | cut -f4- -d\. | rev)
for t in $tables; do
cpyComand $t $workspace/$t.csv >> "$tmpWS/trans.sql"
mkfifo $tmpWs/$t.csv
tar xjOf $workspace/$t.csv.tar.bz2 > $tmpWs/$t.csv &
cpyComand $t $tmpWs/$t.csv >> "$tmpWS/trans.sql"
done
tables=$(ls -1 $workspace | grep -v ".bz2" | rev | cut -f2- -d\. | rev)
for t in $tables; do
cpyComand $t $workspace/$t.csv >> "$tmpWS/trans.sql"
done
echo "COMMIT;" >> "$tmpWS/trans.sql"
# Performs schema creation. As is in a transaction if fails it will
......
......@@ -85,3 +85,4 @@ updateSequences() {
rm -fr $tmpWs
return $error
}
......@@ -57,6 +57,26 @@ else
echo -e "\tFail"
fi
echo "Should insert a tuple, with the right sequence, on compactedfile"
psql -h ${POSTGRES_HOST}\
-d ${POSTGRES_DB}\
-U ${POSTGRES_USER}\
-c "INSERT INTO workercompact(login, password) VALUES('worker4', 'pass4')"\
> /dev/null
value=$(psql -h ${POSTGRES_HOST}\
-d ${POSTGRES_DB}\
-U ${POSTGRES_USER}\
-c "SELECT MAX(id) FROM workercompact" |\
head -n3 | tail -n1)
if [[ $value -eq 4 ]]; then
echo -e "\tSucess"
else
error=$(($error +1))
echo -e "\tFail"
fi
echo "Should create dummie data in the database"
./manager.sh fixture &> /dev/null
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment