Register trainee teachers - Testing Data Migrations
Data migrations can/should be tested using production data. To download a copy from production:
- Request production access in #twd_regsiter_devs noting why you need it.
- Log in:
cf login -a https://api.london.cloud.service.gov.uk --sso
- Set space to:
bat-prod
- Make sure conduit is installed:
cf install-plugin conduit
- Download the db:
cf conduit register-postgres-13-production -- pg_dump -f register-postgres-production.sql --no-acl --no-owner --clean
- Then import:
DISABLE_DATABASE_ENVIRONMENT_CHECK=1 rake db:{drop,create} && psql register_trainee_teacher_data_development < register-postgres-production.sql
- This will have overwritten any migrations you have created for the feature you are working on, if so run
bundle exec rails db:migrate
- Finally, ensure the psql dump is deleted once testing is complete.
specs
Where a migration has logic beyond looping a list and updating records, it is best practice to include a service within the migration and write a spec for the service. See for an example: