How do I differentiate between databases when using e.g. sequence

隐身守侯 提交于 2019-12-11 02:42:56

问题


I just started using Liquibase and stumpled upon the problem to differentiate between the capabilities of different databases.

We would like to support multiple databases (Oracle, MySQL, Derby - to name three).

The all have different capabilities. In specific Oracle supports sequences whereas MySQL and Derby do not.

When I let hibernate generate the DDL I can choose different dialects and it will consider these different capabilities and generate a Sequencer when using Oracle and use a plain table (for ID-generation) when using Derby or MySQL.

Now, I know I can constraint changesets by specifying 'oracle' in the dbms attribute. But then how can I do the plain table solution for the other databases? There does not seem to be a 'not oracle' attribute for dbms.

How does anyone else handle this? (I could not find anything about it on the liquibase pages nor on the forum.)


回答1:


Try using a precondition on the changset. Boolean operations are supported.

For example

 <preConditions onFail="CONTINUE">
     <or>
         <dbms type="oracle" />
         <dbms type="mysql" />
     </or>
 </preConditions>



回答2:


An alternative approach is to put all your sequences in a changlog file which you include in your main changelog, and then do something like this:

<changeSet
    dbms="oracle,db2,db2i"
    author="mccallim (generated)"
    id="1419011907193-1"
>
    <createSequence
        schemaName="${main.schema}"
...

That changeset only gets executed for the DBMSs listed.



来源:https://stackoverflow.com/questions/11246009/how-do-i-differentiate-between-databases-when-using-e-g-sequence

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!