Skip to content

Instantly share code, notes, and snippets.

@nrmancuso
Created October 24, 2021 22:19
Show Gist options
  • Save nrmancuso/c2a0f6c5febbf9c4dfb1bb2045c40cc4 to your computer and use it in GitHub Desktop.
Save nrmancuso/c2a0f6c5febbf9c4dfb1bb2045c40cc4 to your computer and use it in GitHub Desktop.

SETTING UP LOCAL DATABASE WITH CONTENT

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.

  1. 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

  1. cp to local postgresql dir: sudo cp <<CWD> <<../var/lib/postgresql>>

Example:

sudo cp db_backup_10_24_2021 ../../../../var/lib/postgresql
  1. Restart Postgresql: sudo service postgresql restart
  2. Change to postgres user: sudo -i -u postgres
  3. Log into database: psql
  4. drop current django_db: DROP DATABASE django_db (WARNING: THIS WILL CAUSE DATA LOSS FROM DROPPING THE DB)
  5. make new django_db: CREATE DATABASE django_db
  6. 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)

  1. Exit out of postgres user: exit
  2. From CIVAM/django_project/civam/migrations run: rm !(__init__.py) (Ignore error: 'cannot remove pycache: Is a directory warning')
  3. From CIVAM/django_project run to make new data show up on site: python3 manage.py makemigrations then run: python3 managy.py migrate
  4. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment