Stirling-PDF
Stirling-PDF copied to clipboard
feat(db): add database version tracking and automated upgrades
Description of Changes
- Introduce database version tracking entity and repository to persist the last applied schema/data version.
- Add a migration framework with a
MigrationStepinterface and implement an H2-specific, data-only migration from 0.33.1 to 0.34.0 that imports user-facing data from the latest backup without altering the new schema. - Refactor
DatabaseServiceto implement a newDatabaseServiceInterface; expose utility methods for linked tables, identity handling, and backup imports; and addmigrateDatabase()orchestration. - Call
databaseService.migrateDatabase()during initial security setup to run migrations early on startup. - Swap controller dependencies from
DatabaseServicetoDatabaseServiceInterface; update signatures to surfaceSQLException/UnsupportedProviderExceptionwhere appropriate. - Simplify
H2SQLCondition: enable H2-specific beans when no custom datasource is configured (instead of checkingsystem.datasource.type). - Minor robustness tweak: use constant-first
equalsfor team name comparison in internal API user reassignment.
Why the change was made
- Provide a safe, idempotent path to carry user data from older H2 backups into the new schema without DDL changes, improving upgrade reliability.
- Persist an application-level database version to avoid re-running data migrations and to make future steps explicit.
- Decouple controllers from a concrete service and centralize migration/backup utilities to make the codebase easier to test and maintain.
- Ensure migrations run automatically on boot for H2 setups, reducing operational friction.
Checklist
General
- [x] I have read the Contribution Guidelines
- [x] I have read the Stirling-PDF Developer Guide (if applicable)
- [ ] I have read the How to add new languages to Stirling-PDF (if applicable)
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings
Documentation
- [ ] I have updated relevant docs on Stirling-PDF's doc repo (if functionality has heavily changed)
- [ ] I have read the section Add New Translation Tags (for new translation tags only)
UI Changes (if applicable)
- [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR)
Testing (if applicable)
- [ ] I have tested my changes locally. Refer to the Testing Guide for more details.
For database tracking and migration might be good to use spring flyway
For database tracking and migration might be good to use spring flyway
I basically went the same route, just without the additional library. Because with Flyway, a migration*.sql file would also have to be applied. Now, only four files have been added.