Dev/QA/Similar: Either containerize and back to persistent volume, or use a managed DB service such as RDS or Cloud SQL and create a schema per environment. Include a deployment pipeline argument to reset to known state. CI pipeline can be tuned to handling dynamic environments in either case.
Stage/Prod: Use managed DB service such as RDS or Cloud SQL.
The time and cost to automate a DB upgrade with every edge case considered is huge. Rarely makes sense for small/medium business.