我正在使用flyway迁移集成测试数据库,这是我的Maven构建的一部分。
我已将飞行路线配置为在pre-integration-test
阶段运行。每次都会清理并重建数据库。
<build>
<plugins>
<!-- Flyway -->
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>5.1.4</version>
<configuration>
<url>${jdbc.url}</url>
<schemas>
<schema>public</schema>
</schemas>
</configuration>
<executions>
<execution>
<id>migrate-database</id>
<phase>pre-integration-test</phase>
<goals>
<goal>clean</goal>
<goal>migrate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我使用mvn clean install
运行该构建,并向其传递测试数据库的JDBC URL。如您所见,它以postgres用户racer_test
racer
mvn -Djdbc.url=jdbc:postgresql://localhost:5432/racer_test?user%3Dracer%26password%3Dfoo clean install
在构建过程中一切正常
[INFO] --- flyway-maven-plugin:5.1.4:clean (migrate-database) @ racer-api ---
[INFO] Flyway Community Edition 5.1.4 by Boxfuse
[INFO] Database: jdbc:postgresql://localhost:5432/racer_test (PostgreSQL 9.6)
[INFO] Successfully cleaned schema "public" (execution time 00:00.026s)
[INFO]
[INFO] --- flyway-maven-plugin:5.1.4:migrate (migrate-database) @ racer-api ---
[INFO] Database: jdbc:postgresql://localhost:5432/racer_test (PostgreSQL 9.6)
[INFO] Successfully validated 1 migration (execution time 00:00.005s)
[INFO] Creating Schema History table: "public"."flyway_schema_history"
[INFO] Current version of schema "public": << Empty Schema >>
[INFO] Migrating schema "public" to version 1 - create users
[INFO] Successfully applied 1 migration to schema "public" (execution time 00:00.040s)
但是,当我在postgres中查看数据库时,它创建的表和其他对象是我以(jeeves
)登录的系统用户而不是我指定的用户({{1} })
racer
我以某种方式指定用户不正确吗?它不应该是JDBC URL的一部分吗?
谢谢!
答案 0 :(得分:1)
您应该使用flyway用户参数执行此操作:只需将-Dflyway.user=racer
添加到您的maven命令中,即可正常工作!如果您使用的是flyway.properties
文件,只需在其后附加flyway.user=racer
。
另外,如果使用url,则应将具有postgres的用户设置如下:
jdbc:postgresql://{$user}:{$optional_password}@{$host}:{$port}/{$db_name}{$GET_parameters}