Skip to content

Commit

Permalink
0003481: Postgres create tables with an auto increment column create
Browse files Browse the repository at this point in the history
sequence without respect to schema
  • Loading branch information
jumpmind-josh committed Mar 8, 2018
1 parent 37cc322 commit 8939fa7
Showing 1 changed file with 13 additions and 0 deletions.
Expand Up @@ -23,6 +23,7 @@
import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.jumpmind.db.alter.AddColumnChange;
import org.jumpmind.db.alter.ColumnAutoIncrementChange;
import org.jumpmind.db.alter.ColumnDataTypeChange;
Expand Down Expand Up @@ -195,6 +196,10 @@ private void createAutoIncrementSequence(Table table, Column column, StringBuild
println("$$ LANGUAGE plpgsql; ", ddl);
} else {
ddl.append("CREATE SEQUENCE ");
if (StringUtils.isNotBlank(table.getSchema())) {
printIdentifier(table.getSchema(), ddl);
ddl.append(".");
}
printIdentifier(getConstraintName(null, table, column.getName(), "seq"), ddl);
printEndOfStatement(ddl);
}
Expand All @@ -219,6 +224,10 @@ private void dropAutoIncrementSequence(Table table, Column column, StringBuilder
printEndOfStatement(ddl);
} else {
ddl.append("DROP SEQUENCE ");
if (StringUtils.isNotBlank(table.getSchema())) {
printIdentifier(table.getSchema(), ddl);
ddl.append(".");
}
printIdentifier(getConstraintName(null, table, column.getName(), "seq"), ddl);
printEndOfStatement(ddl);
}
Expand All @@ -232,6 +241,10 @@ protected void writeColumnAutoIncrementStmt(Table table, Column column, StringBu
ddl.append("()");
} else {
ddl.append(" DEFAULT nextval('");
if (StringUtils.isNotBlank(table.getSchema())) {
printIdentifier(table.getSchema(), ddl);
ddl.append(".");
}
printIdentifier(getConstraintName(null, table, column.getName(), "seq"), ddl);
ddl.append("')");
}
Expand Down

0 comments on commit 8939fa7

Please sign in to comment.