← Writing

Can You Roll Back Spring Boot After a PostgreSQL Schema Change?

Once PostgreSQL commits the schema change, reverting the Spring Boot app leaves the migrated schema in place. Before release, rehearse reads and writes against the migrated database using the exact artifact you would roll back to. Have the new app write a row and verify that the older app can read and update it. PostgreSQL 17 COMMIT

Two migrations, two outcomes

Two HTTP integration tests passed in a synthetic local lab on macOS arm64 with Java 21, Docker, Spring Boot 3.5.16, and PostgreSQL 17.12. Each scenario started with a fresh copy of an items table with a name column and committed one of these migrations.

-- Scenario 1
ALTER TABLE items RENAME COLUMN name TO display_name;

-- Scenario 2 (fresh copy of the starting schema)
ALTER TABLE items
  ADD COLUMN display_name text GENERATED ALWAYS AS (name) STORED;

The rename preserved stored values. The old app still used name in its SQL, so GET and PUT both returned HTTP 500. PostgreSQL 17 ALTER TABLE

With the generated column, old reads and writes returned HTTP 200. Both versions wrote to name, and PostgreSQL computed and stored display_name. After the new app wrote a row, the restarted old app could read and update it. PostgreSQL 17 generated columns

A direct rename caused old GET and PUT requests to return HTTP 500. Keeping name and adding a generated column let the old app read and update a row written by the new app.

Both branches start from the original schema. The generated-column branch follows the same row through a write by the new app and a read and update by the restarted old app.

What to verify before release

  1. Apply and commit the planned migration in a test database. Check which schema initialization settings or migration tools will run when the rollback artifact starts. Spring Boot 3.5 database initialization
  2. Have the new app write a row. Start the exact rollback artifact against the same migrated database.
  3. Read and update that row through the old API. Verify the expected HTTP responses and read the value back to confirm the update persisted.

The lab establishes local compatibility for these operations. Production lock and rewrite impact, large tables, backup restores, and zero downtime were outside the test scope.

I sell the rollback kit for US$15. It includes the full local lab, two HTTP integration tests, and an editable release checklist. View the rollback kit

Discussion

View on GitHub ↗