1 | |
package liquibase.sqlgenerator.core; |
2 | |
|
3 | |
import liquibase.database.Database; |
4 | |
import liquibase.database.core.MySQLDatabase; |
5 | |
import liquibase.database.core.OracleDatabase; |
6 | |
import liquibase.database.core.PostgresDatabase; |
7 | |
import liquibase.exception.ValidationErrors; |
8 | |
import liquibase.sql.Sql; |
9 | |
import liquibase.sql.UnparsedSql; |
10 | |
import liquibase.sqlgenerator.SqlGenerator; |
11 | |
import liquibase.sqlgenerator.SqlGeneratorChain; |
12 | |
import liquibase.statement.core.SetTableRemarksStatement; |
13 | |
|
14 | 13 | public class SetTableRemarksGenerator extends AbstractSqlGenerator<SetTableRemarksStatement> { |
15 | |
|
16 | |
@Override |
17 | |
public boolean supports(SetTableRemarksStatement statement, Database database) { |
18 | 3 | return database instanceof MySQLDatabase || database instanceof OracleDatabase |
19 | |
|| database instanceof PostgresDatabase; |
20 | |
} |
21 | |
|
22 | |
public ValidationErrors validate(SetTableRemarksStatement setTableRemarksStatement, Database database, |
23 | |
SqlGeneratorChain sqlGeneratorChain) { |
24 | 0 | ValidationErrors validationErrors = new ValidationErrors(); |
25 | 0 | validationErrors.checkRequiredField("tableName", setTableRemarksStatement.getTableName()); |
26 | 0 | validationErrors.checkRequiredField("remarks", setTableRemarksStatement.getRemarks()); |
27 | 0 | return validationErrors; |
28 | |
} |
29 | |
|
30 | |
public Sql[] generateSql(SetTableRemarksStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { |
31 | |
String sql; |
32 | 0 | String remarks = database.escapeStringForDatabase(statement.getRemarks()); |
33 | 0 | if (database instanceof MySQLDatabase) { |
34 | 0 | sql = "ALTER TABLE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName()) |
35 | |
+ " COMMENT = '" + remarks + "'"; |
36 | |
} else { |
37 | 0 | sql = "COMMENT ON TABLE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName()) |
38 | |
+ " IS '" + remarks + "'"; |
39 | |
} |
40 | |
|
41 | 0 | return new Sql[] { new UnparsedSql(sql) }; |
42 | |
} |
43 | |
} |