具有多个架构的Liquibase [英] Liquibase with multiple schemas

查看:78
本文介绍了具有多个架构的Liquibase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用多个架构的软件.我制作了db.changelog-master.xml来维护不同的发行版,并制作了db.changelog-S16.xml到当前的sprint(当前是sprint 16). db.changelog-S16.xml看起来像这样:

I have a software wich uses multiple schemas. I made db.changelog-master.xml to maintain different releases and db.changelog-S16.xml to current sprint (it's currently sprint 16 going on). db.changelog-S16.xml is looking like this:

<?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">

  <include file="my_schema_1.xml" relativeToChangelogFile="true" /> 
</databaseChangeLog>

这里的问题是,我想制作一个可以将所有架构更新为一个的变更日志,但是我没有找到在变更日志中对架构名称进行硬编码的方法.是否可以以某种方式通过generateChangelog将其获取到变更日志中(因此,模式名称将位于my_schema_1.xml中),或者可以将其键入变更日志中?我正在寻找的将是这样的:

Problem here is, that I want to make one changelog which could update all the schemas in one but I have failed to find a way to hardcode the schemaname in the changelog. Can it be obtained to the changelog via generateChangelog somehow (so the schemanames would be in my_schema_1.xml), or can I type it to the changelog? What I am looking for would be like this:

 <?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">

    <TAG WHERE I COULD INSERT SCHEMANAME>
  <include file="my_schema_1.xml" relativeToChangelogFile="true" /> 
      <TAG WHERE I COULD INSERT SCHEMANAME>
    <include file="my_schema_2.xml" relativeToChangelogFile="true" />
       etc...
</databaseChangeLog>

因为现在只有从命令行运行liquibase时,才有可能在update子句中更改架构.当我将客户数据库建立到他们的服务器上时,这也将很方便.我可以只制作customer_master.xml并在其中硬编码其模式名,然后从头开始将其运行到他们的服务器.到目前为止,我发现插入模式名称的唯一地方是在进行命令行调用时.那意味着我将不得不以不同的方式更新每个架构,或者制作一些powershell脚本来为我做这些...

Because now it is only possibly to change schema in the update clause when running the liquibase from the commandline. This would be handy too when I am making customer databases to their servers. I could just make customer_master.xml and hardcode their schemanames in it and then run it to their server from the scratch. So far only place I have found to insert schema name is when you make the commandline call. That would mean that I would have to update each schema differently or make some powershell script to do them for me...

推荐答案

大多数更改标记具有"schemaName"属性,可用于指定架构.例如,<createTable tableName="person" schemaName="customer">

Most change tags have a "schemaName" attribute that you can use to specify the schema. For example, <createTable tableName="person" schemaName="customer">

如果您的模式总是被命名为相同的名称,则可以将它们直接硬编码到change标记中.如果它们从部署更改为正式,则可能要使用changelog参数,以便可以使用<createTable tableName="person" schemaName="${primarySchema}">,然后指定在运行时等于什么primarySchema.

If your schemas are always named the same, you can hard code them directly into the change tags. If they change from deploy to deply, you probably want to use changelog parameters so you can use <createTable tableName="person" schemaName="${primarySchema}"> and then specify what primarySchema is equal to at runtime.

您将需要在每个changeSet上指定schemaName,否则它将使用默认的schemaName,该默认的schemaName不能在脚本中进行部分更改.

You will need to specify the schemaName on each changeSet, otherwise it will use the default schemaName which cannot be changed part way through the script.

这篇关于具有多个架构的Liquibase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