Skip to content

Instantly share code, notes, and snippets.

@yusuke2255 yusuke2255/file1.java
Last active Aug 29, 2015

Embed
What would you like to do?
【メモ】Dropwizardのmigrationでmigration.xmlファイルを指定する ref: http://qiita.com/Kawata/items/87172148fc86431b49e4
package jp.hoge;
import org.skife.jdbi.v2.DBI;
import io.dropwizard.Application;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.jdbi.DBIFactory;
import io.dropwizard.migrations.MigrationsBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
public class HogeApplication extends Application<HogeConfiguration> {
public static void main(String[] args) throws Exception {
new HogeApplication().run(args);
}
@Override
public String getName() {
return "hoge";
}
@Override
public void initialize(Bootstrap<HogeConfiguration> bootstrap) {
bootstrap.addBundle(new MigrationsBundle<HogeConfiguration>() {
@Override
public DataSourceFactory getDataSourceFactory(HogeConfiguration configuration) {
return configuration.getHogeDataSourceFactory();
}
});
}
@Override
public void run(HogeConfiguration configuration,Environment environment) throws Exception {
}
}
# dry-run
java -jar hoge-1.0.jar db migrate /home/hoge/hoge_config.yml --migrations /home/hoge/hoge_migration.yml --dry-run
databaseHoge:
driverClass: com.mysql.jdbc.Driver
user: hoge_user
password: hogepassword
url: jdbc:mysql://127.0.0.1:3306/hoge
properties:
charSet: UTF-8
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
<changeSet id="1" author="y.hogetaro">
<createTable tableName="messages">
<column name="id" type="int(11)" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(64)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
package jp.hoge;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.NotEmpty;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.Configuration;
import io.dropwizard.db.DataSourceFactory;
public class HogeConfiguration extends Configuration {
@Valid
@NotNull
@JsonProperty
private DataSourceFactory databaseHoge = new DataSourceFactory();
public DataSourceFactory getHogeDataSourceFactory() {
return databaseHoge;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.