By ReWild
Laravel, as many other PHP frameworks, has command line tools to migrate database schema up and down.
It is not clear how to use those schema migration command line tools with the DigitalOcean App Platform. For instance:
If horizontal scaling is used, it is not clear which container should run the migration command, and how to make it so that the migration is executed once only
If the service is rolled back, how to make it also automatically roll back the database schema? Or at least to restore the database to the previous state at the point in time before the update happened?
Any additional comments / examples on database schema migration and rollback with the App Platform?
Thanks!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
@ReWild 👋
This is a great question. We’re working to make operations like database migrations much easier to do on the App Platform, and plan to rollout support for pre-deploy and post-deploy jobs very soon for exactly this use-case.
In the meantime, you have a couple options:
Console access in the UI. This has the downside of not running automatically with every deploy.We’ll follow-up on this question when we ship pre/post deploy jobs, very soon, so stay tuned.
We recently introduced the jobs component type that can be used for this, where you can specify the type such that the job will run pre-deploy or post-deploy.
This feature is currently only available via API/CLI (doctl), but not yet the UI.
We have an example of this here: https://github.com/digitalocean/sample-golang-notes/blob/migrate-job/.do/app.yaml
name: sample-golang-notes
services:
- name: web
github:
repo: digitalocean/sample-golang-notes
branch: migrate-job
envs:
- key: DATABASE_URL
value: ${db.DATABASE_URL}
jobs:
- name: migrate
kind: PRE_DEPLOY
github:
repo: digitalocean/sample-golang-notes
branch: migrate-job
build_command: mkdir -p bin && cd cmd/migrate && go build -o ../../bin/migrate
run_command: bin/migrate
envs:
- key: DATABASE_URL
value: ${db.DATABASE_URL}
databases:
- name: db
engine: PG
version: "12"
You can submit this using doctl (make sure you’re using the latest version):
doctl apps create --spec .do/app.yaml
We have another job type that will be landing in production soon as well — executed on failed deploys — so stay tuned for that.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.