注:简单记录,方便自己查阅
插件名: db-migrator-maven-plugin
pom.xml (environments 中配置的key和database.properties的前缀匹配,配了就会执行)
<plugin>
<groupId>org.javalite</groupId>
<artifactId>db-migrator-maven-plugin</artifactId>
<version>${activejdbc.version}</version>
<configuration>
<configFile>${project.basedir}/src/main/resources/database.properties</configFile>
<environments>development.test,development</environments>
</configuration>
<executions>
<execution>
<id>dev_migrations</id>
<phase>validate</phase>
<goals>
<goal>migrate</goal>
</goals>
</execution>
</executions>
<dependencies>
<!--<dependency>-->
<!--<groupId>mysql</groupId>-->
<!--<artifactId>mysql-connector-java</artifactId>-->
<!--<version>5.1.34</version>-->
<!--</dependency>-->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.198</version>
<!--<scope>test</scope>-->
</dependency>
</dependencies>
</plugin>
database.properties
development.driver=org.h2.Driver development.username=sa development.password= development.url=jdbc:h2:~/test #development.test.driver=com.mysql.jdbc.Driver #development.test.username=root #development.test.password=123456 #development.test.url=jdbc:mysql://localhost:3306/movies_test
mvn指令
mvn db-migrator:help ... [INFO] db-migrator:drop [INFO] drops database configured in pom [INFO] db-migrator:create [INFO] creates database configured in pom [INFO] db-migrator:new [INFO] creates a new migration file [INFO] db-migrator:check [INFO] checks that no pending migrations remain. This can be used in build lifecycle to fail the build if pending migrations are found [INFO] db-migrator:migrate [INFO] migrates all pending migrations [INFO] db-migrator:validate [INFO] validates and prints a report listing pending migrations [INFO] db-migrator:reset [INFO] drops/re-creates the database, and runs all migrations, effectively resetting database to pristine state [INFO] db-migrator:help [INFO] prints this message
通常以下两个步骤即可:
mvn db-migrator:create 基于数据库链接创建数据库
mvn db-migrator:migrate 执行sql文件
原文:https://www.cnblogs.com/lngo/p/10993812.html