MySql 到 Hsqldb 迁移,在 sql 中使用 engine=InnoDb

MySql to Hsqldb migration with engine=InnoDb in sql

我正在为 gitlab 中的动态环境创建一个 spring 配置文件,不想为每个实例创建一个单独的 mysql 数据库,所以我尝试使用我现有的 liquibase 迁移在那个特定的配置文件中使用 hsqldb,这似乎除了 sql.
中的 engine=InnoDb 部分之外还有效 我已经将 sql.syntax_mys=true 添加到数据源 url,它支持数据类型,而不是引擎部分。

因为我想避免为动态环境编写不同的 sql 迁移并且已经有一个 prod 实例更改迁移或添加单独的迁移对我来说不是一个真正的选择。

有没有办法告诉 hsql 忽略那个部分,或者将它定义为某个什么都不做的函数?

一个例子 sql 是:

create table if not exists xy(
    field1             varchar(255) not null,
    field2  ....
) engine=InnoDB;

下个版本HSQLDB会加入自动剥离功能

同时,您可以修改JDBCStatement的源码,实现提交时的字符串校验和剥离。

更新:现在可在 http://hsqldb.org/download

获得具有此功能的快照 jar

MySQL 支持注释,包括条件执行的特殊格式: https://dev.mysql.com/doc/refman/8.0/en/comments.html

If you add a version number after the ! character, the syntax within the comment is executed only if the MySQL version is greater than or equal to the specified version number. The KEY_BLOCK_SIZE keyword in the following comment is executed only by servers from MySQL 5.1.10 or higher:

CREATE TABLE t1(a INT, KEY (a)) /*!50110 KEY_BLOCK_SIZE=1024 */;

HSQLDB 还支持 SQL 语句中的注释语法:http://www.hsqldb.org/doc/1.8/guide/ch09.html#N124ED

All these types of comments are ignored by the database.

基于此,您可以将 ENGINE=InnoDB 放入注释中,这样 HSQLDB 将忽略它,但 MySQL 将 运行 它:

create table if not exists xy(
    field1             varchar(255) not null,
    field2  ....
) /*!10000 engine=InnoDB; */