Skip to content

Add Liquibase migrations to proj-courses - #316

Draft
pconrad wants to merge 3 commits into
mainfrom
pc/issue-315-liquibase
Draft

Add Liquibase migrations to proj-courses#316
pconrad wants to merge 3 commits into
mainfrom
pc/issue-315-liquibase

Conversation

@pconrad

@pconrad pconrad commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds Liquibase-managed database migrations to proj-courses, replacing Hibernate's spring.jpa.hibernate.ddl-auto=update, per #315.

  • Surveyed the Liquibase setups in proj-frontiers, proj-happycows, proj-dining, and proj-scaffold to design a consistent setup here (full findings and a table of where the four repos agree/differ is in docs/liquibase.md).
  • Added org.liquibase:liquibase-core dependency (idiomatic Spring Boot style, matching proj-scaffold rather than the misused liquibase-maven-plugin dependency used by the other three repos).
  • Added src/main/resources/db/migration/changelog-master.json + one changeset per existing JPA entity under db/migration/changes/, each with preConditions/MARK_RAN guards (matching proj-scaffold's convention, the most disciplined of the four surveyed repos).
  • The master changelog also includes the changelog bundled inside the lib-jobs shared library jar to create the JOBS table (mirroring proj-dining's approach, since courses recently migrated to lib-jobs in Migrate jobs system to lib-jobs v0.1.6 (shared library) #314), rather than re-implementing that table locally.
  • Set spring.jpa.hibernate.ddl-auto=none so schema is exclusively Liquibase-managed from here on.
  • Removed a dead, inert Flyway-style leftover file (V4__Add_admin_to_users.sql) that proj-courses shared with proj-happycows/proj-dining — it lived outside db/migration/changes/ so Liquibase's includeAll never picked it up.
  • Added docs/liquibase.md: a programmer-facing doc explaining this repo's Liquibase setup, plus an "Alignment across repos" section with a comparison table and copy/paste-ready issue text for each of the five repos (courses, dining, frontiers, happycows, scaffold) to bring their setups into closer alignment.

Test plan

  • mvn test — full suite passes (416 tests, 0 failures/errors) with Liquibase managing schema creation against the default auto-configured embedded H2 database.
  • Verified this is not masking a pre-existing failure: ran the same full suite against unmodified main and it also passes cleanly.
  • Manually verify mvn -Plocalhost startup on a fresh target/db-development.mv.db creates all tables correctly via Liquibase (H2 console) before merging.
  • Reviewer: confirm the recommended alignment approach (adopting proj-scaffold's liquibase-core + preConditions conventions, and proj-dining's lib-jobs changelog include approach) before the per-repo alignment issues in docs/liquibase.md are opened.

🤖 Generated with Claude Code

pconrad and others added 3 commits July 13, 2026 14:54
Introduces org.liquibase:liquibase-core with a JSON changelog under
src/main/resources/db/migration, covering all 8 existing JPA entities plus an
include of the lib-jobs library's own changelog for the JOBS table (mirroring
proj-dining's approach). Sets spring.jpa.hibernate.ddl-auto=none so schema
changes are exclusively Liquibase-managed going forward.

Setup follows the conventions surveyed across proj-frontiers, proj-happycows,
proj-dining, and proj-scaffold (see docs/liquibase.md), adopting
proj-scaffold's liquibase-core dependency style and universal preConditions
guards. Also removes a dead, unreferenced Flyway-style leftover file
(V4__Add_admin_to_users.sql) that proj-courses shared with happycows/dining.

Addresses #315.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds .github/workflows/18-validate-db-schema.yml, pinned to
ucsb-cs156/workflows@main, matching the pattern already present in
proj-frontiers/proj-happycows/proj-scaffold. It boots the app with
ddl-auto=validate so Hibernate's entity mappings are checked against the
Liquibase-created schema on every PR, catching drift between entities and
changesets that the ddl-auto=none unit test suite can't.

Running this locally surfaced a real bug it was meant to catch: the
005-create-ucsbapiquarter-table changeset named three columns pass1_begin/
pass2_begin/pass3_begin, but Hibernate's naming strategy only inserts an
underscore at a lowercase-to-uppercase boundary, not a digit-to-uppercase one,
so pass1Begin etc. actually map to pass1begin/pass2begin/pass3begin. Fixed.

Also updates docs/liquibase.md's alignment analysis: corrects which branch of
ucsb-cs156/workflows each sibling repo's schema-validation workflow is pinned
to (happycows was already on @main, not @Division7-patch-1; scaffold is on
@Division7-patch-1, not @main, as previously stated), and updates the
per-repo alignment issue text and recommendations accordingly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The first production deploy of this Liquibase setup failed with "relation
'jobs' already exists". Root cause: production's JOBS table (like all its
other tables) pre-dates Liquibase, having been created by the old
ddl-auto=update. This repo's own 8 changesets all have preConditions/MARK_RAN
guards, so they correctly no-op'd against the pre-existing schema. The JOBS
table's createTable changeset, bundled inside the lib-jobs jar and pulled in
via `include`, has no such guard, so it unconditionally failed.

Tried shadowing the library's changelog file with a locally-guarded copy at
the same classpath-relative path, but Liquibase 4.29.2 explicitly detects and
rejects duplicate resource paths on the classpath rather than silently
picking one.

Fix: drop the `include` of lib-jobs' bundled changelog and add
009-create-jobs-table.json, a locally-owned changeset with the same
preConditions/MARK_RAN guard as every other changeset here (matching how
proj-scaffold already handles this, it turns out for the same reason).
Verified by simulating a database with pre-existing users/jobs tables
(mimicking production's pre-Liquibase schema) and confirming clean startup,
and by confirming a fresh database still gets a fully working JOBS table.

Also updates docs/liquibase.md: adds a full incident writeup, corrects the
lib-jobs alignment recommendation (previously suggested proj-scaffold adopt
the `include` approach used by proj-dining/proj-courses — that was backwards
and is withdrawn), flags proj-dining as being at risk of the same failure,
and adds a suggested issue for ucsb-cs156/lib-jobs to add the missing guard
upstream.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant