https://github.com/ebean-orm/ebean-migration
DB Migration runner (similar to Flyway) which can be used standalone or with Ebean (run migrations on EbeanServer start)
https://github.com/ebean-orm/ebean-migration
database database-migrations flyway java
Last synced: 5 months ago
JSON representation
DB Migration runner (similar to Flyway) which can be used standalone or with Ebean (run migrations on EbeanServer start)
- Host: GitHub
- URL: https://github.com/ebean-orm/ebean-migration
- Owner: ebean-orm
- License: apache-2.0
- Created: 2016-05-18T05:10:27.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-07-02T10:48:54.000Z (over 1 year ago)
- Last Synced: 2025-04-24T02:09:18.657Z (9 months ago)
- Topics: database, database-migrations, flyway, java
- Language: Java
- Homepage:
- Size: 495 KB
- Stars: 9
- Watchers: 6
- Forks: 5
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/ebean-orm/ebean-migration/actions/workflows/build.yml)
[](https://maven-badges.herokuapp.com/maven-central/io.ebean/ebean-migration)
[](https://github.com/ebean-orm/ebean-migration/blob/master/LICENSE)
[](https://github.com/ebean-orm/ebean-migration/actions/workflows/jdk-ea.yml)
[](https://github.com/ebean-orm/ebean-migration/actions/workflows/native-image.yml)
# Ebean Migration
DB Migration runner (similar to FlywayDB) which can be used standalone or with Ebean (to run DB Migrations on EbeanServer start)
## Example use
To use firstly create a MigrationConfig and set properties, then create and run MigrationRunner.
```java
MigrationConfig config = new MigrationConfig();
config.setDbUsername("sa");
config.setDbPassword("");
config.setDbUrl("jdbc:h2:mem:db1");
// or load from Properties
Properties properties = ...
config.load(properties);
// run it ...
MigrationRunner runner = new MigrationRunner(config);
runner.run();
```
Then create a run a MigrationRunner. When running the database connection can either be:
- Passing a Connection explicitly
- Creating a connection (by specifying JDBC Driver and URL on MigrationConfig)
- Passing a DataSource (MigrationConfig dbUsername and dbPassword used)
### Run with explicit connection
```java
Connection connection = ...;
MigrationRunner runner = new MigrationRunner(config);
// pass explicit connection
runner.run(connection);
```
### Run with explicit DataSource
```java
DataSource dataSource = ...;
MigrationRunner runner = new MigrationRunner(config);
// pass a dataSource
runner.run(dataSource);
```
### Run creating a Connection (via MigrationConfig)
```java
MigrationRunner runner = new MigrationRunner(config);
runner.run();
```
## Notes:
MigrationConfig migrationPath is the root path (classpath or filesystem) where the migration scripts are searched for.
```java
MigrationConfig config = createMigrationConfig();
// load .sql migration resources from a file system location
config.setMigrationPath("filesystem:my-directory/dbmigration");
```
DB Migration runner follows the FlywayDB conventions and supports running "Versioned" migrations and "Repeatable" migrations.
```console
dbmigration
dbmigration/1.1__initial.sql
dbmigration/1.2__add_some_stuff.sql
dbmigration/R__create_views_repeatable.sql
```
"Repeatable migrations" start with `R__` and execute if they have not been or if their content has changed (using a Md5 checksum).
"Version migrations" start with `V` (or not) and have a version number (1.2 etc) followed by double underscore `__` and then a comment.