From: Eric Hartmann Date: Wed, 14 Jun 2017 15:37:44 +0000 (+0200) Subject: SONAR-9304 remove orphans from rules_profiles X-Git-Tag: 6.5-M1~11 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b33d63ad5fb20e1b25ab377770fd91c6cb8f7cda;p=sonarqube.git SONAR-9304 remove orphans from rules_profiles --- diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChanges.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChanges.java new file mode 100644 index 00000000000..003a69d24be --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChanges.java @@ -0,0 +1,54 @@ +/* + * 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.v65; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.def.VarcharColumnDef; +import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class AddIndexRulesProfileUuidOnQProfileChanges extends DdlChange { + + private static final String TABLE_NAME = "qprofile_changes"; + private static final String COLUMN_NAME = "rules_profile_uuid"; + private static final String NEW_INDEX_NAME = "qp_changes_rules_profile_uuid"; + + public AddIndexRulesProfileUuidOnQProfileChanges(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + VarcharColumnDef rulesProfileUuid = VarcharColumnDef.newVarcharColumnDefBuilder() + .setColumnName(COLUMN_NAME) + .setLimit(255) + .setIsNullable(false) + .build(); + + context.execute(new CreateIndexBuilder(getDialect()) + .setName(NEW_INDEX_NAME) + .setTable(TABLE_NAME) + .addColumn(rulesProfileUuid) + .build() + ); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChangesIsIndexed.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChangesIsIndexed.java deleted file mode 100644 index cd7ebee4ec9..00000000000 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChangesIsIndexed.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.v65; - -import java.sql.SQLException; -import org.sonar.db.Database; -import org.sonar.server.platform.db.migration.def.VarcharColumnDef; -import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class AddIndexRulesProfileUuidOnQProfileChangesIsIndexed extends DdlChange { - - private static final String TABLE_NAME = "qprofile_changes"; - private static final String COLUMN_NAME = "rules_profile_uuid"; - private static final String NEW_INDEX_NAME = "qp_changes_rules_profile_uuid"; - - public AddIndexRulesProfileUuidOnQProfileChangesIsIndexed(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - VarcharColumnDef rulesProfileUuid = VarcharColumnDef.newVarcharColumnDefBuilder() - .setColumnName(COLUMN_NAME) - .setLimit(255) - .setIsNullable(false) - .build(); - - context.execute(new CreateIndexBuilder(getDialect()) - .setName(NEW_INDEX_NAME) - .setTable(TABLE_NAME) - .addColumn(rulesProfileUuid) - .build() - ); - } -} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java index 67b0d8fbf43..75ac30953ab 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java @@ -52,8 +52,9 @@ public class DbVersion65 implements DbVersion { .add(1723, "Populate table qprofiles", PopulateOrgQProfiles.class) .add(1724, "Drop columns organization_uuid and parent_kee from rules_profiles", DropOrgColumnsFromRulesProfiles.class) .add(1725, "Mark rules_profiles.is_built_in to true for default organization", SetRulesProfilesIsBuiltInToTrueForDefaultOrganization.class) - .add(1726, "Update OrgQProfiles to point to built-in profiles", UpdateOrgQProfilesToPointToBuiltInProfiles.class) - .add(1727, "Rename column qprofile_changes.qprofile_key to qprofile_changes.rules_profile_uuid", RenameQProfileKeyToRulesProfileUuidOnQProfileChanges.class) - .add(1728, "Ensure presence of index on qprofile_changes.rules_profile_uuid", AddIndexRulesProfileUuidOnQProfileChangesIsIndexed.class); + .add(1726, "Update org_qprofiles to reference built-in profiles", UpdateOrgQProfilesToPointToBuiltInProfiles.class) + .add(1727, "Delete rules_profiles orphans", DeleteOrphansFromRulesProfiles.class) + .add(1728, "Rename column qprofile_changes.qprofile_key to qprofile_changes.rules_profile_uuid", RenameQProfileKeyToRulesProfileUuidOnQProfileChanges.class) + .add(1729, "Add index on qprofile_changes.rules_profile_uuid", AddIndexRulesProfileUuidOnQProfileChanges.class); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChangesIsIndexedTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChangesIsIndexedTest.java deleted file mode 100644 index 818b4c74680..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChangesIsIndexedTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.v65; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.CoreDbTester; - -public class AddIndexRulesProfileUuidOnQProfileChangesIsIndexedTest { - - private static final String TABLE_NAME = "qprofile_changes"; - private static final String COLUMN_NAME = "rules_profile_uuid"; - private static final String INDEX_NAME = "qp_changes_rules_profile_uuid"; - - @Rule - public CoreDbTester db = CoreDbTester.createForSchema(AddIndexRulesProfileUuidOnQProfileChangesIsIndexedTest.class, "initial.sql"); - - private AddIndexRulesProfileUuidOnQProfileChangesIsIndexed underTest = new AddIndexRulesProfileUuidOnQProfileChangesIsIndexed(db.database()); - - @Test - public void add_index_ON_RULES_PROFILE_UUID_of_QPROFILE_CHANGES() throws SQLException { - underTest.execute(); - - db.assertIndex(TABLE_NAME, INDEX_NAME,COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChangesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChangesTest.java new file mode 100644 index 00000000000..d2039468c7c --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChangesTest.java @@ -0,0 +1,44 @@ +/* + * 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.v65; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +public class AddIndexRulesProfileUuidOnQProfileChangesTest { + + private static final String TABLE_NAME = "qprofile_changes"; + private static final String COLUMN_NAME = "rules_profile_uuid"; + private static final String INDEX_NAME = "qp_changes_rules_profile_uuid"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddIndexRulesProfileUuidOnQProfileChangesTest.class, "initial.sql"); + + private AddIndexRulesProfileUuidOnQProfileChanges underTest = new AddIndexRulesProfileUuidOnQProfileChanges(db.database()); + + @Test + public void add_index_ON_RULES_PROFILE_UUID_of_QPROFILE_CHANGES() throws SQLException { + underTest.execute(); + + db.assertIndex(TABLE_NAME, INDEX_NAME,COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java index 008357b2f8d..618c8014db3 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java @@ -35,6 +35,6 @@ public class DbVersion65Test { @Test public void verify_migration_count() { - verifyMigrationCount(underTest, 29); + verifyMigrationCount(underTest, 30); } } diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChangesIsIndexedTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChangesIsIndexedTest/initial.sql deleted file mode 100644 index 43d3ab5c3c1..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChangesIsIndexedTest/initial.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE TABLE "QPROFILE_CHANGES" ( - "KEE" VARCHAR(40) NOT NULL PRIMARY KEY, - "RULES_PROFILE_UUID" VARCHAR(255) NOT NULL, - "CHANGE_TYPE" VARCHAR(20) NOT NULL, - "CREATED_AT" BIGINT NOT NULL, - "USER_LOGIN" VARCHAR(255), - "CHANGE_DATA" CLOB -); -CREATE INDEX "QPROFILE_CHANGES_QPROFILE_KEY" ON "QPROFILE_CHANGES" ("RULES_PROFILE_UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChangesTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChangesTest/initial.sql new file mode 100644 index 00000000000..43d3ab5c3c1 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/AddIndexRulesProfileUuidOnQProfileChangesTest/initial.sql @@ -0,0 +1,9 @@ +CREATE TABLE "QPROFILE_CHANGES" ( + "KEE" VARCHAR(40) NOT NULL PRIMARY KEY, + "RULES_PROFILE_UUID" VARCHAR(255) NOT NULL, + "CHANGE_TYPE" VARCHAR(20) NOT NULL, + "CREATED_AT" BIGINT NOT NULL, + "USER_LOGIN" VARCHAR(255), + "CHANGE_DATA" CLOB +); +CREATE INDEX "QPROFILE_CHANGES_QPROFILE_KEY" ON "QPROFILE_CHANGES" ("RULES_PROFILE_UUID");