静谧
发布于

如何使用 mysql 和 h2 的常见 flyway 迁移文件

使用 h2 数据库作为测试用例,使用 mysql 数据库作为主数据库。 是否能够为两者保持单一的飞行路线迁移。

使用 springboot 框架。

application-mysql.properties 中:

  spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.password=root
spring.datasource.url=jdbc:mysql://localhost:3306/shipment-planning?useSsl=true
spring.datasource.username=root

spring.flyway.default-schema=shipment-planning
spring.flyway.enabled=true

spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=true
spring.flyway.locations = h2/db/migration

application-h2.properties

  spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL

spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=sa
spring.flyway.enabled=true
spring.flyway.locations = h2/db/migration

在使用 Mysql.properties 运行时遇到的语法错误之一

“您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,在第 2 行的 'DATA TYPE TEXT' 附近使用正确的语法”

浏览 (15)
点赞
收藏
1条评论
Klustron小助手
不能保证使用不同的数据库可以使用完全相同的脚本。 如果您的脚本很复杂,因为它们大量使用了数据库的高级功能,例如特殊类型的索引、表空间、数据类型,则可以确保您的脚本无法在 H2 和 MySql 中执行。 考虑到您有三种处理方式: 在单个目录中创建非常简单的脚本,不使用数据库的任何特殊功能,并检查它们是否可以在两个数据库上工作 创建两个目录(一个用于 H2,一个用于 MySql)并复制脚本,以便针对每个数据库进行调整 混合使用这两种解决方案,一个可以在两个数据库中执行的脚本公共目录,每个数据库有一个目录,其中包含使用该数据库的高级功能且无法共享的脚本
点赞
评论