Skip to content

Commit

Permalink
Fixed #3722 auto-increment column starting with a custom value no lon…
Browse files Browse the repository at this point in the history
…ger works with H2 v1 (#4013)

* Fixed #3722 auto-increment column starting with a custom value no longer works with H2 v1

* Add auto-increment with custom value changeset to validate H2 auto-increment fix.

---------

Co-authored-by: Daniel Mallorga <dmallorga@liquibase.com>
  • Loading branch information
fengjiansheng and MalloD12 committed May 3, 2023
1 parent ab98dae commit 8fc5ccc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Expand Up @@ -403,5 +403,11 @@
<preConditions onFail="MARK_RAN"><tableExists tableName="NOT_EXISTENT_TABLE"/></preConditions>
<dropTable tableName="NOT_EXISTENT_TABLE_DOESNT_MATTER"/>
</changeSet>
<changeSet id="addAutoIncrementColumnWithCustomValue" author="mallod">
<createTable tableName="autoIncrementColumnStartingWithCustomValueTest">
<column name="id" type="BIGINT" autoIncrement="true" startWith="100"/>
<column name="name" type="int"/>
</createTable>
</changeSet>

</databaseChangeLog>
Expand Up @@ -304,6 +304,32 @@ protected String getAutoIncrementClause() {
}
}

@Override
protected String getAutoIncrementStartWithClause() {
try {
if (getDatabaseMajorVersion() == 1) {
return "%d";
} else {
return super.getAutoIncrementStartWithClause();
}
} catch (DatabaseException e) {
return "%d";
}
}

@Override
protected String getAutoIncrementByClause() {
try {
if (getDatabaseMajorVersion() == 1) {
return "%d";
} else {
return super.getAutoIncrementByClause();
}
} catch (DatabaseException e) {
return "%d";
}
}

@Override
public String getAutoIncrementClause(BigInteger startWith, BigInteger incrementBy, String generationType, Boolean defaultOnNull) {
final String clause = super.getAutoIncrementClause(startWith, incrementBy, generationType, defaultOnNull);
Expand Down

0 comments on commit 8fc5ccc

Please sign in to comment.