flyway 相关问题

Boxfuse的Flyway是一个开源数据库迁移工具。它强烈支持简单性和约定优于配置。

Flyway设置位于Java

我只是使用最新版本,并且阅读文档我找不到以编程方式指定飞行的方式来指定我的迁移v*_description.sql文件在file-sys ...

回答 2 投票 0



FlywaySpring引导错误:无法连接到数据库。配置URL,用户和密码

大家早上好, 我正在为我的应用程序创建一个后端,我想使用Flayway迁移数据库。 i我将所需的依赖性添加到我的pom.xml

回答 1 投票 0

有可能使用Flyway通过Athena创建冰山桌

我们计划使用冰山表代替PostgreSQL。对于PostgreSQL,我们正在使用Flyway进行数据库迁移。因此,我想知道是否也可以为冰山桌做到这一点。 chatgpt

回答 1 投票 0


尝试在詹金斯上建立一个工作,我使用fluway-sbt插件

我正在构建一个使用flyway-sbt的特定工作。奇怪的是,该作业在本地运行,但在詹金斯中失败,错误消息是: [警告] 注意:一些未解决的依赖关系有

回答 1 投票 0

从 Flyway 迁移中删除可重复脚本的最佳方法是什么

我目前正在使用 Flyway 命令行工具来管理我们的脚本,这些脚本将通过从 CI 构建服务器触发的发布过程来调用。 问题是我有 274 个可重复迁移...

回答 2 投票 0

使用 EmbeddedId 创建名为“entityManagerFactory”的 bean 时出错

我遇到了这个问题,我收到错误创建名为“entityManagerFactory”的 bean 时出错 错误 LocalContainerEntityManagerFactoryBean.buildNativeEntityManagerFactory:426 - 无法初始化 JPA

回答 1 投票 0

Flyway Gradle 插件使用 postgres 连接字符串手动运行

我正在尝试使用 https://documentation.red-gate.com/fd/gradle-task-184127407.html 手动运行 Flyway 迁移。 在 micronaut application.properties 文件中我已经有一个 postgres

回答 1 投票 0

在 Micronaut 中使用 gradle Flyway 插件手动运行 Flyway 迁移

我正在尝试手动运行flyway迁移,而不是在应用程序启动时运行,使用以下参考 - https://documentation.red-gate.com/fd/gradle-task-184127407.html 在 b...

回答 1 投票 0

Flyway升级与过渡到在线模式迁移等

我们的主要项目自启动以来一直使用现在非常旧的 Flyway 版本。 (v3.2.1) Flyway 多年来进行了大量改进,v6+ 似乎包含许多有趣的功能......

回答 2 投票 0

对于没有java经验的人来说flyway入门

我对测试flyway很感兴趣,如果我没记错的话,我读到它支持通过java和SQL进行数据库更改。我是一名 dba,熟悉 SQL,但不熟悉 java。 我通读了“获得明星...

回答 1 投票 0

验证失败:检测到应用的迁移未在本地解决 |飞行路线

在设置 Flyway 时,我在 spring-boot 应用程序中收到此错误 org.springframework.beans.factory.BeanCreationException:创建类中定义的名称为“flywayInitializer”的bean时出错...

回答 5 投票 0

Flyway DB 脚本拼写错误

我有一个 Flyway 脚本,它创建一个新表来将报告数据存储到另一个表的数据中。 我在从 Java 对象剪切和粘贴时犯了一个错误,正如您在下面的脚本中看到的,&

回答 1 投票 0

BeanCreationException:创建名为“flywayInitializer”的 bean 时出错

我正在尝试在 Docker 容器中运行我的项目测试。所有测试在本地运行时都运行良好。当我尝试将测试转移到 docker 容器时,错误开始发生。 这里...

回答 7 投票 0

如何在 sprintboot stratup 上运行反应式 r2dbc 驱动程序的 Flyway 迁移

