diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-05-31 10:59:33 +0200 |
---|---|---|
committer | Eric Hartmann <hartmann.eric@gmail.com> | 2017-06-14 15:43:12 +0200 |
commit | 3e26c9b9b44ebabbc2c81e134c26799ce3f4bc3b (patch) | |
tree | 548b40695d3fb85cdcd42c889bb1ae470cbbbb14 /server/sonar-db-migration | |
parent | d4133c63eb8e7b6acc54195da3206f1b3a5f7689 (diff) | |
download | sonarqube-3e26c9b9b44ebabbc2c81e134c26799ce3f4bc3b.tar.gz sonarqube-3e26c9b9b44ebabbc2c81e134c26799ce3f4bc3b.zip |
SONAR-9304 rename table qprofiles to org_qprofiles
Diffstat (limited to 'server/sonar-db-migration')
11 files changed, 152 insertions, 39 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfiles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfiles.java index 23d137c1142..787fa699238 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfiles.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfiles.java @@ -30,11 +30,11 @@ import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.new import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; -public class CreateTableQProfiles extends DdlChange { +public class CreateTableOrgQProfiles extends DdlChange { - private static final String TABLE_NAME = "qprofiles"; + private static final String TABLE_NAME = "org_qprofiles"; - public CreateTableQProfiles(Database db) { + public CreateTableOrgQProfiles(Database db) { super(db); } @@ -46,21 +46,21 @@ public class CreateTableQProfiles extends DdlChange { .setIsNullable(false) .setIgnoreOracleUnit(true) .build(); + VarcharColumnDef rulesProfileUuid = newVarcharColumnDefBuilder() + .setColumnName("rules_profile_uuid") + .setLimit(UUID_SIZE) + .setIsNullable(false) + .setIgnoreOracleUnit(true) + .build(); context.execute( new CreateTableBuilder(getDialect(), TABLE_NAME) .addPkColumn(newVarcharColumnDefBuilder() .setColumnName("uuid") .setLimit(UUID_SIZE) .setIsNullable(false) - .setIgnoreOracleUnit(true) .build()) .addColumn(organizationColumn) - .addColumn(newVarcharColumnDefBuilder() - .setColumnName("rules_profile_uuid") - .setLimit(UUID_SIZE) - .setIsNullable(false) - .setIgnoreOracleUnit(true) - .build()) + .addColumn(rulesProfileUuid) .addColumn(newVarcharColumnDefBuilder() .setColumnName("parent_uuid") .setLimit(UUID_SIZE) @@ -83,5 +83,12 @@ public class CreateTableQProfiles extends DdlChange { .setName("qprofiles_org_uuid") .addColumn(organizationColumn) .build()); + + context.execute( + new CreateIndexBuilder(getDialect()) + .setTable(TABLE_NAME) + .setName("qprofiles_rp_uuid") + .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 a9956f20c78..abf295015e0 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 @@ -49,6 +49,7 @@ public class DbVersion65 implements DbVersion { .add(1720, "Populate table default_qprofiles", PopulateTableDefaultQProfiles.class) .add(1721, "Drop rules_profiles.is_default", DropIsDefaultColumnFromRulesProfiles.class) .add(1722, "Create table qprofiles", CreateTableQProfiles.class) - .add(1723, "Populate table qprofiles", PopulateQProfiles.class); + .add(1723, "Populate table qprofiles", PopulateQProfiles.class) + .add(1724, "Drop columns organization_uuid and parent_kee from rules_profiles", DropOrgUuidAndParentKeeFromRulesProfiles.class); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfiles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfiles.java new file mode 100644 index 00000000000..105c8fde6ab --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfiles.java @@ -0,0 +1,41 @@ +/* + * 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.sql.DropColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropOrgUuidAndParentKeeFromRulesProfiles extends DdlChange { + + private static final String TABLE_NAME = "rules_profiles"; + + public DropOrgUuidAndParentKeeFromRulesProfiles(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, "organization_uuid").build()); + context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, "parent_kee").build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateQProfiles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfiles.java index a7505cd9d55..b8f35b3057a 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateQProfiles.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfiles.java @@ -26,11 +26,11 @@ import org.sonar.db.Database; import org.sonar.server.platform.db.migration.step.DataChange; import org.sonar.server.platform.db.migration.step.MassUpdate; -public class PopulateQProfiles extends DataChange { +public class PopulateOrgQProfiles extends DataChange { private final System2 system2; - public PopulateQProfiles(Database db, System2 system2) { + public PopulateOrgQProfiles(Database db, System2 system2) { super(db); this.system2 = system2; } @@ -41,15 +41,19 @@ public class PopulateQProfiles extends DataChange { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("select p.kee, p.organization_uuid, p.parent_kee from rules_profiles p " + - "where not exists ( select qp.uuid from qprofiles qp where qp.uuid = p.kee and qp.organization_uuid = p.organization_uuid )"); - massUpdate.update("insert into qprofiles" + + "where not exists ( select qp.uuid from org_qprofiles qp where qp.uuid = p.kee and qp.organization_uuid = p.organization_uuid )"); + massUpdate.update("insert into org_qprofiles" + " (uuid, organization_uuid, rules_profile_uuid, parent_uuid, created_at, updated_at) values (?, ?, ?, ?, ?, ?)"); - massUpdate.rowPluralName("qprofiles"); + massUpdate.rowPluralName("org_qprofiles"); massUpdate.execute((row, update) -> { - update.setString(1, row.getString(1)); - update.setString(2, row.getString(2)); - update.setString(3, row.getString(1)); - update.setString(4, row.getString(3)); + String uuid = row.getString(1); + String organizationUuid = row.getString(2); + String parentUuid = row.getString(3); + + update.setString(1, uuid); + update.setString(2, organizationUuid); + update.setString(3, uuid); + update.setString(4, parentUuid); update.setLong(5, now); update.setLong(6, now); return true; diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest.java index 6ad59c3fdc5..d44d46715df 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest.java @@ -29,16 +29,16 @@ import org.sonar.db.CoreDbTester; import static org.assertj.core.api.Assertions.assertThat; -public class CreateTableQProfilesTest { +public class CreateTableOrgQProfilesTest { - private static final String TABLE = "qprofiles"; + private static final String TABLE = "org_qprofiles"; @Rule - public final CoreDbTester db = CoreDbTester.createForSchema(CreateTableQProfilesTest.class, "empty.sql"); + public final CoreDbTester db = CoreDbTester.createForSchema(CreateTableOrgQProfilesTest.class, "empty.sql"); @Rule public ExpectedException expectedException = ExpectedException.none(); - private CreateTableQProfiles underTest = new CreateTableQProfiles(db.database()); + private CreateTableOrgQProfiles underTest = new CreateTableOrgQProfiles(db.database()); @Test public void creates_table_on_empty_db() throws SQLException { @@ -47,12 +47,13 @@ public class CreateTableQProfilesTest { assertThat(db.countRowsOfTable(TABLE)).isEqualTo(0); db.assertColumnDefinition(TABLE, "uuid", Types.VARCHAR, 40, false); - db.assertPrimaryKey(TABLE, "pk_qprofiles", "uuid"); + db.assertPrimaryKey(TABLE, "pk_org_qprofiles", "uuid"); db.assertColumnDefinition(TABLE, "organization_uuid", Types.VARCHAR, 40, false); db.assertColumnDefinition(TABLE, "rules_profile_uuid", Types.VARCHAR, 40, false); db.assertColumnDefinition(TABLE, "created_at", Types.BIGINT, null, false); db.assertColumnDefinition(TABLE, "updated_at", Types.BIGINT, null, false); db.assertIndex(TABLE, "qprofiles_org_uuid", "organization_uuid"); + db.assertIndex(TABLE, "qprofiles_rp_uuid", "rules_profile_uuid"); } @Test 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 a1f026d0fff..e9474738566 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, 24); + verifyMigrationCount(underTest, 25); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest.java new file mode 100644 index 00000000000..f879628475b --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest.java @@ -0,0 +1,43 @@ +/* + * 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 DropOrgUuidAndParentKeeFromRulesProfilesTest { + + private static final String TABLE_NAME = "rules_profiles"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropOrgUuidAndParentKeeFromRulesProfilesTest.class, "initial.sql"); + + private DropOrgUuidAndParentKeeFromRulesProfiles underTest = new DropOrgUuidAndParentKeeFromRulesProfiles(db.database()); + + @Test + public void columns_are_dropped() throws SQLException { + underTest.execute(); + + db.assertColumnDoesNotExist(TABLE_NAME, "organization_uuid"); + db.assertColumnDoesNotExist(TABLE_NAME, "parent_kee"); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateQProfilesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest.java index b4fb5dc578c..301fefc0e21 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateQProfilesTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest.java @@ -35,16 +35,16 @@ import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; -public class PopulateQProfilesTest { +public class PopulateOrgQProfilesTest { @Rule public ExpectedException expectedException = ExpectedException.none(); @Rule - public CoreDbTester db = CoreDbTester.createForSchema(PopulateQProfilesTest.class, "initial.sql"); + public CoreDbTester db = CoreDbTester.createForSchema(PopulateOrgQProfilesTest.class, "initial.sql"); private System2 system2 = new AlwaysIncreasingSystem2(); - private PopulateQProfiles underTest = new PopulateQProfiles(db.database(), system2); + private PopulateOrgQProfiles underTest = new PopulateOrgQProfiles(db.database(), system2); @Test public void migration_is_reentrant() throws SQLException { @@ -52,13 +52,13 @@ public class PopulateQProfilesTest { insertRulesProfile("ORG_2", "js", "u2", "u1", true); // org1 is already processed - insertQProfile("u1", "ORG_1", "RPU1"); + insertOrgQProfile("u1", "ORG_1", "RPU1"); underTest.execute(); assertThat(countRows()).isEqualTo(2); - Map<String, Object> qprofile1 = selectQProfile("u1", "ORG_1"); - Map<String, Object> qprofile2 = selectQProfile("u2", "ORG_2"); + Map<String, Object> qprofile1 = selectOrgQProfile("u1", "ORG_1"); + Map<String, Object> qprofile2 = selectOrgQProfile("u2", "ORG_2"); assertThat(qprofile1.get("UUID")).isEqualTo("u1"); assertThat(qprofile1.get("ORGANIZATION_UUID")).isEqualTo("ORG_1"); @@ -86,7 +86,7 @@ public class PopulateQProfilesTest { private int countRows() { - return db.countRowsOfTable("qprofiles"); + return db.countRowsOfTable("org_qprofiles"); } private void insertRulesProfile(String orgUuid, String language, String uuid, String parentKee, boolean isDefault) { @@ -100,8 +100,8 @@ public class PopulateQProfilesTest { "IS_BUILT_IN", true); } - private void insertQProfile(String uuid, String orgUuid, String rulesProfileUuid) { - db.executeInsert("QPROFILES", + private void insertOrgQProfile(String uuid, String orgUuid, String rulesProfileUuid) { + db.executeInsert("ORG_QPROFILES", "ORGANIZATION_UUID", orgUuid, "RULES_PROFILE_UUID", rulesProfileUuid, "UUID", uuid, @@ -110,7 +110,7 @@ public class PopulateQProfilesTest { ); } - private Map<String, Object> selectQProfile(String uuid, String orgUuid) { - return db.selectFirst(format("select * from qprofiles where uuid='%s' and organization_uuid='%s'", uuid, orgUuid)); + private Map<String, Object> selectOrgQProfile(String uuid, String orgUuid) { + return db.selectFirst(format("select * from org_qprofiles where uuid='%s' and organization_uuid='%s'", uuid, orgUuid)); } } diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest/empty.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest/empty.sql index e69de29bb2d..e69de29bb2d 100644 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest/empty.sql +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest/empty.sql diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest/initial.sql new file mode 100644 index 00000000000..7c1c1fedab0 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest/initial.sql @@ -0,0 +1,15 @@ +CREATE TABLE "RULES_PROFILES" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "NAME" VARCHAR(100) NOT NULL, + "LANGUAGE" VARCHAR(20), + "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, + "KEE" VARCHAR(255) NOT NULL, + "PARENT_KEE" VARCHAR(255), + "RULES_UPDATED_AT" VARCHAR(100), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP, + "LAST_USED" BIGINT, + "USER_UPDATED_AT" BIGINT, + "IS_BUILT_IN" BOOLEAN NOT NULL +); +CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateQProfilesTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest/initial.sql index df8bf1316ff..3d84b4a125f 100644 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateQProfilesTest/initial.sql +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest/initial.sql @@ -15,7 +15,7 @@ CREATE TABLE "RULES_PROFILES" ( ); CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE"); -CREATE TABLE "QPROFILES" ( +CREATE TABLE "ORG_QPROFILES" ( "UUID" VARCHAR(40) NOT NULL PRIMARY KEY, "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, "RULES_PROFILE_UUID" VARCHAR(40) NOT NULL, @@ -23,4 +23,5 @@ CREATE TABLE "QPROFILES" ( "CREATED_AT" BIGINT NOT NULL, "UPDATED_AT" BIGINT NOT NULL ); -CREATE INDEX "QPROFILES_ORG_UUID" ON "QPROFILES" ("ORGANIZATION_UUID"); +CREATE INDEX "ORG_QPROFILES_ORG_UUID" ON "ORG_QPROFILES" ("ORGANIZATION_UUID"); +CREATE INDEX "ORG_QPROFILES_RP_UUID" ON "ORG_QPROFILES" ("RULES_PROFILE_UUID"); |