Skip to content

ywnaing/simple-db-migrator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple DB Migrator

A lightweight database migration tool built with Java 21, picocli, and SLF4J.

Features

  • Java 21 Modernization: Uses Records, Sealed Interfaces, and modern APIs like HexFormat.
  • Migration Locking: Prevents concurrent migrations from multiple instances using a database-level lock.
  • Robust CLI: Powered by picocli for easy parameter handling and help.
  • Logging: SLF4J with Logback for production-grade logging.
  • Checksum Validation: Ensures migration files haven't changed after being applied.

Prerequisites

  • Java 21 or higher.
  • MySQL Database.

Usage

Run the migrator as an executable JAR with a subcommand:

1. Migrate (Apply pending)

java -jar simple-db-migrator.jar migrate -u <jdbc_url> -user <username> -p -m <migrations_path>

2. Rollback (Undo applied)

java -jar simple-db-migrator.jar rollback -u <jdbc_url> -user <username> -p -m <migrations_path> --steps 1

Parameters

  • -u, --url: The JDBC connection URL (e.g., jdbc:mysql://localhost:3306/mydb).
  • -user, --username: Database username.
  • -p, --password: Database password (interactive prompt).
  • -m, --migrations: Path to the migrations directory (default: src/main/resources/migrations).
  • -s, --steps: (Rollback only) Number of migrations to undo (default: 1).

Migration File Naming

  • Action: V<Version>__<Description>.sql (Example: V1__create_users.sql)
  • Rollback: V<Version>__<Description>.rollback.sql (Example: V1__create_users.rollback.sql)

Verification

Run ./gradlew test to execute the full testing suite (includes H2 integration tests).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages