【发布时间】:2015-11-11 08:44:30
【问题描述】:
我正在尝试在两个不同的数据库上制作变更日志:MS SQL Server 和 PostgreSQL。更改日志在 SQL Server 上运行良好,但数据库和字段的大小写使其在 PostgreSQL 上中断。我尝试过不在值周围使用引号(这会引发错误)并使用了objectQuotingStategy="QUOTE_ALL_OBJECTS",但两者都不起作用。
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet id="create-PushApplication" author="me">
<createTable tableName="PushApplication">
<column name="ApplicationKey" type="NUMERIC(19,0)" autoIncrement="true" remarks="Unique id of the application">
<constraints primaryKey="true" primaryKeyName="PushApplication_PK" nullable="false" />
</column>
<column name="ApplicationId" type="VARCHAR(100)" remarks="Id of the application in the Push Server">
<constraints unique="true" uniqueConstraintName="PushApplication_U1" nullable="false" />
</column>
<column name="MasterSecret" type="VARCHAR(100)" remarks="Password for the application in the Push Server">
<constraints nullable="false" />
</column>
<column name="Name" type="VARCHAR(100)" remarks="Name of the application">
<constraints nullable="false" />
</column>
<column name="Description" type="VARCHAR(200)" remarks="Description of the application" />
<column name="DateCreated" type="DATETIME" remarks="Date the application was created" />
</createTable>
</changeSet>
<changeSet id="create-PushVariant" author="me">
<createTable tableName="PushVariant">
<column name="VariantKey" type="NUMERIC(19,0)" autoIncrement="true" remarks="Unique id of the variant">
<constraints primaryKey="true" primaryKeyName="PushVariant_PK" nullable="false" />
</column>
<column name="VariantId" type="VARCHAR(100)" remarks="Id of the variant in the Push Server">
<constraints unique="true" uniqueConstraintName="PushVariant_UK1" nullable="false" />
</column>
<column name="Secret" type="VARCHAR(100)" remarks="Password for the variant in the Push Server">
<constraints nullable="false" />
</column>
<column name="Name" type="VARCHAR(100)" remarks="Name of the variant">
<constraints nullable="false" />
</column>
<column name="Description" type="VARCHAR(200)" remarks="Description of the variant" />
<column name="ApplicationKey" type="NUMERIC(19,0)" remarks="Id of the application the variant belogns to">
<constraints nullable="false" foreignKeyName="PushVariant_FK1" references="PushApplication(ApplicationKey)" />
</column>
</createTable>
</changeSet>
</databaseChangeLog>
错误:关系“pushapplication”不存在
在 PostgreSQL 中创建了表“PushApplication”,但是当它尝试创建“PushVariant”时,会为外键抛出此错误。
如果我将所有数据库名称和列名称更改为小写,这将起作用。但是,这会使 SQL Server 的大小写不正确。
目标
目标是在 SQL Server 中拥有“PushVariant”,在 PostgreSQL 中拥有“pushvariant”。
有没有办法让变更日志中的大小写保留在 SQL Server 中,但在 PostgreSQL 中小写?
【问题讨论】:
-
"但是,这会使 SQL Server 的大小写不正确" 小写名称的“不正确”是什么?如果您想在不同的 DBMS 之间保持兼容,您将必须做出一些妥协。无论如何,我个人更喜欢
push_variant而不是PushVariant。与 SQL 标准相比,SQL Server 保持大小写不变的行为与 Postgres 以小写形式编写所有内容的行为一样错误。 SQL 标准要求所有未加引号的标识符都以大写形式存储。 -
@a_horse_with_no_name 使用我们多年的当前架构,我们在 SQL Server 中不使用小写名称。如果它们变成小写,它将与当前设置不匹配。根据您的最后一条评论,我应该将所有内容全部大写吗?
-
啊,好吧。如果我真的想保留这个案例,那么几乎可以创建不同的变更日志。如果我不这样做,请考虑使用下划线。谢谢!如果可以的话,请根据您的 cmets 的要点创建一个答案,我会接受您的答案:-)
-
我为我的答案添加了另一个解决方案。默认行为实际上可以很容易地更改。
标签: sql-server postgresql liquibase