Managing Hibernate schema migrations during Scalingo rolling updates
0 reputation · 23 May 2026, 18:58 UTC
0 reputation · 23 May 2026, 18:58 UTC
Scalingo implements zero-downtime deployments through rolling updates, where new containers are spun up and health-checked before the previous version is terminated. This mechanism ensures continuous traffic flow via the platform's load balancer.
When deploying Java applications using Hibernate ORM, there is a potential conflict between the rolling update process and automatic schema updates (such as hbm2ddl.auto). Because two different versions of the application may connect to the same database simultaneously during the transition, a schema change initiated by the new version could render the active old version incompatible.
What is the recommended strategy for handling database migrations on Scalingo to prevent errors in the legacy containers during a rolling deploy? Does the platform provide a mechanism to sequence schema updates independently of the application container lifecycle?
30275 reputation · 24 May 2026, 06:24 UTC
To prevent errors in legacy containers during a rolling update, you must decouple schema migrations from the application startup process and ensure all database changes are backward-compatible. Relying on hibernate.hbm2ddl.auto=update is not recommended for production environments on Scalingo, as it lacks versioning and can cause race conditions or incompatible schema states when multiple versions of the application are active.
Replace automatic Hibernate updates with a dedicated migration tool such as Flyway or Liquibase. These tools maintain a schema history table to track which migrations have been applied, ensuring consistency across all containers.
Because Scalingo's rolling updates keep the old version running until the new version passes health checks, the database must support both versions simultaneously. Follow these rules for schema changes:
Scalingo does not provide a built-in "pre-deploy" hook for database migrations. To sequence updates independently of the application lifecycle, execute your migrations using a one-off container before triggering the rolling update.
Example workflow:
scalingo run "java -jar app.jar --migrate-only" (assuming your app has a migration-only mode).To verify the migration before the rolling update proceeds, check the migration history table:
SELECT * FROM flyway_schema_history ORDER BY installed_rank DESC LIMIT 1;
If the latest version matches your current release, it is safe to proceed with the rollout. If you encounter SQLGrammarException or ColumnNotFoundException in the logs of legacy containers during the rollout, it indicates a breaking change was introduced without backward compatibility.
Diagnostic Detail Needed: Are you currently using a custom entrypoint script or a CI/CD pipeline (e.g., GitHub Actions, GitLab CI) to trigger your Scalingo deploys? This determines whether the one-off migration can be fully automated.
Use comments to ask for clarification. Post a solution as an answer.
3,300 reputation · 24 May 2026, 03:58 UTC
When using Flyway (or Liquibase) for versioned migrations on Scalingo, set hibernate.hbm2ddl.auto=validate (or none) in the production profile so Hibernate never attempts to alter the schema. This guarantees that only the migration tool changes the database, eliminating the risk of concurrent update calls during a rolling update. Verify the setting by checking the application’s startup log for the line HHH000400: using dialect: … and confirming no schema update messages appear.