Note: This is for setting up a local Postgresql database on the local running CIVAM site Primarily this will be used to ensure dev work is inline with what is running on the current CIVAM site.
- Pull DB file from site:
scp -i civam-new.pem [email protected]:<<SRC>> <<DEST>>
Example:
scp -i civam-new.pem [email protected]:~/db-backups/DBFullBackups/db_backup_10_24_2021 .
This will pull the file "db_backup_10_24_2021" into my current working directory
- cp to local postgresql dir:
sudo cp <<CWD> <<../var/lib/postgresql>>
Example:
sudo cp db_backup_10_24_2021 ../../../../var/lib/postgresql
- Restart Postgresql:
sudo service postgresql restart
- Change to postgres user:
sudo -i -u postgres
- Log into database:
psql
- drop current django_db:
DROP DATABASE django_db
(WARNING: THIS WILL CAUSE DATA LOSS FROM DROPPING THE DB) - make new django_db:
CREATE DATABASE django_db
- Reload db with:
psql <<Db_name>> < <<db_restore_script_file>>
Example:
psql django_db < db_backup_10_24_2021
This will open up psql and recreate all data (tables, indexes, PK/FK,etc in the DB)
- Exit out of postgres user:
exit
- From
CIVAM/django_project/civam/migrations
run:rm !(__init__.py)
(Ignore error: 'cannot remove pycache: Is a directory warning') - From
CIVAM/django_project
run to make new data show up on site:python3 manage.py makemigrations
then run:python3 managy.py migrate
- Run local instructions to set up site and check if new items are there:
sudo service postgresql start
python3 manage.py runserver
cd ../angular-frontend
ng build
ng serve