Stirling-PDF icon indicating copy to clipboard operation
Stirling-PDF copied to clipboard

feat(db): add database version tracking and automated upgrades

Open Ludy87 opened this issue 3 months ago • 2 comments

Description of Changes

  • Introduce database version tracking entity and repository to persist the last applied schema/data version.
  • Add a migration framework with a MigrationStep interface 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 DatabaseService to implement a new DatabaseServiceInterface; expose utility methods for linked tables, identity handling, and backup imports; and add migrateDatabase() orchestration.
  • Call databaseService.migrateDatabase() during initial security setup to run migrations early on startup.
  • Swap controller dependencies from DatabaseService to DatabaseServiceInterface; update signatures to surface SQLException/UnsupportedProviderException where appropriate.
  • Simplify H2SQLCondition: enable H2-specific beans when no custom datasource is configured (instead of checking system.datasource.type).
  • Minor robustness tweak: use constant-first equals for 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

Documentation

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.

Ludy87 avatar Sep 09 '25 05:09 Ludy87

For database tracking and migration might be good to use spring flyway

Frooodle avatar Sep 09 '25 21:09 Frooodle

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.

Ludy87 avatar Sep 10 '25 05:09 Ludy87