001package io.ebeaninternal.dbmigration.ddlgeneration.platform; 002 003import java.util.ArrayList; 004import java.util.List; 005 006import io.ebean.config.dbplatform.DatabasePlatform; 007import io.ebeaninternal.dbmigration.ddlgeneration.DdlAlterTable; 008import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer; 009import io.ebeaninternal.dbmigration.ddlgeneration.DdlOptions; 010import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite; 011 012/** 013 * SQLite platform specific DDL. 014 * 015 * Note: SQLite has very limited alter capabilities. Altering a column is not 016 * supported and may need a recreation of the whole table 017 */ 018public class SQLiteDdl extends PlatformDdl { 019 020 public SQLiteDdl(DatabasePlatform platform) { 021 super(platform); 022 this.identitySuffix = ""; 023 this.inlineForeignKeys = true; 024 } 025 026 @Override 027 public void addTableComment(DdlBuffer apply, String tableName, String tableComment) { 028 // not supported 029 } 030 031 @Override 032 public void addColumnComment(DdlBuffer apply, String table, String column, String comment) { 033 // not supported 034 } 035 036 @Override 037 public String alterTableAddForeignKey(DdlOptions options, WriteForeignKey request) { 038 return "-- not supported: " + super.alterTableAddForeignKey(options, request); 039 } 040 041 @Override 042 public String alterTableDropForeignKey(String tableName, String fkName) { 043 return "-- not supported: " + super.alterTableDropForeignKey(tableName, fkName); 044 } 045 046 @Override 047 public String alterTableAddCheckConstraint(String tableName, String checkConstraintName, String checkConstraint) { 048 return "-- not supported: " + super.alterTableAddCheckConstraint(tableName, checkConstraintName, checkConstraint); 049 } 050 051 @Override 052 public String alterTableDropConstraint(String tableName, String constraintName) { 053 return "-- not supported: " + super.alterTableDropConstraint(tableName, constraintName); 054 } 055 056 @Override 057 public String alterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, String[] nullableColumns) { 058 return "-- not supported: " + super.alterTableAddUniqueConstraint(tableName, uqName, columns, nullableColumns); 059 } 060 061 @Override 062 public String alterTableDropUniqueConstraint(String tableName, String uniqueConstraintName) { 063 return "-- not supported: " + super.alterTableDropUniqueConstraint(tableName, uniqueConstraintName); 064 } 065 066 @Override 067 protected DdlAlterTable alterTable(DdlWrite writer, String tableName) { 068 return writer.applyAlterTable(tableName, SQLiteAlterTableWrite::new); 069 } 070 071 class SQLiteAlterTableWrite extends BaseAlterTableWrite { 072 public SQLiteAlterTableWrite(String tableName) { 073 super(tableName, SQLiteDdl.this); 074 } 075 076 @Override 077 protected List<AlterCmd> postProcessCommands(List<AlterCmd> cmds) { 078 List<AlterCmd> ret = new ArrayList<AlterCmd>(); 079 for (AlterCmd cmd : cmds) { 080 switch (cmd.getOperation()) { 081 case "alter column": 082 ret.add(newRawCommand("-- not supported: " + cmd)); 083 break; 084 default: 085 ret.add(cmd); 086 } 087 } 088 return ret; 089 } 090 } 091}