🔖 Flyway 示例

pull/1/head
Zhang Peng 2018-08-22 15:04:26 +08:00
parent ec69dbc775
commit 72f33c6a06
4 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,53 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.dunwu</groupId>
<artifactId>db-middleware-flyway</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>DB :: Middleware :: Flyway</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<dependencies>
<!-- db begin -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>5.1.4</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.197</version>
</dependency>
<!-- db end -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>5.1.4</version>
<configuration>
<url>jdbc:h2:file:./target/io/github/dunwu/db/middleware</url>
<user>sa</user>
</configuration>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.197</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,16 @@
package io.github.dunwu.db.middleware;
import org.flywaydb.core.Flyway;
public class FlywayDemo {
public static void main(String[] args) {
// Create the Flyway instance
Flyway flyway = new Flyway();
// Point it to the database
flyway.setDataSource("jdbc:h2:file:./target/io/github/dunwu/db/middleware", "sa", null);
// Start the migration
flyway.migrate();
}
}

View File

@ -0,0 +1,4 @@
create table PERSON (
ID int not null,
NAME varchar(100) not null
);

View File

@ -0,0 +1,3 @@
insert into PERSON (ID, NAME) values (1, 'Axel');
insert into PERSON (ID, NAME) values (2, 'Mr. Foo');
insert into PERSON (ID, NAME) values (3, 'Ms. Bar');