Add Liquibase migrations to proj-courses - #316
Draft
pconrad wants to merge 3 commits into
Draft
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Liquibase-managed database migrations to proj-courses, replacing Hibernate's
spring.jpa.hibernate.ddl-auto=update, per #315.docs/liquibase.md).org.liquibase:liquibase-coredependency (idiomatic Spring Boot style, matching proj-scaffold rather than the misusedliquibase-maven-plugindependency used by the other three repos).src/main/resources/db/migration/changelog-master.json+ one changeset per existing JPA entity underdb/migration/changes/, each withpreConditions/MARK_RANguards (matching proj-scaffold's convention, the most disciplined of the four surveyed repos).includes the changelog bundled inside thelib-jobsshared library jar to create theJOBStable (mirroring proj-dining's approach, since courses recently migrated tolib-jobsin Migrate jobs system to lib-jobs v0.1.6 (shared library) #314), rather than re-implementing that table locally.spring.jpa.hibernate.ddl-auto=noneso schema is exclusively Liquibase-managed from here on.V4__Add_admin_to_users.sql) that proj-courses shared with proj-happycows/proj-dining — it lived outsidedb/migration/changes/so Liquibase'sincludeAllnever picked it up.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.mainand it also passes cleanly.mvn -Plocalhoststartup on a freshtarget/db-development.mv.dbcreates all tables correctly via Liquibase (H2 console) before merging.liquibase-core+preConditionsconventions, and proj-dining'slib-jobschangelogincludeapproach) before the per-repo alignment issues indocs/liquibase.mdare opened.🤖 Generated with Claude Code