在postgres中使用liquibase制作不区分大小写的表
有没有人知道如何使用 liquibase 制作不区分大小写的表格。我正在使用最新的 postgres。 例如 liquibase 以这种方式创建表:
create table "Users" ( "userId" integer unique not null, "userFirstName" varchar(50) not null, "userLastName" varchar(50) not null );
但如何让 liquibase 以这种方式创建表:
create table Users ( userId integer unique not null, userFirstName varchar(50) not null, userLastName varchar(50) not null );
Does anybady know how to make case insensitive table with liquibase. I'm using the newest postgres.
For example liquibase creates table in that way:
create table "Users" ( "userId" integer unique not null, "userFirstName" varchar(50) not null, "userLastName" varchar(50) not null );
but how to make liquibase to create table in that way:
create table Users ( userId integer unique not null, userFirstName varchar(50) not null, userLastName varchar(50) not null );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 liquibase 没有生成您想要的内容,您始终可以使用该标签来指定您想要执行的确切 SQL。
默认的 postgres 支持始终在表名和列名周围使用引号,因此使用保留字作为对象名不会出现问题。您可以通过创建自己的 liquibase.database.core.PostgresDatabase 子类并让 liquibase 使用您的类来覆盖它。有一个 escapeDatabaseObject(String) 方法,该方法传入原始字符串并返回带引号的值。您只需要重写此方法即可返回原样的原始字符串。
您如何使用数据库取决于您的 liquibase 版本。如果您使用的是即将发布的 2.0 版本的快照 (http://liquibase.org/ci/latest),您只需将您的类保存在 liquibase.database.ext 包中即可。如果您使用的是 1.9,则应该有一个 databaseClassName 参数,您可以使用它来告诉 liquibase 您的类。
You can always use the tag to specify the exact SQL you want executed if liquibase is not generating what you want.
The default postgres support uses quotes around table and column names all the time so there will not be problems with using reserved words as object names. You can override this by creating your own liquibase.database.core.PostgresDatabase subclass and having liquibase use your class instead. There is an escapeDatabaseObject(String) method that is passed in the original string and returns the quoted value. You would just need to override this method to return the original string untouched.
How you use your database depends on your version of liquibase. If you are using a snapshot of the upcoming 2.0 release (http://liquibase.org/ci/latest), you simply need to keep your class in a liquibase.database.ext package. If you are using 1.9, there should be a databaseClassName parameter you can use to tell liquibase about your class.
从 Liquibase 3.0 开始,
databaseChangeLog
有一个属性objectQuotingStrategy
。默认值为 LEGACY ,但可以更改为 QUOTE_ONLY_RESERVED_WORDS ,这通常会使 PostgreSQL 的更改日志变得不区分大小写:该属性也可用于特定的 ChangeSet< /code>,但我不确定,因为它可能会更改更改集的校验和。您还可以将其与 YAML 配置
关于 PostgreSQL 区分大小写。
Since Liquibase 3.0 there is an attribute
objectQuotingStrategy
for thedatabaseChangeLog
. The default isLEGACY
but it can be changed toQUOTE_ONLY_RESERVED_WORDS
which mostly turns a changelog to become case insensitive for PostgreSQL:The attribute is also available for a particular
changeSet
, but I am not sure as it may change the checksum of the change set. You can also use it with YAML config of course.The PostgreSQL behaviour is explained in About PostgreSQL Case Sensitivity.