import java.util.List;
import org.apache.commons.dbutils.DbUtils;
import org.sonar.db.Database;
+import org.sonar.db.dialect.Dialect;
import static java.lang.String.*;
import static java.util.Arrays.asList;
return db;
}
+ protected Dialect getDialect() {
+ return db.getDialect();
+ }
+
public static class Context {
private final Connection writeConnection;
*/
public class AddIssuesColumns extends DdlChange {
- private final Database db;
-
public AddIssuesColumns(Database db) {
super(db);
- this.db = db;
}
@Override
}
private String generateSql() {
- return new AddColumnsBuilder(db.getDialect(), "issues")
+ return new AddColumnsBuilder(getDialect(), "issues")
.addColumn(newBigDecimalColumnDefBuilder().setColumnName("issue_creation_date_ms").setIsNullable(true).build())
.addColumn(newBigDecimalColumnDefBuilder().setColumnName("issue_update_date_ms").setIsNullable(true).build())
.addColumn(newBigDecimalColumnDefBuilder().setColumnName("issue_close_date_ms").setIsNullable(true).build())
*/
public class DropIssuesColumns extends DdlChange {
- private final Database db;
-
public DropIssuesColumns(Database db) {
super(db);
- this.db = db;
}
@Override
@VisibleForTesting
String generateSql() {
- return new DropColumnsBuilder(db.getDialect(), "issues",
+ return new DropColumnsBuilder(getDialect(), "issues",
"issue_creation_date", "issue_update_date", "issue_close_date", "component_id", "root_component_id")
.build();
}
}
private String generateSql() {
- return new AddColumnsBuilder(getDatabase().getDialect(), "manual_measures")
+ return new AddColumnsBuilder(getDialect(), "manual_measures")
.addColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(50).setIsNullable(true).build())
.build();
}
}
private List<String> generateSql(String table, String... columns) {
- AlterColumnsTypeBuilder columnsBuilder = new AlterColumnsTypeBuilder(getDatabase().getDialect(), table);
+ AlterColumnsTypeBuilder columnsBuilder = new AlterColumnsTypeBuilder(getDialect(), table);
for (String column : columns) {
columnsBuilder.updateColumn(newDecimalColumnDefBuilder().setColumnName(column).build());
}
*/
public class AddUsersIdentityColumns extends DdlChange {
- private final Database db;
-
public AddUsersIdentityColumns(Database db) {
super(db);
- this.db = db;
}
@Override
}
private String generateSql() {
- return new AddColumnsBuilder(db.getDialect(), "users")
+ return new AddColumnsBuilder(getDialect(), "users")
.addColumn(newVarcharColumnDefBuilder().setColumnName("external_identity").setLimit(255).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("external_identity_provider").setLimit(100).setIsNullable(true).build())
.build();
*/
public class IncreaseProjectsNameColumnsSize extends DdlChange {
- private final Database db;
-
public IncreaseProjectsNameColumnsSize(Database db) {
super(db);
- this.db = db;
}
@Override
}
private List<String> generateSql() {
- return new AlterColumnsTypeBuilder(db.getDialect(), "projects")
+ return new AlterColumnsTypeBuilder(getDialect(), "projects")
.updateColumn(newVarcharColumnDefBuilder().setColumnName("name").setLimit(2000).setIsNullable(true).build())
.updateColumn(newVarcharColumnDefBuilder().setColumnName("long_name").setLimit(2000).setIsNullable(true).build())
.build();
*/
public class AddActiveRulesLongDateColumns extends DdlChange {
- private final Database db;
-
public AddActiveRulesLongDateColumns(Database db) {
super(db);
- this.db = db;
}
@Override
}
private String generateSql() {
- return new AddColumnsBuilder(db.getDialect(), "active_rules")
+ return new AddColumnsBuilder(getDialect(), "active_rules")
.addColumn(newBigDecimalColumnDefBuilder().setColumnName("created_at_ms").setIsNullable(true).build())
.addColumn(newBigDecimalColumnDefBuilder().setColumnName("updated_at_ms").setIsNullable(true).build())
.build();
public class AddIssuesType extends DdlChange {
- private final Database db;
-
public AddIssuesType(Database db) {
super(db);
- this.db = db;
}
@Override
}
private String generateSql() {
- return new AddColumnsBuilder(db.getDialect(), "issues")
+ return new AddColumnsBuilder(getDialect(), "issues")
.addColumn(new TinyIntColumnDef.Builder().setColumnName("issue_type").setIsNullable(true).build())
.build();
}
*/
public class AddRulesColumns extends DdlChange {
- private final Database db;
-
public AddRulesColumns(Database db) {
super(db);
- this.db = db;
}
@Override
}
private String generateSql() {
- return new AddColumnsBuilder(db.getDialect(), "rules")
+ return new AddColumnsBuilder(getDialect(), "rules")
.addColumn(newBigDecimalColumnDefBuilder().setColumnName("created_at_ms").setIsNullable(true).build())
.addColumn(newBigDecimalColumnDefBuilder().setColumnName("updated_at_ms").setIsNullable(true).build())
.addColumn(new TinyIntColumnDef.Builder().setColumnName("rule_type").setIsNullable(true).build())
*/
public class DropActiveRulesDateColumns extends DdlChange {
- private final Database db;
-
public DropActiveRulesDateColumns(Database db) {
super(db);
- this.db = db;
}
@Override
@VisibleForTesting
String generateSql() {
- return new DropColumnsBuilder(db.getDialect(), "active_rules",
+ return new DropColumnsBuilder(getDialect(), "active_rules",
"created_at", "updated_at")
.build();
}
*/
public class DropRulesDatesAndCharacteristics extends DdlChange {
- private final Database db;
-
public DropRulesDatesAndCharacteristics(Database db) {
super(db);
- this.db = db;
}
@Override
@VisibleForTesting
String generateSql() {
- return new DropColumnsBuilder(db.getDialect(), "rules",
+ return new DropColumnsBuilder(getDialect(), "rules",
"created_at", "updated_at", "characteristic_id", "default_characteristic_id")
.build();
}
@Override
public void execute(Context context) throws SQLException {
- if (getDatabase().getDialect().getId().equals(Oracle.ID)) {
+ if (getDialect().getId().equals(Oracle.ID)) {
// in order to not depend on value of variable NLS_LENGTH_SEMANTICS, unit of length
// is enforced to CHAR so that we're sure that type can't be 4000 BYTE.
context.execute("ALTER TABLE issues MODIFY (message VARCHAR (4000 CHAR))");
// In SQ 5.5, migration 1100 create columns with type TINYINT(1) instead of TINYINT(2)
// In SQ 5.4 and lower, the type TINYINT(1) was used only for boolean columns, so no problem
// As an optimization fix must be applied only for instances upgrading from 5.5.x
- if (getDatabase().getDialect().getId().equals(MySql.ID) &&
+ if (getDialect().getId().equals(MySql.ID) &&
dbVersion.getInitialDbVersion() >= SQ_5_5 && dbVersion.getInitialDbVersion() < SQ_5_6) {
Loggers.get(getClass()).info("Changing TINYINT(1) to TINYINT(2)");
context.execute("ALTER TABLE rules MODIFY COLUMN rule_type TINYINT (2)");
private static final String TABLE_RESOURCE_INDEX = "resource_index";
- private final Database db;
-
public AddUuidColumnsToResourceIndex(Database db) {
super(db);
- this.db = db;
}
@Override
public void execute(Context context) throws SQLException {
- context.execute(new AddColumnsBuilder(db.getDialect(), TABLE_RESOURCE_INDEX)
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE_RESOURCE_INDEX)
.addColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("root_component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(true).build())
.build());
private static final String TABLE_RESOURCE_INDEX = "resource_index";
- private final Database db;
-
public DropIdColumnsFromResourceIndex(Database db) {
super(db);
- this.db = db;
}
@Override
public void execute(Context context) throws SQLException {
context.execute(
new DropColumnsBuilder(
- db.getDialect(), TABLE_RESOURCE_INDEX,
+ getDialect(), TABLE_RESOURCE_INDEX,
"resource_id", "root_project_id")
.build());
}
private static final String TABLE_RESOURCE_INDEX = "resource_index";
- private final Database db;
-
public MakeUuidColumnsNotNullOnResourceIndex(Database db) {
super(db);
- this.db = db;
}
@Override
public void execute(Context context) throws SQLException {
- context.execute(new AlterColumnsTypeBuilder(db.getDialect(), TABLE_RESOURCE_INDEX)
+ context.execute(new AlterColumnsTypeBuilder(getDialect(), TABLE_RESOURCE_INDEX)
.updateColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build())
.updateColumn(newVarcharColumnDefBuilder().setColumnName("root_component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build())
.build());