问题
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