我在 MySQL 8 中使用 Liquibase 时遇到一个问题,其中以下脚本没有放置“time(3)”类型的小数部分,它仅将“time”放置在列的类型上。我们之前在 MySQL 5 上运行过这个脚本,效果很好。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.16.xsd"
logicalFilePath="20220901.xml">
<changeSet author="MyUser" id="Change column 'time' to Datatype to milliseconds">
<modifyDataType
columnName="time"
newDataType="TIME(3)"
schemaName="${defaultSchema}"
tableName="table1"/>
<addNotNullConstraint
columnDataType="TIME(3)"
columnName="time"
schemaName="${defaultSchema}"
tableName="table1" />
</changeSet>
</databaseChangeLog>
Run Code Online (Sandbox Code Playgroud)
我尝试将 liquibase.core(至 4.16.1)和 mysql-connector-java(至 8.0.30)的 Maven 依赖项更新到最新版本,问题仍然存在。
经过多次测试,我发现问题可能出在 liquibase 生成的查询上,该查询不包含分数部分“(3)”,因此作为解决方法,我使用“modifySql”在最后更改查询。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.16.xsd"
logicalFilePath="20220901.xml">
<!-- WORK-AROUND - Liquibase was generating a query with type 'TIME' instead of 'TIME(3)' so
we use 'REPLACE_WITH_TIME' as …Run Code Online (Sandbox Code Playgroud)