1 package liquibase.sqlgenerator.core; 2 3 import liquibase.database.Database; 4 import liquibase.database.core.PostgresDatabase; 5 import liquibase.exception.ValidationErrors; 6 import liquibase.sql.Sql; 7 import liquibase.sql.UnparsedSql; 8 import liquibase.sqlgenerator.SqlGenerator; 9 import liquibase.sqlgenerator.SqlGeneratorChain; 10 import liquibase.statement.core.DropSequenceStatement; 11 12 public class DropSequenceGenerator extends AbstractSqlGenerator<DropSequenceStatement> { 13 14 @Override 15 public boolean supports(DropSequenceStatement statement, Database database) { 16 return database.supportsSequences(); 17 } 18 19 public ValidationErrors validate(DropSequenceStatement dropSequenceStatement, Database database, 20 SqlGeneratorChain sqlGeneratorChain) { 21 ValidationErrors validationErrors = new ValidationErrors(); 22 validationErrors.checkRequiredField("sequenceName", dropSequenceStatement.getSequenceName()); 23 return validationErrors; 24 } 25 26 public Sql[] generateSql(DropSequenceStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { 27 String sql = "DROP SEQUENCE " 28 + database.escapeSequenceName(statement.getSchemaName(), statement.getSequenceName()); 29 if (database instanceof PostgresDatabase) { 30 sql += " CASCADE"; 31 } 32 33 return new Sql[] { new UnparsedSql(sql) }; 34 } 35 }