To activate autoconfiguration just add dependency from maven central.
This project is intended to be used with spring-boot executable fat jar.
In distinction to MyBatis Migrations CLI there is no need for drivers
and environments
folders. Drivers are managed as maven dependencies and environments are configured through spring boot properties and profiles.
To place scripts
folder in classpath (for example in src/main/resources
folder) should be enough. You can use migrations-maven-plugin to create migration scripts.
After you package your app with mvn package
, app would like to migrate database on startup and then run itself.
Furthermore, you can use your app for controlled migrations. See full usage with:
java -jar target/app.jar migrations
and status of your database with:
java -jar target/app.jar migrations status
If you want to provide additional Spring or Java parameters, ensure to place migration commands last:
java -jar target/app.jar --spring.profiles.active=test migrations up
Currently following commands are supported:
- status: Report the current state of the database
- bootstrap: Runs the bootstrap migration script
- up: Run unapplied migrations
- pending: Run pending migrations
- version: Migrate to specific version
- down: Runs the undo section of migration scripts
Following defaults are provided by autoconfiguration:
mybatis.migrations:
enabled: true
path: classpath:scripts
charset: UTF-8
properties:
cliCommand: migrations
migrationCommand: [--no-exit, up]
MyBatis Migrations defaults are described by DatabaseOperationOption.java.
enabled
: is useful to disable migrations. For example to use Hibernate Schema Updates for development.
path
: path to migrations scripts. This can be a physical location as well:
mybatis.migrations.path: file:/home/user/workspace/migration/scripts
properties
: Additional properties for placeholder replacement in migration scripts:
mybatis.migrations:
properties:
myVariable: Hello world!
anotherVariable: yes, I can!
cliCommand
: which command is used for CLI. Useful on commands clash.
migrationCommand
: which command should run before app is started.
Just inject SpringMyBatisMigrations
bean. For example:
@Autowired
private SpringMyBatisMigrations springMyBatisMigrations;
@Before
public void createDb() {
springMyBatisMigrations.up(null);
}
@After
public void dropDb() {
springMyBatisMigrations.down(2);
}
The MIT License (MIT)
Copyright (c) 2017, Anton Bessonov
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.