aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration
diff options
context:
space:
mode:
authorPierre <pierre.guillot@sonarsource.com>2021-09-03 14:16:30 +0200
committersonartech <sonartech@sonarsource.com>2021-09-14 20:03:24 +0000
commita1724a62333f603eb09f129b8b7d865c99c3a616 (patch)
tree9284a76273168d33bbe6d3fe0cdbd9f9f7e80738 /server/sonar-db-migration
parentcbe317bdda5b5cbcc026c144a11757f4519443c8 (diff)
downloadsonarqube-a1724a62333f603eb09f129b8b7d865c99c3a616.tar.gz
sonarqube-a1724a62333f603eb09f129b8b7d865c99c3a616.zip
SONAR-15334 - Project Export Findings endpoint
Diffstat (limited to 'server/sonar-db-migration')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/CreateIndexForIssueChangesOnIssueKeyAndChangeType.java51
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91.java1
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/CreateIndexForIssueChangesOnIssueKeyAndChangeTypeTest.java53
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91Test.java2
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/CreateIndexForIssueChangesOnIssueKeyAndChangeTypeTest/schema.sql16
5 files changed, 122 insertions, 1 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/CreateIndexForIssueChangesOnIssueKeyAndChangeType.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/CreateIndexForIssueChangesOnIssueKeyAndChangeType.java
new file mode 100644
index 00000000000..f14a82e2fc1
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/CreateIndexForIssueChangesOnIssueKeyAndChangeType.java
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v91;
+
+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.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class CreateIndexForIssueChangesOnIssueKeyAndChangeType extends DdlChange {
+ private static final String TABLE_NAME = "issue_changes";
+ private static final String INDEX_NAME = "issue_changes_issue_key_type";
+
+ public CreateIndexForIssueChangesOnIssueKeyAndChangeType(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ try (Connection c = getDatabase().getDataSource().getConnection()) {
+ if (!DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, c)) {
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE_NAME)
+ .setName(INDEX_NAME)
+ .addColumn("issue_key")
+ .addColumn("change_type")
+ .setUnique(false)
+ .build());
+ }
+ }
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91.java
index f7b27125deb..d84329d82f4 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91.java
@@ -43,6 +43,7 @@ public class DbVersion91 implements DbVersion {
.add(6015, "Create 'portfolio_projects' table", CreatePortfolioProjectsTable.class)
.add(6016, "Create unique index for 'portfolio_projects'", CreateIndexForPortfolioProjects.class)
.add(6017, "Migrate portfolios to new tables", MigratePortfoliosToNewTables.class)
+ .add(6018, "Create index for 'issue_changes' on 'issue_key' and 'change_type'", CreateIndexForIssueChangesOnIssueKeyAndChangeType.class)
;
}
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/CreateIndexForIssueChangesOnIssueKeyAndChangeTypeTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/CreateIndexForIssueChangesOnIssueKeyAndChangeTypeTest.java
new file mode 100644
index 00000000000..b004a804fea
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/CreateIndexForIssueChangesOnIssueKeyAndChangeTypeTest.java
@@ -0,0 +1,53 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v91;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class CreateIndexForIssueChangesOnIssueKeyAndChangeTypeTest {
+ private final static String TABLE_NAME = "issue_changes";
+ private final static String INDEX_NAME = "issue_changes_issue_key_type";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexForIssueChangesOnIssueKeyAndChangeTypeTest.class, "schema.sql");
+
+ private final CreateIndexForIssueChangesOnIssueKeyAndChangeType underTest = new CreateIndexForIssueChangesOnIssueKeyAndChangeType(db.database());
+
+ @Test
+ public void should_create_index() throws SQLException {
+ db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);
+ underTest.execute();
+ db.assertIndex(TABLE_NAME, INDEX_NAME, "issue_key", "change_type");
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);
+
+ underTest.execute();
+ //re-entrant
+ underTest.execute();
+
+ db.assertIndex(TABLE_NAME, INDEX_NAME, "issue_key", "change_type");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91Test.java
index 23abf039d73..ab995043de2 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91Test.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91Test.java
@@ -41,7 +41,7 @@ public class DbVersion91Test {
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 17);
+ verifyMigrationCount(underTest, 18);
}
}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/CreateIndexForIssueChangesOnIssueKeyAndChangeTypeTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/CreateIndexForIssueChangesOnIssueKeyAndChangeTypeTest/schema.sql
new file mode 100644
index 00000000000..cdca6f7f350
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/CreateIndexForIssueChangesOnIssueKeyAndChangeTypeTest/schema.sql
@@ -0,0 +1,16 @@
+CREATE TABLE "ISSUE_CHANGES"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "KEE" VARCHAR(50),
+ "ISSUE_KEY" VARCHAR(50) NOT NULL,
+ "USER_LOGIN" VARCHAR(255),
+ "CHANGE_TYPE" VARCHAR(20),
+ "CHANGE_DATA" CLOB,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "ISSUE_CHANGE_CREATION_DATE" BIGINT,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL
+);
+ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("UUID");
+CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY");
+CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE");
+CREATE INDEX "ISSUE_CHANGES_PROJECT_UUID" ON "ISSUE_CHANGES"("PROJECT_UUID");