# Update prepreprod Database Contents

This document describes the process to import the database from one heroku environment to another (e.g. production to pre-prod).
The goal is then to remove all users, with the exception of superusers and some whitelisted ones, and also their custom content.

```bash
heroku pg:backups:restore my-dhf-prod::b313 --app my-dhf-preprod
```

Check latest backup on the _source_ (where the data comes from) environment, note the backup id

```bash
heroku pg:backups --app <source-app>

# example
# 21:56:52 $ heroku pg:backups --app my-dhf-prod
 # ›   Warning: heroku update available from 7.60.1 to 8.1.9.
# === Backups
# ID    Created at                 Status                               Size    Database
# ────  ─────────────────────────  ───────────────────────────────────  ──────  ────────
# a314  2023-08-31 01:02:23 +0000  Completed 2023-08-31 01:03:52 +0000  7.52MB  DATABASE

```

If desired, capture a new backup

```bash
heroku pg:backups:capture --app <source-app>
```

For redundancy's sake, create backup on _target_ app

```bash
heroku pg:backups:capture --app <target-app>
```

Restore the backup from the _source_ to the _target_ (where the data goes, and all the old data is _lost_) app, using the backup id noted before

```bash
heroku pg:backups:restore <source-app>::<backup-id> --app <target-app>

# example
#
# heroku pg:backups:restore my-dhf-prod::b313 --app my-dhf-preprod
```

Connect to target app and run a bash prompt

```bash
heroku run --app <target-app> /bin/bash
```

Go to server folder, run the python shell

```bash
cd server
python manage.py shell
```

Import the nuke_user script, run it

```python
from nuke_users import nuke_users
nuke_users()
```
