Auto-Increment Precondition

Some of my databases have an auto-increment on the id column of my log table, while others don’t. As I need this auto-increment on all of my databases, I created a changeSet like this:

  1.    
  2.         <addAutoIncrement columnDataType="int"
  3.                 columnName="id"
  4.                 incrementBy="1"
  5.                 startWith="1"
  6.                 tableName="log"/>
  7.    

However, this fails when I run it on my databases that already have this auto-increment.

I’d like something like this:

  1.    
  2.        
  3.                  
  4.                         <autoIncrementExists columnName="id"
  5.                               tableName="log"/>
  6.                  
  7.        
  8.         <addAutoIncrement columnDataType="int"
  9.                 columnName="id"
  10.                 incrementBy="1"
  11.                 startWith="1"
  12.                 tableName="log"/>
  13.    

Is this possible in any way?

PS: If you’re wondering why I ended up with this inconsistency on my databases, it’s because MySQL deletes the auto-increment when you change a column type, while PostgreSQL doesn’t.

There is no built-in autoIncrementExists or similar precondition. Your best option is probably to find the correct SQL and use a precondition. 

Or use failOnError=“false” in the tag and just ignore the error. That tends to be a bit more dangerous, though, since you don’t know the actual error that is being skipped.

Nathan