用liquibase,保留的关键字生成JOOQ代码? (“价值”列名称错误)

发布于 2025-01-26 02:12:10 字数 1158 浏览 3 评论 0原文

我有一个在Liquibase脚本中定义的表格,其中一个名为“ Value”的列:

- column:
    name: value
    type: VARCHAR
    constraints:
      - nullable: false

DBMS是

使用Maven插件运行JOOQ CODEGEN时的PostgResQL,它将运行Liquibase脚本,并且我会收到以下错误:

Syntax error in SQL statement "CREATE TABLE PUBLIC.TABLE_NAME (ID BIGINT AUTO_INCREMENT NOT NULL, ... , VALUE[*] VARCHAR NOT NULL)"; expected "identifier";

如果我从“从“更改”列名称中”:价值“对其他任何东西,它都有效。随着Jooq升至3.15版,它可以正常工作。

关于如何处理这个问题的任何线索?我宁愿不更改名称,我有多个表格,其中包含一个名为“ Value”的列,因此它是一个很大的重构,并且明智的命名是它代表的最合适的名称。

解决方案

已经在较新版本的Liquibase中修复,因此您可以手动指定在JOOQ Codegen中使用的LB版本:

<plugin>
        <groupId>org.jooq</groupId>
        <artifactId>jooq-codegen-maven</artifactId>
        <version>${jooq.version}</version>
        <dependencies>
          <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
            <version>${liquibase.version}</version>
          </dependency>
        ...
</plugin>

I have a table defined in a liquibase script with a column named "value":

- column:
    name: value
    type: VARCHAR
    constraints:
      - nullable: false

dbms is postgresql

When running the JOOQ codegen with the maven plugin, it runs the liquibase script and I get the following error:

Syntax error in SQL statement "CREATE TABLE PUBLIC.TABLE_NAME (ID BIGINT AUTO_INCREMENT NOT NULL, ... , VALUE[*] VARCHAR NOT NULL)"; expected "identifier";

If I change the column name from "value" to anything else, it works. With JOOQ up to version 3.15, it works.

Any clue on how to handle this? I'd rather not change the name, I have multiple tables with a column named "value" so it's a quite big refactor, and naming wise I feel it's the most appropriate name for what it represents.

Solution

This is already fixed in the newer versions of liquibase, so you can manually specify which LB version to use in the jOOQ codegen:

<plugin>
        <groupId>org.jooq</groupId>
        <artifactId>jooq-codegen-maven</artifactId>
        <version>${jooq.version}</version>
        <dependencies>
          <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
            <version>${liquibase.version}</version>
          </dependency>
        ...
</plugin>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疯狂的代价 2025-02-02 02:12:10

为什么会发生这种情况

在JOOQ 3.16的代码生成配置中,模拟您的内存中H2数据库的迁移,从H2 2.0开始,该数据库已声明value一个关键字,而无需报价就不能再用作标识符。

在liquibase上进行解决方法

,因此您的解决方法可能是引用所有对象(或保留单词,如果liquibase与H2的最新更改保持最新状态):
https://docs.liquibase.com/parameters.com/parameters/object-quoting-strategy-strategy。 html

例如

databaseChangeLog:
    -  object-quoting-strategy: QUOTE_ALL_OBJECTS

,这意味着您应该确保仅在液体库群配置中使用较低的案例标识符,以免在PostgreSQL数据库中偶然地创建案例敏感标识符,

液体

我不能用最新版本来重现此 liquibase。看来他们已经修复了此问题,现在支持H2 2.x

在Jooq Jooq中正确的修复程序

应该在Jooq方面进行修复。最终,将H2从方程式中删除(至少可以选择退出使用),JOOQ将直接解释Liquibase生成的DDL以生成您的代码。相关功能请求是:
https://github.com/jooq/jooq/jooq/sissues/7034

Why this happens

The LiquibaseDatabase in jOOQ 3.16's code generation configuration works by simulating your migration against an in-memory H2 database, which, starting from H2 2.0 has incompatibly declared VALUE a keyword, which can no longer be used as an identifier without quoting.

Workaround in Liquibase

So, your workaround could be to quote all objects (or reserved words, if Liquibase is up to date with H2's latest changes):
https://docs.liquibase.com/parameters/object-quoting-strategy.html

E.g.

databaseChangeLog:
    -  object-quoting-strategy: QUOTE_ALL_OBJECTS

However, this means that you should make sure to use only lower case identifiers in your Liquibase configuration, as to not accidentally create case sensitive identifiers in your PostgreSQL database

Upgrading Liquibase

I can't reproduce this with the latest versions of Liquibase. It seems they have fixed this and now support H2 2.x correctly

A future fix in jOOQ

jOOQ should fix this on the jOOQ side. Eventually, H2 will be removed from the equation (at least it will be possible to opt out of using it), and jOOQ will interpret the DDL generated by Liquibase directly in order to generate your code. The relevant feature request is:
https://github.com/jOOQ/jOOQ/issues/7034

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文