Skip to content
This repository has been archived by the owner on Jul 2, 2022. It is now read-only.

Fix AUTOINCREMENT #101

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public SnowflakeDatabase() {
super.unmodifiableDataTypes.addAll(Arrays.asList("integer", "bool", "boolean", "int4", "int8", "float4", "float8", "numeric", "bigserial", "serial", "bytea", "timestamptz"));
super.unquotedObjectsAreUppercased = false;
super.addReservedWords(getDefaultReservedWords());
super.defaultAutoIncrementStartWith = BigInteger.ONE;
super.defaultAutoIncrementBy = BigInteger.ONE;
}

@Override
Expand Down Expand Up @@ -137,21 +139,22 @@ public boolean supportsTablespaces() {
return false;
}

public String getAutoIncrementClause(BigInteger startWith, BigInteger incrementBy) {
if (startWith != null && incrementBy != null) {
return " AUTOINCREMENT(" + startWith + "," + incrementBy + ") ";
}
return " AUTOINCREMENT ";
}

@Override
public boolean supportsAutoIncrement() {
return true;
}

@Override
public String getAutoIncrementClause() {
return "";
return "AUTOINCREMENT";
}

protected String getAutoIncrementStartWithClause() {
return "%d";
}

protected String getAutoIncrementByClause() {
return "%d";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package liquibase.ext.snowflake.database;

import liquibase.database.AbstractJdbcDatabase;
import liquibase.database.Database;
import liquibase.ext.snowflake.helpers.SetUtils;
import liquibase.CatalogAndSchema;
import liquibase.database.jvm.JdbcConnection;
Expand Down Expand Up @@ -137,9 +139,13 @@ public void testSupportsAutoIncrementClause() {

@Test
public void testGetAutoIncrementClause() {
assertEquals("", database.getAutoIncrementClause());
assertEquals(" AUTOINCREMENT ", database.getAutoIncrementClause(null, null));
assertEquals(" AUTOINCREMENT(1,1) ", database.getAutoIncrementClause(new BigInteger("1"), new BigInteger("1")));
assertEquals("AUTOINCREMENT", database.getAutoIncrementClause());
assertEquals("AUTOINCREMENT (1, 1)", database.getAutoIncrementClause(null, null, null, null));
assertEquals("AUTOINCREMENT (1, 1)", database.getAutoIncrementClause(new BigInteger("1"), new BigInteger("1"), null, null));
assertEquals("AUTOINCREMENT (7, 1)", database.getAutoIncrementClause(new BigInteger("7"), new BigInteger("1"), null, null));
assertEquals("AUTOINCREMENT (1, 7)", database.getAutoIncrementClause(new BigInteger("1"), new BigInteger("7"), null, null));
assertEquals("AUTOINCREMENT (7, 1)", database.getAutoIncrementClause(new BigInteger("7"), null, null, null));
assertEquals("AUTOINCREMENT (1, 7)", database.getAutoIncrementClause(null, new BigInteger("7"), null, null));
}

@Test
Expand Down Expand Up @@ -217,4 +223,4 @@ public void jdbcSchemaNameIsNullWhenCatalogAndSchemaAreNull() {
assertNull(database.getJdbcSchemaName(new CatalogAndSchema(null, null)));
}

}
}