## Database Transfer

To move database from production to staging or staging to dev:

1. Copy DB
1. Update email addresses in `opportunities_types` and clear out sessions:

```
UPDATE `opportunities_types` SET `notification_always` = NULL WHERE 1; UPDATE `opportunities_types` SET `notification_always_bcc` = NULL WHERE 1; UPDATE `opportunities_types` SET `notification_outside_department_music` = NULL WHERE 1; UPDATE `opportunities_types` SET `notification_outside_department_music_bcc` = NULL WHERE 1; UPDATE `opportunities_types` SET `notification_outside_department_talent` = NULL WHERE 1; UPDATE `opportunities_types` SET `notification_outside_department_talent_bcc` = NULL WHERE 1;

TRUNCATE TABLE `sessions` 
```

1. update email addresses in `tribes` table
1. Make sure any DB changes that have been made during this sprint are RE-APPLIED.
1. If moving to `dev`, run `php artisan obfuscate:db`

## Production Build Checklist

* Build number: __________
* Last build date: ___________
* Build: [intranet/website/api]

1. Backup Database
1. Merge DEVELOP branch into MASTER
1. Create a tag at the merged commit
1. Run database updates if non-disruptive.
1. Open both Intranet machines in terminal. check `df -h` to make sure disk space is ok.
1. `php artisan down` intranet node 2. Wait for it to be taken out of load balancer rotation
1. intranet node 2: `rm -rf node_modules;git reset --hard; git pull; composer install; npm ci; npm run prod;`
1. intranet node 2: Compare `env-example` to `.env` and update as needed.
1. intranet node 2: run `php artisan config:cache`
1. Run destructive DB changes
1. intranet node 2: `php artisan up`. ...[wait]... intranet node 1: `php artisan down`
1. Check if intranet looks good. If so, do the same stuff as above on intranet node 1
1. If needed, update API
    1. AWS interface: `EC2 > Target groups > production api > health checks tab` - reduce `Interval` to `5`
    1. Open both API machines in terminal. check `df -h` to make sure disk space is ok.
    1. api node 2: `php artisan down` - Wait for it to be taken out of load balancer rotation
    1. Make sure website still working properly
    1. `git status`
    1. `git reset --hard`
    1. `git pull`
    1. `php artisan up` ...[wait]... api node 1: `php artisan down`
    1. Make sure website still working properly
        1. If doing a website build, update the website here and make sure it works properly with API. If not, revert website back and keep running on one API machine until we figure out issue.
    1. If everything looks good, do above steps on api node 1
    1. Check website to make sure it is accessing the API correctly.
    1. AWS interface: `EC2 > Target groups > production api > health checks tab` - increase `Interval` to `10`
1. If needed, update website
1. Contact Andy about build complete
1. Setup for next build:
    1. Create a folder in `db/db_updates`
    1. Create new milestone
    1. Close out old milestone if applicable.
    1. Delete old `audit_log_views` entries:

        ```
        DELETE FROM audit_log_views WHERE created_at < '2021-07-01 00:00:00';
        ```

        (update to 30 days ago)
1. Encrypt Backups
