Running Sandboxed Tasks
How to safely test Rails schema changes or data migrations
Similarly to the Running Remote Tasks, you can run tasks in a sandboxed environment to safely test changes before deploying to production. Since direct access to production database dumps is restricted, this process provides a secure environment to validate Rails schema migrations or data migration Rake tasks using a snapshot of the production database.
Use Cases
You can use sandboxed tasks for:
- Rails database migrations - Validate schema changes before deployment
- Data migration Rake tasks - Test one-off scripts or data cleanup logic using a copy of the production database
Tasks run in sandboxed mode have access to a limited set of System Parameters, and access to external services is disabled. This is intended to prevent accidental changes to production data or services.
Note that any jobs enqueued during the execution of the task will not be run.
Prerequisites
Before running the script:
- Ensure your branch is up to date with the latest
main
- Push the commit you want to test to the remote
Usage
The script is located in the arc-api
repository at bin/run_sandboxed_task
. Typical execution time is between 10 and 15 minutes, depending on the complexity of the migration.
Testing Rails Migrations
To test Rails migrations, provide the full commit SHA:
bin/run_sandboxed_task run --commit-sha <commit-sha>
Example:
bin/run_sandboxed_task run --commit-sha f8a5a0942c2208c3ae7169f006fec15123456789
Testing Rake Tasks
To test a Rake task, specify both the commit SHA and the full Rake task name:
bin/run_sandboxed_task run --commit-sha <commit-sha> --rake-task <rake-task>
Example:
bin/run_sandboxed_task run --commit-sha f8a5a0942c2208c3ae7169f006fec15123456789 --rake-task one_off:cleanup_duplicated_patients
Execution Logs
The script streams logs in real time during execution. If you need to reconnect to an ongoing run (e.g., after exiting the command), use the execution ID displayed at the start of the script:
bin/run_sandboxed_task watch --sf-execution-arn <execution-id>
Run bin/run_sandboxed_task --help
to view all available command options.