"LOCATIONS" BINARY LARGE OBJECT,
"ISSUE_TYPE" TINYINT,
"FROM_HOTSPOT" BOOLEAN,
- "QUICK_FIX_AVAILABLE" BOOLEAN
+ "QUICK_FIX_AVAILABLE" BOOLEAN,
+ "RULE_DESCRIPTION_CONTEXT_KEY" CHARACTER VARYING(50)
);
ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE" NULLS FIRST);
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
import static org.sonar.server.platform.db.migration.version.v95.CreateRuleDescSectionsTable.RULE_DESCRIPTION_SECTIONS_TABLE;
+import static org.sonar.server.platform.db.migration.version.v96.DbConstants.CONTEXT_KEY_COLUMNS_SIZE;
public class AddContextColumnsToRuleDescSectionsTable extends DdlChange {
}
private void createContextKeyColumn(Context context, Connection connection) {
- VarcharColumnDef contextKeyColumn = newVarcharColumnDefBuilder().setColumnName(COLUMN_CONTEXT_KEY).setIsNullable(true).setLimit(50).build();
+ VarcharColumnDef contextKeyColumn = newVarcharColumnDefBuilder().setColumnName(COLUMN_CONTEXT_KEY).setIsNullable(true).setLimit(CONTEXT_KEY_COLUMNS_SIZE).build();
createColumnIfNotExists(context, connection, contextKeyColumn);
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v96;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.version.v96.DbConstants.CONTEXT_KEY_COLUMNS_SIZE;
+
+public class AddRuleDescriptionContextKeyInIssuesTable extends DdlChange {
+
+ @VisibleForTesting
+ static final String ISSUES_TABLE_NAME = "issues";
+ @VisibleForTesting
+ static final String RULE_DESCRIPTION_CONTEXT_KEY_COLUMN_NAME = "rule_description_context_key";
+
+ private static final VarcharColumnDef columnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName(RULE_DESCRIPTION_CONTEXT_KEY_COLUMN_NAME)
+ .setLimit(CONTEXT_KEY_COLUMNS_SIZE)
+ .setIsNullable(true)
+ .build();
+
+ public AddRuleDescriptionContextKeyInIssuesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ try (Connection c = getDatabase().getDataSource().getConnection()) {
+ if (!DatabaseUtils.tableColumnExists(c, ISSUES_TABLE_NAME, RULE_DESCRIPTION_CONTEXT_KEY_COLUMN_NAME)) {
+ context.execute(new AddColumnsBuilder(getDialect(), ISSUES_TABLE_NAME)
+ .addColumn(columnDefinition)
+ .build());
+ }
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v96;
+
+class DbConstants {
+ static final int CONTEXT_KEY_COLUMNS_SIZE = 50;
+
+ private DbConstants() {
+ throw new IllegalStateException("This class must not be instantiated");
+ }
+}
.add(6502, "Drop unique index uniq_rule_desc_sections_kee", DropIndexForRuleDescSection.class)
.add(6503, "Create unique uniq_rule_desc_sections", CreateIndexForRuleDescSections.class)
.add(6504, "Add column 'expiration_date' to 'user_tokens'", AddExpirationDateColumnToUserTokens.class)
+ .add(6505, "Add column 'rule_description_context_key' to 'issues'", AddRuleDescriptionContextKeyInIssuesTable.class)
;
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v96;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static org.sonar.db.CoreDbTester.createForSchema;
+import static org.sonar.server.platform.db.migration.version.v96.AddRuleDescriptionContextKeyInIssuesTable.ISSUES_TABLE_NAME;
+import static org.sonar.server.platform.db.migration.version.v96.AddRuleDescriptionContextKeyInIssuesTable.RULE_DESCRIPTION_CONTEXT_KEY_COLUMN_NAME;
+
+public class AddRuleDescriptionContextKeyInIssuesTableTest {
+
+ @Rule
+ public final CoreDbTester db = createForSchema(AddRuleDescriptionContextKeyInIssuesTableTest.class, "schema.sql");
+
+ private final AddRuleDescriptionContextKeyInIssuesTable addRuleDescriptionContextKeyInIssuesTable = new AddRuleDescriptionContextKeyInIssuesTable(db.database());
+
+ @Test
+ public void column_rule_description_context_key_should_be_added() throws SQLException {
+ db.assertColumnDoesNotExist(ISSUES_TABLE_NAME, RULE_DESCRIPTION_CONTEXT_KEY_COLUMN_NAME);
+
+ addRuleDescriptionContextKeyInIssuesTable.execute();
+
+ db.assertColumnDefinition(ISSUES_TABLE_NAME, RULE_DESCRIPTION_CONTEXT_KEY_COLUMN_NAME, Types.VARCHAR, 50, true);
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ addRuleDescriptionContextKeyInIssuesTable.execute();
+ addRuleDescriptionContextKeyInIssuesTable.execute();
+
+ db.assertColumnDefinition(ISSUES_TABLE_NAME, RULE_DESCRIPTION_CONTEXT_KEY_COLUMN_NAME, Types.VARCHAR, DbConstants.CONTEXT_KEY_COLUMNS_SIZE, true);
+ }
+}
--- /dev/null
+CREATE TABLE "ISSUES"(
+ "KEE" CHARACTER VARYING(50) NOT NULL,
+ "RULE_UUID" CHARACTER VARYING(40),
+ "SEVERITY" CHARACTER VARYING(10),
+ "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+ "MESSAGE" CHARACTER VARYING(4000),
+ "LINE" INTEGER,
+ "GAP" DOUBLE PRECISION,
+ "STATUS" CHARACTER VARYING(20),
+ "RESOLUTION" CHARACTER VARYING(20),
+ "CHECKSUM" CHARACTER VARYING(1000),
+ "ASSIGNEE" CHARACTER VARYING(255),
+ "AUTHOR_LOGIN" CHARACTER VARYING(255),
+ "EFFORT" INTEGER,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "ISSUE_CREATION_DATE" BIGINT,
+ "ISSUE_UPDATE_DATE" BIGINT,
+ "ISSUE_CLOSE_DATE" BIGINT,
+ "TAGS" CHARACTER VARYING(4000),
+ "COMPONENT_UUID" CHARACTER VARYING(50),
+ "PROJECT_UUID" CHARACTER VARYING(50),
+ "LOCATIONS" BINARY LARGE OBJECT,
+ "ISSUE_TYPE" TINYINT,
+ "FROM_HOTSPOT" BOOLEAN,
+ "QUICK_FIX_AVAILABLE" BOOLEAN
+);
+ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
+CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE" NULLS FIRST);
+CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE" NULLS FIRST);
+CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID" NULLS FIRST);
+CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION" NULLS FIRST);
+CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT" NULLS FIRST);
+CREATE INDEX "ISSUES_RULE_UUID" ON "ISSUES"("RULE_UUID" NULLS FIRST);