版本
Liquibase: 3.6.2
春季靴: 2.1.0.RELEASE
MySQL / MariaDB: MySQL Ver 15.1 Distrib 10.1.25-MariaDB,用于Win32(AMD64)
H2: 1.4.197
目标
我有一个迁移脚本,该脚本将数据从两个表转换为一个表。该脚本是用SQL编写的,并且可以正常运行(通过手动执行进行验证)。此外,当使用H2数据库运行迁移时,它运行良好。
问题
当我切换到MySQL / MariaDB时,未按照脚本中的定义插入数据。但是,根据databasechangelog表,脚本可以正常运行:
004.transform_translatable_data vetemi classpath:db/changelogs/0004.transfrom_translatabl... 2018-12-07 16:26:14 68 EXECUTED 8:3dc05e2db0d93de8ce10de09612dd2c0 sqlFile NULL 3.6.2 NULL NULL 4196374083
运行应用程序(日志文件)时也没有错误:
2018-12-07 16:26:14.880 INFO 13628 --- [ main] liquibase.changelog.ChangeSet : ChangeSet classpath:db/changelogs/0004.transfrom_translatable_data.yaml::004.transform_translatable_data::vetemi ran successfully in 0ms
注意日志消息的结尾,执行时间为0ms。这很可疑。
在H2上运行相同的设置将显示16ms的执行时间:
2018-12-07 16:37:40.699 INFO 13648 --- [ main] liquibase.changelog.ChangeSet : ChangeSet classpath:db/changelogs/0004.transfrom_translatable_data.yaml::004.transform_translatable_data::vetemi ran successfully in 16ms
很明显,即使Spring和Liquibase没有显示任何错误,该脚本也没有运行。
迁移脚本:
INSERT INTO `activity_translatables` (`id`, `name`, `description`, `modified`, `created`, `language_id`, `parent_id`)
SELECT UUID(), activities.name, activities.description, activities.modified, activities.created, languages.id, activities.id
FROM `activities`, `languages`
WHERE languages.locale = 'de';
liquibase更改日志:
- changeSet:
id: 004.transform_translatable_data
author: vetemi
changes:
- sqlFile:
dbms: h2, mysql
encoding: utf8
endDelimiter: \nGO
path: ../data/004.transform_translatable.sql
relativeToChangelogFile: true
splitStatements: true
stripComments: true
我也尝试过:
- changeSet:
id: 004.transform_translatable_data
author: vetemi
changes:
- sql:
comment: transfer all activities translatables into the new table with German as default
dbms: mysql, h2
splitStatements: true
sql: insert into activities_translatables (id, name, modified, created, language_id, parent_id)
select UUID(), activities.description, activities.modified, activities.created, languages.id, activities.id
from activities, languages
where languages.locale = 'de'
stripComments: true
属性文件:
spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://localhost:3306/db
spring.datasource.username=root
spring.datasource.password=
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.platform=mysql
我想念什么?为什么它不起作用?
答案 0 :(得分:1)
我们目前正在从Spring Boot 1.5.x迁移到Spring Boot 2.1.17,我们在Liquibase
和MariaDB
数据库中也遇到了同样的问题。
问题似乎是它们将MySQL
与MariaDb
进行了新的区分,并且此配置不再有效:
<property name="re.component.name" value="edos-dp-project-manager" />
<changeSet author="edosdp" id="1.0.0-${re.component.name}" logicalFilePath="path-independent">
<sqlFile encoding="utf8" endDelimiter=";" path="Create_DataBase.sql" relativeToChangelogFile="true" splitStatements="true" stripComments="true" dbms="mysql"/>
<sqlFile encoding="utf8" endDelimiter=";" path="Create_Database_H2.sql" relativeToChangelogFile="true" splitStatements="true" stripComments="true" dbms="h2"/>
</changeSet>
在发生这种情况时,有一条日志消息(处于DEBUG级别!!)表明了这一点:
2019-10-25 10:33:23,249+0200 [DEBUG] liquibase.changelog.ChangeSet edos-dp-project-manager 1.5.0-SNAPSHOT - Change sqlFile not included for database mariadb
因此,您现在需要将DMBS设置为mariadb ,以便更改日志如下所示:
<property name="re.component.name" value="edos-dp-project-manager" />
<changeSet author="edosdp" id="1.0.0-${re.component.name}" logicalFilePath="path-independent">
<sqlFile encoding="utf8" endDelimiter=";" path="Create_DataBase.sql" relativeToChangelogFile="true" splitStatements="true" stripComments="true" dbms="mariadb"/>
<sqlFile encoding="utf8" endDelimiter=";" path="Create_Database_H2.sql" relativeToChangelogFile="true" splitStatements="true" stripComments="true" dbms="h2"/>
</changeSet>