Importing Database dumps
This guide will elaborate on how to import a database dump into the local development environment. The example commands will assume that you are using the dev-container.
Acquiring a database dump
Before importing, you must first have a dump file to load.
Downloading the example maps from the dedicated 'maps' repository
Before you begin, you must make sure you have git-lfs
installed.
To install it in a debian or debian derivative environment, use the following command:
sudo apt-get install git-lfs
Next, you need to clone the repository and fetch the lfs data:
git clone git@gitlab.tuwien.ac.at:permaplant/maps.git
git lfs fetch --all
Now you can download the database dump:
git lfs pull --include "deployed_dump.psql"
Wiping the local database
In the following parts, you will need the database IP/DNS Name and Port for the database that you are trying to load the dump onto.
In the dev-container, this should just be db
and 5432
. For more information on what to use in your environment,
consult the documentation
To correctly wipe the permaplant
database, you have two options:
- Using the
make wipe-database
command - Manually using the following commands:
psql -h db -p 5432 -U permaplant postgres -c 'DROP DATABASE permaplant'
psql -h db -p 5432 -U permaplant postgres -c 'CREATE DATABASE permaplant'
Loading the dump file
To load the database dump file, use the following command:
psql -h db -p 5432 -U permaplant permaplant < "<path to dump file>"
Using the helper script
The script located in tools/import_db_dumps.sh
can be used to wipe the database and import a dump. This is useful, if you need to repeat these steps often.
It has 3 Parameters: database IP
, database Port
, path to the dump file
. Here is an example of how to use the script from the root directory:
./tools/import_db_dumps.sh db 5432 'path/to/my/dump.sql'