package io.ebean.dbmigration.ddlgeneration.platform; import io.ebean.config.dbplatform.DatabasePlatform; /** * Postgres specific DDL. */ public class PostgresDdl extends PlatformDdl { public PostgresDdl(DatabasePlatform platform) { super(platform); this.historyDdl = new PostgresHistoryDdl(); this.dropTableCascade = " cascade"; this.columnSetType = "type "; this.alterTableIfExists = "if exists "; this.columnSetNull = "drop not null"; } @Override protected String convertArrayType(String logicalArrayType) { int colonPos = logicalArrayType.lastIndexOf(']'); if (colonPos == -1) { return logicalArrayType; } else { // trim of the fallback varchar length return logicalArrayType.substring(0, colonPos + 1); } } /** * Map bigint, integer and smallint into their equivalent serial types. */ @Override public String asIdentityColumn(String columnDefn) { if ("bigint".equalsIgnoreCase(columnDefn)) { return "bigserial"; } if ("integer".equalsIgnoreCase(columnDefn)) { return "serial"; } if ("smallint".equalsIgnoreCase(columnDefn)) { return "smallserial"; } return columnDefn; } }