使用flyway
This commit is contained in:
@@ -62,6 +62,11 @@
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- utils -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
@@ -121,28 +126,4 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>refresh-db</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<configuration>
|
||||
<target>
|
||||
<property file="src/main/resources/application-prod.properties" />
|
||||
<sql driver="${spring.datasource.driverClassName}" url="${spring.datasource.url}" userid="${spring.datasource.username}"
|
||||
password="${spring.datasource.password}" onerror="continue" encoding="${project.build.sourceEncoding}">
|
||||
<classpath refid="maven.test.classpath" />
|
||||
<transaction src="src/main/resources/schema-h2.sql" />
|
||||
<transaction src="src/main/resources/data-h2.sql" />
|
||||
</sql>
|
||||
</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "init db for production mode"
|
||||
|
||||
mvn antrun:run -Prefresh-db
|
||||
@@ -6,7 +6,6 @@ management.port=7002
|
||||
app.loginTimeoutSecs=600
|
||||
|
||||
# db init settings
|
||||
spring.datasource.platform=h2
|
||||
spring.datasource.sqlScriptEncoding=UTF-8
|
||||
spring.jpa.hibernate.ddl-auto=validate
|
||||
spring.jpa.showsql=false
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
drop table if exists book;
|
||||
drop table if exists account;
|
||||
drop table if exists message;
|
||||
|
||||
create table book (
|
||||
id bigint generated by default as identity,
|
||||
douban_id varchar(64) not null,
|
||||
title varchar(128) not null,
|
||||
url varchar(255),
|
||||
description varchar(255),
|
||||
owner_id bigint not null,
|
||||
onboard_date timestamp,
|
||||
status varchar(32) not null,
|
||||
borrower_id bigint null,
|
||||
borrow_date timestamp,
|
||||
primary key (id)
|
||||
);
|
||||
|
||||
create table account (
|
||||
id bigint generated by default as identity,
|
||||
name varchar(64) not null,
|
||||
email varchar(128),
|
||||
hash_password varchar(255),
|
||||
primary key (id)
|
||||
);
|
||||
|
||||
create table message (
|
||||
id bigint generated by default as identity,
|
||||
receiver_id bigint null,
|
||||
message varchar(256),
|
||||
receive_date timestamp,
|
||||
primary key (id)
|
||||
);
|
||||
|
||||
|
||||
|
||||
insert into book (id, douban_id, title, url, description, owner_id,status,onboard_date) values(1,'25984046', 'Big Data日知录', 'http://book.douban.com/subject/25984046/','', 1,'idle','2015-01-01');
|
||||
insert into book (id, douban_id, title, url, description, owner_id,status,onboard_date) values(2,'25900156', 'Redis设计与实现', 'http://book.douban.com/subject/25900156/','', 1,'idle','2015-01-02');
|
||||
insert into book (id, douban_id, title, url, description, owner_id,status,onboard_date) values(3,'25741352', 'DSL实战', 'http://book.douban.com/subject/25741352/','', 2,'idle','2015-01-03');
|
||||
|
||||
insert into account (id,email,name,hash_password) values(1,'calvin.xiao@vipshop.com','Calvin','+2MunThvGcEfdYIFlT4NQQHt6z4=');
|
||||
insert into account (id,email,name,hash_password) values(2,'david02.wang@vipshop.com','David','+2MunThvGcEfdYIFlT4NQQHt6z4=');
|
||||
@@ -10,13 +10,8 @@ cd modules
|
||||
call %MVN% clean install
|
||||
if errorlevel 1 goto error
|
||||
|
||||
|
||||
echo [Step 2] init db for production mode..
|
||||
echo [Step 2] run boot-api project in dev mode.
|
||||
cd ..\examples\boot-api
|
||||
call %MVN% antrun:run -Prefresh-db
|
||||
if errorlevel 1 goto error
|
||||
|
||||
echo [Step 3] run boot-api project in dev mode.
|
||||
call %MVN% spring-boot:run
|
||||
if errorlevel 1 goto error
|
||||
|
||||
|
||||
@@ -13,11 +13,8 @@ if [ $? -ne 0 ];then
|
||||
exit -1
|
||||
fi
|
||||
|
||||
echo "[Step 2] init db for production mode."
|
||||
echo "[Step 2] run boot-api project in dev mode."
|
||||
cd ../examples/boot-api
|
||||
mvn antrun:run -Prefresh-db
|
||||
|
||||
echo "[Step 3] run boot-api project in dev mode."
|
||||
mvn spring-boot:run
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#H2 Server Properties
|
||||
#Sun Nov 08 17:40:21 CST 2015
|
||||
#Tue Nov 10 01:20:28 CST 2015
|
||||
0=Generic H2 (Server)|org.h2.Driver|jdbc\:h2\:tcp\://localhost/~/test|sa
|
||||
1=Generic H2 (Embedded)|org.h2.Driver|jdbc\:h2\:mem\:testdb|sa
|
||||
2=H2 Boot API DB|org.h2.Driver|jdbc\:h2\:file\:~/.h2/bootapi;AUTO_SERVER\=TRUE;DB_CLOSE_DELAY\=-1;|sa
|
||||
|
||||
Reference in New Issue
Block a user