简体   繁体   English

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

[英]MySql to Hsqldb migration with engine=InnoDb in sql

I am creating a spring profile for dynamic environments in gitlab and don't want to create a separate mysql db for each instance, so what I try is to use my existing liquibase migrations with hsqldb in that speciffic profile, which seems to work besides the engine=InnoDb part in the sql. I am creating a spring profile for dynamic environments in gitlab and don't want to create a separate mysql db for each instance, so what I try is to use my existing liquibase migrations with hsqldb in that speciffic profile, which seems to work besides the sql 中的 engine=InnoDb 部分。
I already added sql.syntax_mys=true to the datasource url, which supported the datatypes, not the engine part tho.我已经将sql.syntax_mys=true添加到数据源 url 中,它支持数据类型,而不是引擎部分。

Since I want to avoid writing different sql migrations for the dynamic environments and already have a prod instance changing the migration or adding separate migrations is not really an option for me.由于我想避免为动态环境编写不同的 sql 迁移,并且已经有一个产品实例更改迁移或添加单独的迁移,这对我来说并不是一个真正的选择。

Is there a way to tell hsql to just ignore that part, or define it as some function which does nothing?有没有办法告诉 hsql 忽略该部分,或者将其定义为一些 function 什么都不做?

An example sql would be:一个示例 sql 将是:

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

An automatic stripping feature will be added to HSQLDB in the next version.下一个版本将在 HSQLDB 中添加自动剥离功能。

In the meantime, you could modify the source code of JDBCStatement to check and strip the string when it is submitted.同时,您可以修改 JDBCStatement 的源代码,以便在提交时检查和剥离字符串。

Update: A snapshot jar with this feature is now available at http://hsqldb.org/download更新:具有此功能的快照 jar 现在可在http://hsqldb.org/download

MySQL supports comments, including a special format for conditional execution: https://dev.mysql.com/doc/refman/8.0/en/comments.html MySQL supports comments, including a special format for conditional execution: 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.字符,仅当 MySQL 版本大于或等于指定的版本号时才执行注释中的语法。 The KEY_BLOCK_SIZE keyword in the following comment is executed only by servers from MySQL 5.1.10 or higher:以下注释中的 KEY_BLOCK_SIZE 关键字仅由 MySQL 5.1.10 或更高版本的服务器执行:

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

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

All these types of comments are ignored by the database.所有这些类型的评论都会被数据库忽略。

Based on this, you could put the ENGINE=InnoDB into a comment so that HSQLDB will ignore it, but MySQL will run it:基于此,您可以将ENGINE=InnoDB放入注释中,以便 HSQLDB 将忽略它,但 MySQL 将运行它:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM