aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-04-11 11:49:50 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-04-11 12:20:49 +0200
commit2489c157e7a4e563c7279b57f12c197aa53d28b5 (patch)
tree7b1c26da08348770d67ac6322ee918498c95b752 /server
parent7b458e820fa2298aaeef3febac4467bc868965d5 (diff)
parenta8a990b0170b730b642f44d683376dd710b47110 (diff)
downloadsonarqube-2489c157e7a4e563c7279b57f12c197aa53d28b5.tar.gz
sonarqube-2489c157e7a4e563c7279b57f12c197aa53d28b5.zip
Merge branch 'branch-6.3'
Diffstat (limited to 'server')
-rw-r--r--server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql2
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java1
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUnique.java57
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java4
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63Test.java2
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueReentranceTest.java80
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueTest.java79
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64Test.java2
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueReentranceTest/organizations_with_unique_index.sql16
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueTest/organizations_with_non_unique_index.sql16
10 files changed, 256 insertions, 3 deletions
diff --git a/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql b/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql
index 0dd7c8e771d..710248fe604 100644
--- a/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql
+++ b/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql
@@ -531,6 +531,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1514');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1515');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1516');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1517');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1518');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1600');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1601');
@@ -550,6 +551,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1614');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1615');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1616');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1617');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1618');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, IS_ROOT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', false, '1418215735482', '1418215735482');
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java
index c2815a97bcf..0e4d36500cc 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java
@@ -50,6 +50,7 @@ public class DbVersion63 implements DbVersion {
.add(1515, "Unset user root flags", UnsetUserRootFlags.class)
.add(1516, "Add ORGANIZATIONS.USER_ID", AddUserIdToOrganizations.class)
.add(1517, "Delete PROJECT_MEASURES rows having no value", DeleteMeasuresHavingNoValue.class)
+ .add(1518, "Make index on ORGANIZATIONS.KEE unique", MakeIndexOnOrganizationsKeeUnique.class)
;
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUnique.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUnique.java
new file mode 100644
index 00000000000..4dde2641f57
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUnique.java
@@ -0,0 +1,57 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.v63;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeIndexOnOrganizationsKeeUnique extends DdlChange {
+
+ private static final String TABLE_ORGANIZATIONS = "organizations";
+ private static final String INDEX_NAME = "organization_key";
+
+ public MakeIndexOnOrganizationsKeeUnique(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable(TABLE_ORGANIZATIONS)
+ .setName(INDEX_NAME)
+ .build());
+
+ context.execute(new CreateIndexBuilder(getDialect())
+ .setTable(TABLE_ORGANIZATIONS)
+ .setName(INDEX_NAME)
+ .addColumn(newVarcharColumnDefBuilder()
+ .setColumnName("kee")
+ .setLimit(32)
+ .setIsNullable(false)
+ .build())
+ .setUnique(true)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java
index e000208527b..39301e3da37 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java
@@ -44,6 +44,8 @@ public class DbVersion64 implements DbVersion {
.add(1614, "Upgrade loaded template entries for quality profiles", UpgradeQualityTemplateLoadedTemplates.class)
.add(1615, "Create table RULES_METADATA", CreateRulesMetadata.class)
.add(1616, "Populate table RULES_METADATA", PopulateRulesMetadata.class)
- .add(1617, "Drop metadata columns from RULES", DropMetadataColumnsFromRules.class);
+ .add(1617, "Drop metadata columns from RULES", DropMetadataColumnsFromRules.class)
+ // ensure the index is made unique even on existing 6.4-SNAPSHOT instances (such as next or the developer machines)
+ .add(1618, "Make index on ORGANIZATIONS.KEE unique", org.sonar.server.platform.db.migration.version.v63.MakeIndexOnOrganizationsKeeUnique.class);
}
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63Test.java
index e9c26d7fefa..dca9beeebdb 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63Test.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63Test.java
@@ -41,7 +41,7 @@ public class DbVersion63Test {
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 18);
+ verifyMigrationCount(underTest, 19);
}
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueReentranceTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueReentranceTest.java
new file mode 100644
index 00000000000..1bc3bdc1a2c
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueReentranceTest.java
@@ -0,0 +1,80 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.v63;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+public class MakeIndexOnOrganizationsKeeUniqueReentranceTest {
+ private static final String TABLE_ORGANIZATIONS = "organizations";
+ private static final String INDEX_NAME = "organization_key";
+
+ @Rule
+ public CoreDbTester dbTester = CoreDbTester.createForSchema(MakeIndexOnOrganizationsKeeUniqueReentranceTest.class, "organizations_with_unique_index.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private MakeIndexOnOrganizationsKeeUnique underTest = new MakeIndexOnOrganizationsKeeUnique(dbTester.database());
+
+ @Test
+ public void execute_makes_index_unique_on_empty_table() throws SQLException {
+ dbTester.assertIndex(TABLE_ORGANIZATIONS, INDEX_NAME, "kee");
+
+ underTest.execute();
+
+ dbTester.assertUniqueIndex(TABLE_ORGANIZATIONS, INDEX_NAME, "kee");
+ }
+
+ @Test
+ public void execute_makes_index_unique_on_non_empty_table_without_duplicates() throws SQLException {
+ dbTester.assertIndex(TABLE_ORGANIZATIONS, INDEX_NAME, "kee");
+ insert("1", "kee_1");
+ insert("2", "kee_2");
+
+ underTest.execute();
+
+ dbTester.assertUniqueIndex(TABLE_ORGANIZATIONS, INDEX_NAME, "kee");
+ }
+
+ @Test
+ public void execute_fails_non_empty_table_with_duplicates() throws SQLException {
+ dbTester.assertIndex(TABLE_ORGANIZATIONS, INDEX_NAME, "kee");
+ insert("1", "kee_1");
+ insert("2", "kee_1");
+
+ expectedException.expect(IllegalStateException.class);
+
+ underTest.execute();
+ }
+
+ private void insert(String uuid, String kee) {
+ dbTester.executeInsert(TABLE_ORGANIZATIONS,
+ "UUID", uuid,
+ "KEE", kee,
+ "NAME", "name",
+ "GUARDED", "false",
+ "CREATED_AT", "1000",
+ "UPDATED_AT", "2000");
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueTest.java
new file mode 100644
index 00000000000..869e2cf1ac4
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueTest.java
@@ -0,0 +1,79 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.v63;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+public class MakeIndexOnOrganizationsKeeUniqueTest {
+ private static final String TABLE_ORGANIZATIONS = "organizations";
+ private static final String INDEX_NAME = "organization_key";
+
+ @Rule
+ public CoreDbTester dbTester = CoreDbTester.createForSchema(MakeIndexOnOrganizationsKeeUniqueTest.class, "organizations_with_non_unique_index.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private MakeIndexOnOrganizationsKeeUnique underTest = new MakeIndexOnOrganizationsKeeUnique(dbTester.database());
+
+ @Test
+ public void execute_makes_index_unique_on_empty_table() throws SQLException {
+ dbTester.assertIndex(TABLE_ORGANIZATIONS, INDEX_NAME, "kee");
+
+ underTest.execute();
+
+ dbTester.assertUniqueIndex(TABLE_ORGANIZATIONS, INDEX_NAME, "kee");
+ }
+
+ @Test
+ public void execute_makes_index_unique_on_non_empty_table_without_duplicates() throws SQLException {
+ dbTester.assertIndex(TABLE_ORGANIZATIONS, INDEX_NAME, "kee");
+ insert("1", "kee_1");
+ insert("2", "kee_2");
+
+ underTest.execute();
+
+ dbTester.assertUniqueIndex(TABLE_ORGANIZATIONS, INDEX_NAME, "kee");
+ }
+
+ @Test
+ public void execute_fails_non_empty_table_with_duplicates() throws SQLException {
+ dbTester.assertIndex(TABLE_ORGANIZATIONS, INDEX_NAME, "kee");
+ insert("1", "kee_1");
+ insert("2", "kee_1");
+
+ expectedException.expect(IllegalStateException.class);
+
+ underTest.execute();
+ }
+
+ private void insert(String uuid, String kee) {
+ dbTester.executeInsert(TABLE_ORGANIZATIONS,
+ "UUID", uuid,
+ "KEE", kee,
+ "NAME", "name",
+ "GUARDED", "false",
+ "CREATED_AT", "1000",
+ "UPDATED_AT", "2000");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64Test.java
index 727a9de26f4..f30d2ab0e8b 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64Test.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64Test.java
@@ -35,7 +35,7 @@ public class DbVersion64Test {
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 18);
+ verifyMigrationCount(underTest, 19);
}
}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueReentranceTest/organizations_with_unique_index.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueReentranceTest/organizations_with_unique_index.sql
new file mode 100644
index 00000000000..12d83796405
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueReentranceTest/organizations_with_unique_index.sql
@@ -0,0 +1,16 @@
+CREATE TABLE "ORGANIZATIONS" (
+ "UUID" VARCHAR(40) NOT NULL PRIMARY KEY,
+ "KEE" VARCHAR(32) NOT NULL,
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(256),
+ "URL" VARCHAR(256),
+ "AVATAR_URL" VARCHAR(256),
+ "GUARDED" BOOLEAN NOT NULL,
+ "USER_ID" INTEGER,
+ "DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40),
+ "DEFAULT_PERM_TEMPLATE_VIEW" VARCHAR(40),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+CREATE UNIQUE INDEX "PK_ORGANIZATIONS" ON "ORGANIZATIONS" ("UUID");
+CREATE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS" ("KEE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueTest/organizations_with_non_unique_index.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueTest/organizations_with_non_unique_index.sql
new file mode 100644
index 00000000000..12d83796405
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/MakeIndexOnOrganizationsKeeUniqueTest/organizations_with_non_unique_index.sql
@@ -0,0 +1,16 @@
+CREATE TABLE "ORGANIZATIONS" (
+ "UUID" VARCHAR(40) NOT NULL PRIMARY KEY,
+ "KEE" VARCHAR(32) NOT NULL,
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(256),
+ "URL" VARCHAR(256),
+ "AVATAR_URL" VARCHAR(256),
+ "GUARDED" BOOLEAN NOT NULL,
+ "USER_ID" INTEGER,
+ "DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40),
+ "DEFAULT_PERM_TEMPLATE_VIEW" VARCHAR(40),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+CREATE UNIQUE INDEX "PK_ORGANIZATIONS" ON "ORGANIZATIONS" ("UUID");
+CREATE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS" ("KEE");