首页 > 数据库技术 > 详细

自动执行sql脚本插件

时间:2019-06-09 16:26:21      阅读:111      评论:0      收藏:0      [点我收藏+]

注:简单记录,方便自己查阅

插件名: 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文件

自动执行sql脚本插件

原文:https://www.cnblogs.com/lngo/p/10993812.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!