Skip to content

Commit

Permalink
Added note about preventing unexpected DB schema diffs
Browse files Browse the repository at this point in the history
This has become a bit of an annoying issue for the Whitehall team over time, and has sometimes led to changes to the schema.rb file not being committed when they should have been.
  • Loading branch information
ryanb-gds committed Aug 16, 2024
1 parent ff646d9 commit 06a8edf
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,19 @@ This may resolve by removing orphan containers which were created in a previous
```
docker-compose down -v --rmi all --remove-orphans
```


## Rails database schema changed unexpectedly when running `rake db:migrate`

It is common to find that running `rake db:migrate` results in unexpected changes to the `schema.rb` file. This is caused by slight differences between databases running in GOV.UK Docker and the production databases on AWS.

Unfortunately, to resolve the issue, the only solution is to drop the database in GOV.UK docker and create a new one. This is annoying if you've built up a useful corpus of development data, so you might want to take a backup containing just the data. For MySQL you can do this using the [--no-create-info](https://dev.mysql.com/doc/refman/8.4/en/mysqldump-definition-data-dumps.html) option with MySQL dump, for Postgres you can use the `--data-only` option for PostgreSQL dump.

Once you have taken a backup, you can remove and re-create your local database using the following commands:

```bash
rake db:drop
rake db:create
rake db:schema:load
rake db:schema:migrate // optional, but if you are adding a new migration this will now update the schema without creating a horrible diff
```

0 comments on commit 06a8edf

Please sign in to comment.