我正在使用非阻塞数据库驱动程序r2dbc开发springboot webflux项目, 但是当 Springboot 应用程序启动时,Flyway 不会运行迁移。 下面是我的 spring-boot pom.xml 我正在使用非阻塞数据库驱动程序开发 springboot webflux 项目r2dbc, 但是当 Springboot 应用程序启动时,Flyway 不会运行迁移。 下面是我的 spring-boot pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>r2dbmigration</artifactId> <version>0.0.1-SNAPSHOT</version> <name>r2dbmigration</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot.experimental</groupId> <artifactId>spring-boot-starter-data-r2dbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>org.flywaydb</groupId> <artifactId>flyway-core</artifactId> </dependency> <dependency> <groupId>io.r2dbc</groupId> <artifactId>r2dbc-postgresql</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot.experimental</groupId> <artifactId>spring-boot-test-autoconfigure-r2dbc</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot.experimental</groupId> <artifactId>spring-boot-bom-r2dbc</artifactId> <version>0.1.0.M3</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> </repository> </repositories> </project> 我的迁移文件是:V1.1__create_file_import_table.sql 内容为 DROP TABLE IF EXISTS file_import; CREATE TABLE file_import ( id BIGINT GENERATED ALWAYS AS IDENTITY, file_key CHARACTER VARYING(255) NOT NULL, created_at TIMESTAMP without time zone NOT NULL, created_by BIGINT NOT NULL, PRIMARY KEY (id) ); 应用程序属性 spring.r2dbc.url= r2dbc:postgresql://localhost:5432/import spring.r2dbc.username=postgres spring.r2dbc.password=password 我的应用程序启动顺利,但没有迁移运行。 有人可以帮助我吗? Github 网址 谢谢 以下 Java 实现基于 @Sim 的 Kotlin 示例。 示例pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.0.RC1</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>flyway</artifactId> <version>0.0.1-SNAPSHOT</version> <name>flyway</name> <description>Demo project for Spring Boot</description> <properties> <java.version>11</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-r2dbc</artifactId> </dependency> <dependency> <groupId>dev.miku</groupId> <artifactId>r2dbc-mysql</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.flywaydb</groupId> <artifactId>flyway-core</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> </pluginRepository> </pluginRepositories> </project> 示例application.yml --- spring: r2dbc: url: r2dbc:pool:mysql://localhost:3306/defaultdb username: <user> password: <pass> flyway: url: jdbc:mysql://localhost:3306/defaultdb user: ${spring.r2dbc.username} password: ${spring.r2dbc.password} baseline-on-migrate: true 添加以下 Spring Boot 配置 - FlywayConfig.java package com.example.flyway; import org.flywaydb.core.Flyway; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; // https://stackoverflow.com/a/61412233 @Configuration public class FlywayConfig { private final Environment env; public FlywayConfig(final Environment env) { this.env = env; } @Bean(initMethod = "migrate") public Flyway flyway() { return new Flyway(Flyway.configure() .baselineOnMigrate(true) .dataSource( env.getRequiredProperty("spring.flyway.url"), env.getRequiredProperty("spring.flyway.user"), env.getRequiredProperty("spring.flyway.password")) ); } } 首次执行: : Bootstrapping Spring Data R2DBC repositories in DEFAULT mode. : Finished Spring Data repository scanning in 7ms. Found 0 R2DBC repository interfaces. : Flyway Community Edition 6.4.1 by Redgate : Database: jdbc:mysql://localhost:3306/defaultdb (MySQL 5.5) : Successfully validated 1 migration (execution time 00:00.006s) : Creating Schema History table `defaultdb`.`flyway_schema_history` ... : DB: Name 'flyway_schema_history_pk' ignored for PRIMARY key. (SQL State: 42000 - Error Code: 1280) : Current version of schema `defaultdb`: << Empty Schema >> : Migrating schema `defaultdb` to version 1.0.001 - Initialise database tables : Successfully applied 1 migration to schema `default` (execution time 00:00.036s) : Netty started on port(s): 8080 :Started Application in 1.829 seconds (JVM running for 2.343) 第二次执行: : No active profile set, falling back to default profiles: default : Bootstrapping Spring Data R2DBC repositories in DEFAULT mode. : Finished Spring Data repository scanning in 11ms. Found 0 R2DBC repository interfaces. : Flyway Community Edition 6.4.1 by Redgate : Database: jdbc:mysql://localhost:3306/defaultdb (MySQL 5.5) : Successfully validated 1 migration (execution time 00:00.009s) : Current version of schema `defaultdb`: 1.0.001 : Schema `defaultdb` is up to date. No migration necessary. : Netty started on port(s): 8080 : Started Application in 1.273 seconds (JVM running for 1.695) 回答有点晚了,但您也可以手动设置 Spring bean 来处理迁移。 将 Flyway 配置添加到 application.yml(或 .properties): spring: flyway: url: jdbc:postgresql://localhost:5432/<db-name> user: <user> password: <password> 此代码是 Kotlin,但可以轻松翻译为 Java: import org.flywaydb.core.Flyway import org.springframework.boot.autoconfigure.flyway.FlywayProperties import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @Configuration class FlywayConfig(private val flywayProperties: FlywayProperties) { @Bean(initMethod = "migrate") fun flyway(): Flyway? { return Flyway(Flyway.configure() .baselineOnMigrate(true) .dataSource(flywayProperties.url, flywayProperties.user, flywayProperties.password) ) } } 这个问题似乎还没有“官方”解决方案,但有一个临时解决方案可以解决这个问题:“R2DBC迁移工具”。 @Nikita Konev 为我们提供了一个很好的临时解决方案来解决这个问题。我一直在用它并且效果很好。 请检查: R2DBC 支持 - Flyway:https://github.com/flyway/flyway/issues/2502 R2DBC 迁移工具:https://github.com/nkonev/r2dbc-migrate 示例项目(您可以尝试一下):https://github.com/nkonev/r2dbc-migrate-example 感谢尼基塔·科内夫 通过结合使用 Flyway + JDBC 和 R2DBC 来完成其余的数据库交互,解决了这个问题。 应用程序.属性 my.database.url=postgresql://localhost:5432}/my_database spring.r2dbc.url=r2dbc:${my.database.url} spring.r2dbc.username=user spring.r2dbc.password=pass spring.flyway.locations=classpath:db/migration spring.flyway.enabled=true spring.flyway.validate-on-migrate=true spring.flyway.user=${spring.r2dbc.username} spring.flyway.password=${spring.r2dbc.password} spring.flyway.url=jdbc:${my.database.url} 构建.gradle dependencies { ... implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc' runtimeOnly 'org.flywaydb:flyway-core:7.9.1' runtimeOnly 'org.postgresql:postgresql:42.2.20' runtimeOnly 'io.r2dbc:r2dbc-postgresql' runtimeOnly 'org.springframework.boot:spring-boot-starter-jdbc' ... } flyway迁移SQL脚本的位置: src/main/resources/db/migration/V1__create_my_table.sql 这可能是延迟响应,但就我个人而言,我更喜欢只添加弹簧启动器。 这对我有用: // build.gradle.kts implementation("org.flywaydb:flyway-core:7.9.1") runtimeOnly("org.springframework.boot:spring-boot-starter-jdbc") runtimeOnly("org.postgresql:postgresql:42.2.20") 那么您的 application.yml 文件可能如下所示: # application.yml spring: r2dbc: url: r2dbc:postgresql://user:pass@host/db flyway: enabled: true validate-on-migrate: true user: user password: pass url: jdbc:postgresql://host:5432/db schemas: ["schema"] 评论中提到:R2DBC 和 Flyway 还不兼容。 解决方法是使用 Maven Flyway 插件执行 Flyway 迁移,请注意,您需要提供JDBC-URL。 在您的情况下,您可以通过触发迁移 mvn flyway:migrate -Dflyway.url=jdbc:postgresql://localhost:5432/import -Dflyway.user=postgres -Dflyway.password=password 或通过 mvn flyway:migrate 如果您在 pom.xml 中添加插件+配置 <plugin> <groupId>org.flywaydb</groupId> <artifactId>flyway-maven-plugin</artifactId> <version>6.1.3</version> <configuration> <url>jdbc:postgresql://localhost:5432/import</url> <user>postgres</user> <password>password</password> </configuration> </plugin> 通过 执行迁移 有一个 R2dbc Migrate 项目 可以使用 R2dbc API 处理数据库迁移。 与传统的 Flyway 等相比,它不需要 Jdbc 驱动,并且您可以在将 r2dbc-migrate-spring-boot-starter 添加到项目依赖项中时直接重用 Spring r2dbc 属性,并且 R2dbc Migrate db 脚本文件格式 100% 兼容飞行路线。如果您有一些 Flyway 经验,很容易迁移到使用 R2dbc Migrate。 我已经在实际项目中使用它超过3年了,效果很好。 检查我的示例项目:https://github.com/hantsy/spring-r2dbc-sample/tree/master/r2dbc-migrate

回答 7 投票 0

尝试通过 docker-compose 使用 Flyway 迁移数据库时连接被拒绝

所以我遇到了一个问题,我使用 docker-compose 通过 Flyway 设置和运行我的数据库和迁移,但我遇到了一个问题,其中 Flyway 容器不断抛出以下错误...

回答 1 投票 0

如何处理 Azure 应用服务部署中的长启动时间

我正在将 Spring Boot 应用程序部署到 Azure 应用程序服务。此应用程序连接到配置为使用飞路迁移的数据库。 当尝试发布我的最新版本时,我有一个飞行迁移......

回答 1 投票 0

Flyway 可以检查意外的(外部造成的)差异吗?

我正在评估 Flyway,想知道它是否可以检查是否存在任何外部更改? IE。如果有人在 Flyway 之外直接对数据库进行更改,我可以发现吗?...

回答 3 投票 0

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.