Last active
August 29, 2015 14:16
-
-
Save yusuke2255/1cea9be1048d7c20b85d to your computer and use it in GitHub Desktop.
【メモ】Dropwizardのmigrationでmigration.xmlファイルを指定する ref: http://qiita.com/Kawata/items/87172148fc86431b49e4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# dry-run | |
java -jar hoge-1.0.jar db migrate /home/hoge/hoge_config.yml --migrations /home/hoge/hoge_migration.yml --dry-run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
databaseHoge: | |
driverClass: com.mysql.jdbc.Driver | |
user: hoge_user | |
password: hogepassword | |
url: jdbc:mysql://127.0.0.1:3306/hoge | |
properties: | |
charSet: UTF-8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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