Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB-drop-and-reset-write-down #2710

Merged
merged 5 commits into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/Technical-Documentation/CloudFoundry-DB-Connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,36 @@ From [this github](https://github.com/cloud-gov/cf-service-connect) which has so

> `cf connect-to-service tdp-backend-<name> tdp-db-dev`


# How to DROP existing DB and Recreate a fresh DB

### Connecting to DB service
First step is to connect to the instance DB (see above).

#### Optional: DB backup
Before deleting the DB and recreating a fresh DB, you might want to create a backup from the existing data in case you decide to revert the DB changes back.

For creating a DB backup, please see: `/tdpservice/scheduling/BACKUP_README.md`

#### Drop and Recreate

e.g:
>`cf connect-to-service tdp-backend-qasp tdp-db-dev`

After connection to the DB is made (the step above will make a psql connection), then the following Postgres commands have to run:

1. List the DBs: `\l`
2. Potgres does not _DROP_ a database when you are connected to the same DB. As such, you will have to connect to a different DB using command:
>`\c {a_database}`

A good candiadate is:
>`\c postgres`
3. find the associated DB name with instance. E.g: `tdp_db_dev_qasp`
4. use the following command to delete the DB:
>`DROP DATABASE {DB_NAME}`
5. use the following command to create the DB:
>`CREATE DATABASE {DB_NAME}`

After the DB is created, since the database is cinoketely empty, we will need to redeploy the app again to create tables (or alternatively we can restore a good backup), and then we should run populate stt command to add STT data to the empty DB

>`./manage.py populatestts`
Loading