Feature Request: JBang-Based Database Migration Tool with DDL Generation and Rollback Support #2641
Unanswered
anandjaisy
asked this question in
Ideas
Replies: 1 comment
|
Use hibernate tools jar ? It has those features ? |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
Most Java projects using frameworks such as Spring Boot, Micronaut, or Quarkus require a database migration solution such as Flyway or Liquibase.
While these tools are powerful and widely adopted, one pain point is that database migrations are typically tied to the application's build system. Developers often need to use Maven or Gradle to generate, configure, or execute migrations.
I would like to propose a lightweight, standalone database migration approach using JBang.
The idea is to provide a project-level CLI that can:
This would allow database migrations to be managed independently of whether the application uses Maven, Gradle, Spring Boot, Micronaut, or Quarkus.
Example Entity
For example, given the following JPA entity:
The tool could use the entity metadata and JPA annotations to help generate the corresponding DDL migration.
For example:
Proposed Workflow
The migration process could consist of three main steps:
jbang add script initial_migration
This command could:
For example:
jbang update database
This command would:
For example:
jbang update database
Database successfully updated to V005
jbang undo database
This command would:
Example:
jbang undo databaseRolling back: V005__add_shift_tableDatabase successfully rolled back to V004
Version-Based Migration
It would also be useful to support moving the database to a specific version.
For example:
jbang update database 10The tool would migrate forward until version 10 is reached.
Similarly:
jbang undo database 7The tool would execute rollback migrations until the database reaches version 7.
This would allow developers to move both forward and backward between migration versions:
Suggested Migration History Table
The tool could maintain its own migration history table, for example:
This would allow the CLI to determine:
Potential Commands
The initial CLI could support something similar to:
Create a new migration
jbang add script <migration_name>Generate DDL from entities
jbang generate ddlApply all pending migrations
jbang update databaseApply migrations up to a specific version
jbang update database <version>Roll back the latest migration
jbang undo databaseRoll back to a specific version
jbang undo database <version>Show current migration status
jbang database statusWhy JBang?
Using JBang could provide a lightweight and framework-independent experience.
The migration tool could be executed consistently across projects without requiring developers to interact directly with:
For example, the same migration workflow could potentially be used with:
The JBang CLI could act as a standalone developer tool while still allowing applications to use the generated migration scripts during deployment.
Important Considerations
One important requirement would be safe and explicit rollback support.
Automatic generation of a rollback script is not always possible. For example, while adding a column can usually be reversed by dropping the column, a data migration may not have a safe automatic rollback.
For this reason, it may be better to support explicit migration pairs:
This would make rollback behavior predictable and avoid potentially unsafe automatic database changes.
Expected Benefits
I believe this could be particularly useful for teams working across multiple Java frameworks while wanting a consistent and standalone approach to database schema migrations.
All reactions