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!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Click below to sign up and get $100 of credit to try our products over 60 days!
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
You can submit this using
doctl
(make sure you’re using the latest version):We have another job type that will be landing in production soon as well — executed on failed deploys — so stay tuned for that.
@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.