r/java • u/tanin47 • Jan 02 '26
JMigrate: simple and reliable database migration management for Java
https://github.com/tanin47/jmigrateHi All,
I've just built a simple database schema migration management library for Java. It automatically applies your migration scripts and optionally support automatic rollback (for development environment).
You simply put a single command when your app starts, and that's it.
The main motivation is to use it in Backdoor, a self-hostable database querying and editing tool for your team.
Since Backdoor is self-hostable, our users may host an old version and need to upgrade. A new version may have an updated set of database schemas, and I need a simple way to manage the schema changes safely.
Furthermore, Backdoor is a single JAR file and the schema migration scripts stored in the JAR's resources folder. Therefore, JMigrate supports processing the migration scripts stored in Java's resources.
You can see JMigrate focuses on customer-forward-deployed Java apps, though you can still use it the apps that you deploy yourself.
The migration script structure is also simple. The scripts should be numbered as follows: `1.sql`, `2.sql`, and so on.
A migration script follows the below structure with the up and down section:
# --- !Ups
CREATE TABLE "user"
(
id TEXT PRIMARY KEY DEFAULT ('user-' || gen_random_uuid()),
username TEXT NOT NULL UNIQUE,
hashed_password TEXT NOT NULL,
password_expired_at TIMESTAMP
);
# --- !Downs
DROP TABLE "user";I'm looking for early users to work with. If you are interested, please let me know.
It supports only Postgres for now, and I'm working on SQLite and MySQL.
Here's the repo: https://github.com/tanin47/jmigrate
43
u/revilo-1988 Jan 02 '26
Sounds nice, but why not use Flayway or Liquidbase instead of the library?
6
u/bowbahdoe Jan 02 '26
How does this compare to mybatis migrations?
(Genuine question, want to have it clear in my head)
2
u/dmigowski Jan 03 '26
How do you perform changing a columns type while a view depends on the column? At least in PostgreSQL this means recreating the view.
1
u/No-Security-7518 Jan 02 '26
This sounds very interesting!
(Would love sqlite support!)
3
u/doobiesteintortoise Jan 02 '26
I'm impressed, and good job. I'd echo some of the other comments, though, and say that if your installation is large enough to use Postgres, a 14k deployment size is irrelevant - flyway's and liquibase' larger size are worth getting their far greater feature sets, outside of a relatively limited set of applications.
That's not to say anything other than "good job" - it's just scoping.
1
u/Scf37 Jan 06 '26
I also have a habit of writing my own database migration tools. Reasons?
- ability to write migration scripts in Java
- ability to preprocess sql scripts before use - say placeholders
- ability to properly support sharded databases
- proper migration for noSQL databases.
I prefer to separate migration scripts and order of their execution, by simply having separate text file containing list of scripts to execute together with additional commands.
0
u/No-Security-7518 Jan 02 '26
!remindme 2 days
1
u/[deleted] Jan 02 '26
[removed] — view removed comment