Bash script to install test environment to the local machine:
Prerequisites:
- Running pgdb container
OLD Prerequisites:
- You shouldn’t have postgres_spec database
- You should have in the path: dev/powr/db/temp/ this file
powr_test.dump(download link) OR the bash script will download it for you.
Ways to make it
The most general solution
- Create a bash file in the folder ~/dev/powr/db/temp/powr_test_installation.sh
- Copy-paste the code below inside the powr_test_installation.sh
- In the terminal run:
bash ~/dev/powr/db/temp/powr_test_installation.sh
Manual solution
- You can save the bash script file in the same folder as powr_test.dump and run whenever you drop your containers or lost your test env database
- You can just save the code or make it as an alias in the ZSHRC
- Or just save this message and copy paste every time
The bash code
DB_DOCKER_ID=$(docker ps -f name="pgdb" --format="{{.ID}}")
# powr_test.dump folder
POWR_TEST_DUMP=~/dev/powr/db/temp/powr_test.dump
if [[ -f "$POWR_TEST_DUMP" ]]; then
echo "TEST_DUMP file exists! Good to go! (* ^ ω ^)"
else
echo "Didn't find POWR_TEST.dump on folder $POWR_TEST_DUMP"
echo "Downloading to that the $POWR_TEST_DUMP directory!"
wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1XNnMsvW1isoxkEssFxEIDB7cJa__TwKr' -O $POWR_TEST_DUMP
fi
echo "Copying to the docker ~tmp/ as backup.dump"
docker cp ~/dev/powr/db/temp/powr_test.dump $DB_DOCKER_ID:/tmp/backup.dump
echo "Creating database postgres_spec"
docker exec $DB_DOCKER_ID psql -U postgres -c 'create database postgres_spec;'
echo "Fill postgres_spec with dump"
docker exec $DB_DOCKER_ID /bin/bash -c 'psql -U postgres postgres_spec < tmp/backup.dump'