Skip to content

Create staging database

Kuan Fan edited this page Sep 17, 2019 · 11 revisions

page owner: TFRS Developer

On Prod

Backup prod database

  • Login prod postgresql96 pod and run command "pg_dump tfrs | gzip > /postgresql-backup/SQLDump/prod/tfrs-[DateTime].gz"
  • Copy the above database dump to local drive "oc rsync [pod name]:[path to the dump file] [local drive]"

On Test

Create the secret for staging database on test

  • Create secret tfrs-postgresql-staging which contains same content as prod secret tfrs-postgresql

Create storage

  • Create postgresql96-staging-cns storage

Bring down the postgresql96 database

Create DC/postgresql-staging

  • Create DC/postgresql96-stagin, mount ostgresql96-staging-cns and bk-mem-tfrs-test-f2f7inx0x1ba
  • Use the secret tfrs-postgresql-staging for environment variable

Copy the prod SQL Dump file to staging

  • oc rsync [local drive] [pod name]:/postgresql-backup/SQLDump/prod

Verify Django migration table contents

  • Test either has same release deployed as prod, or one or a couple ahead.
  • If we don't run deployment on test, only duplicate prod database to test, there should be no migration happening.
  • Further verification may be needed.

Run following command to restore staging database from prod dump file

psql tfrs
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO public;
DROP SCHEMA tfrs_audit CASCADE;
CREATE SCHEMA tfrs_audit;
GRANT ALL ON SCHEMA tfrs_audit TO postgres;
GRANT ALL ON SCHEMA tfrs_audit TO public;
\q

run command gunzip -c /postgresql-backup/SQLDump/prod/tfrs-[DateTime].gz | psql tfrs

Update the selector of postgresql service to choose postgresql96-staging

Update the DATABASE_USER and DATABASE_PASSWORD in tfrs, celery and scan-handler DC Environment to use tfrs-postgresql-staging secret

Disable email notification in case emails are triggered