英文:
Tryiing to force Liquibase to use Postgres mode for H2 in-memory DB
问题
我在生产环境中使用Postgres数据库,所以我想在运行测试时使用H2以Postgres兼容模式,以确保其行为类似。问题是,Liquibase似乎假定它将在本机模式下运行,因此生成H2样式的数据类型以进行更改。
基本上,我正在使用以下JDBC URL设置H2:
jdbc:h2:mem:~/mydb;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE;MVCC=true;
但问题是,Liquibase仍然生成表创建语句,使用"NUMBER"作为数据类型,而不是H2在PostgreSQL模式下期望的"NUMERIC"。如果我从URL中移除"MODE=PostgreSQL",它就可以正常工作,但在我的单元测试中我就无法获得Postgres的行为。
所以,是否有一种方法可以让Liquibase检测数据库为Postgres,或者在使用H2数据库时强制它这样做?
英文:
I'm using a Postgres database in production, so I want to use H2 in Postgres compatibility mode when running tests to ensure it behaves in a similar way. The problem is that Liquibase seems to assume it will be running in a native mode and so generates H2 style datatypes for its changes.
So, basically, I'm setting up H2 with a JDBC URL like this:
jdbc:h2:mem:~/mydb;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE;MVCC=true;
But the problem is that Liquibase still generates table create statements using "NUMBER" as a datatype rather than the "NUMERIC" which H2 expects in PostgreSQL mode. If I remove the "MODE=PostgreSQL" from the URL it works fine - but then I'm not getting Postgres behaviour in my unit tests.
So, is there a way to get Liquibase to detect the database as Postgres, or force it to, when using the H2 database?
答案1
得分: 2
Liquibase目前(3.8.x版本)没有检测H2数据库兼容模式的机制。您可以尝试在changelog中使用预置条件和modifysql指令的组合来实现您想要的功能。
英文:
Liquibase does not currently (3.8.x) have a mechanism for detecting the compatibility mode of an H2 database. You might be able to get Liquibase to do what you want using a combination of preconditions and modifysql instructions in the changelog.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论