使用 liquibase 将 postgres 表复制到另一个架构

pho*_*Sid 2 database postgresql liquibase

我想将一组表从一个模式复制到同一数据库上的另一个模式。我在 Ubuntu 上使用 postgres v9,并使用 Liquibase 对数据库进行任何更改。

我可以使用类似于下面的代码创建新表,但我需要将新表创建为select * from another table

<changeSet author="jDoe" id="1">
    <createTable tableName="abcproxy">
        <column name="errtime" type="datetime">
            <constraints primaryKey="true" nullable="false"/>
        </column>
        <column name="errmsg" type="varchar(255)">
            <constraints nullable="false"/>
        </column>
        <column name="version" type="integer">
            <constraints nullable="false"/>
        </column>
    </createTable>
Run Code Online (Sandbox Code Playgroud)

我知道我们可以通过此处提到的 sql 来完成此操作,但我想通过 Liquibase XML 配置来完成此操作。另外,如果我们可以使用 liquibase 配置复制授权/权限,那就太好了。

我可以尝试按照此处提到的方式移动表格,但到目前为止,我的要求是复制而不是移动表格。

请让我知道实现相同目标的任何建议。谢谢。

hts*_*ame 5

您可以在您的 中使用sql标签changeSet,例如:

<changeSet author="jDoe" id="1">
    <precondition onFail="MARK_RUN">
        <not>
            <tableExists tableName="abcproxy" schemaName="newSchema"/>
        </not>
    </precondition>
    <sql>create table newSchema.abcproxy as select * from oldSchema.abcproxy</sql>
</changeSet>
Run Code Online (Sandbox Code Playgroud)

但是,这种方法存在一个问题:这changeSet将从旧架构中的表中复制所有数据,但不会复制键。