【问题标题】:Grails 3.3.x does not seem to support schema-per-tenant with PostgreSQLGrails 3.3.x 似乎不支持 PostgreSQL 的每租户模式
【发布时间】:2018-05-26 11:16:39
【问题描述】:

有人设法将 Grails 3.3.x 与多租户和 PostgreSQL 一起使用吗?问题似乎与DefaultSchemaHandler.groovy 类中使用的 SQL 语法有关。对于 PostgreSQL,正确的语法是:SET SCHEMA 'schemaName',但 DefaultSchemaHandler 省略了单个刻度:SET SCHEMA schemaName,这会导致启动失败:

Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.postgresql.util.PSQLException: ERROR: syntax error at or near "information_schema"

其他例外情况会列出 PG DB 中的其他模式,直到启动完全失败。似乎没有任何方法可以覆盖 DefaultSchemaHandler,也没有其他人在与这个问题作斗争,这让我感到惊讶。

我应该补充一点,这在我正忙于移植的 Grails 3.2.11 中一切正常。

【问题讨论】:

    标签: postgresql grails grails-orm multi-tenant


    【解决方案1】:

    我通过实现自己的 SchemaHandler 解决了自己的问题,如下所示:

    @CompileStatic
    @Slf4j
    class PostgreSQLSchemaHandler extends DefaultSchemaHandler {
    
        PostgreSQLSchemaHandler() {
            super("SET SCHEMA '%s'", "CREATE SCHEMA '%s'", "public")
        }
    }
    

    然后在 application.yml 我添加schemaHandler 如下:

    dataSource:
        pooled: true
        jmxExport: true
        driverClassName: org.postgresql.Driver
        dialect: org.hibernate.dialect.PostgreSQLDialect
        schemaHandler: com.mypackage.PostgreSQLSchemaHandler
    

    【讨论】:

      猜你喜欢
      • 2021-12-05
      • 2018-03-20
      • 1970-01-01
      • 2018-03-10
      • 2012-06-02
      • 2020-07-17
      • 1970-01-01
      • 2023-03-18
      • 2019-10-26
      相关资源
      最近更新 更多