aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-06-08 16:53:14 +0200
committerEric Hartmann <hartmann.eric@gmail.com>2017-06-14 15:43:13 +0200
commitd9268101aa0358939e405edc89ee365de71ea035 (patch)
tree86e7f632ee1e1bca16d06644e8eacf991ca9399f /server/sonar-db-migration/src
parent93ece4c32cb488af46855b3ee9d53d7fd9e787b8 (diff)
downloadsonarqube-d9268101aa0358939e405edc89ee365de71ea035.tar.gz
sonarqube-d9268101aa0358939e405edc89ee365de71ea035.zip
SONAR-9304 move rules_profiles.last_used/user_updated_at to org_qprofiles
Diffstat (limited to 'server/sonar-db-migration/src')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfiles.java8
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropOrgColumnsFromRulesProfiles.java (renamed from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfiles.java)6
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfiles.java12
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/UpdateOrgQProfilesToPointToBuiltInProfiles.java2
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest.java2
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropOrgColumnsFromRulesProfilesTest.java (renamed from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest.java)8
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest.java21
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/UpdateOrgQProfilesToPointToBuiltInProfilesTest.java6
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropOrgColumnsFromRulesProfilesTest/initial.sql (renamed from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest/initial.sql)0
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest/initial.sql6
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/UpdateOrgQProfilesToPointToBuiltInProfilesTest/initial.sql4
11 files changed, 48 insertions, 27 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfiles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfiles.java
index 787fa699238..6126aaef4a8 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfiles.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfiles.java
@@ -68,6 +68,14 @@ public class CreateTableOrgQProfiles extends DdlChange {
.setIgnoreOracleUnit(true)
.build())
.addColumn(newBigIntegerColumnDefBuilder()
+ .setColumnName("last_used")
+ .setIsNullable(true)
+ .build())
+ .addColumn(newBigIntegerColumnDefBuilder()
+ .setColumnName("user_updated_at")
+ .setIsNullable(true)
+ .build())
+ .addColumn(newBigIntegerColumnDefBuilder()
.setColumnName("created_at")
.setIsNullable(false)
.build())
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/DropOrgColumnsFromRulesProfiles.java
index 105c8fde6ab..e6a27a8659e 100644
--- 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/DropOrgColumnsFromRulesProfiles.java
@@ -25,11 +25,11 @@ 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 {
+public class DropOrgColumnsFromRulesProfiles extends DdlChange {
private static final String TABLE_NAME = "rules_profiles";
- public DropOrgUuidAndParentKeeFromRulesProfiles(Database db) {
+ public DropOrgColumnsFromRulesProfiles(Database db) {
super(db);
}
@@ -37,5 +37,7 @@ public class DropOrgUuidAndParentKeeFromRulesProfiles extends DdlChange {
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());
+ context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, "last_used").build());
+ context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, "user_updated_at").build());
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfiles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfiles.java
index b8f35b3057a..197e197d84c 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfiles.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfiles.java
@@ -40,22 +40,26 @@ public class PopulateOrgQProfiles extends DataChange {
long now = system2.now();
MassUpdate massUpdate = context.prepareMassUpdate();
- massUpdate.select("select p.kee, p.organization_uuid, p.parent_kee from rules_profiles p " +
+ massUpdate.select("select p.kee, p.organization_uuid, p.parent_kee, p.last_used, p.user_updated_at from rules_profiles p " +
"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 (?, ?, ?, ?, ?, ?)");
+ " (uuid, organization_uuid, rules_profile_uuid, parent_uuid, last_used, user_updated_at, created_at, updated_at) values (?, ?, ?, ?, ?, ?, ?, ?)");
massUpdate.rowPluralName("org_qprofiles");
massUpdate.execute((row, update) -> {
String uuid = row.getString(1);
String organizationUuid = row.getString(2);
String parentUuid = row.getString(3);
+ Long lastUsed = row.getNullableLong(4);
+ Long userUpdatedAt = row.getNullableLong(5);
update.setString(1, uuid);
update.setString(2, organizationUuid);
update.setString(3, uuid);
update.setString(4, parentUuid);
- update.setLong(5, now);
- update.setLong(6, now);
+ update.setLong(5, lastUsed);
+ update.setLong(6, userUpdatedAt);
+ update.setLong(7, now);
+ update.setLong(8, now);
return true;
});
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/UpdateOrgQProfilesToPointToBuiltInProfiles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/UpdateOrgQProfilesToPointToBuiltInProfiles.java
index d1af8566067..d47644190a3 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/UpdateOrgQProfilesToPointToBuiltInProfiles.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/UpdateOrgQProfilesToPointToBuiltInProfiles.java
@@ -54,7 +54,7 @@ public class UpdateOrgQProfilesToPointToBuiltInProfiles extends DataChange {
" inner join rules_profiles rp on rp.kee = oqp.rules_profile_uuid " +
" where oqp.organization_uuid <> ? " +
" and rp.is_built_in = ? " +
- " and rp.user_updated_at is null")
+ " and oqp.user_updated_at is null")
.setString(1, defaultOrganizationUuid)
.setBoolean(2, false);
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest.java
index d44d46715df..ed4a8eb6fac 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest.java
@@ -50,6 +50,8 @@ public class CreateTableOrgQProfilesTest {
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, "last_used", Types.BIGINT, null, true);
+ db.assertColumnDefinition(TABLE, "user_updated_at", Types.BIGINT, null, true);
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");
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/DropOrgColumnsFromRulesProfilesTest.java
index f879628475b..9b5a6beac14 100644
--- 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/DropOrgColumnsFromRulesProfilesTest.java
@@ -24,14 +24,14 @@ import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
-public class DropOrgUuidAndParentKeeFromRulesProfilesTest {
+public class DropOrgColumnsFromRulesProfilesTest {
private static final String TABLE_NAME = "rules_profiles";
@Rule
- public CoreDbTester db = CoreDbTester.createForSchema(DropOrgUuidAndParentKeeFromRulesProfilesTest.class, "initial.sql");
+ public CoreDbTester db = CoreDbTester.createForSchema(DropOrgColumnsFromRulesProfilesTest.class, "initial.sql");
- private DropOrgUuidAndParentKeeFromRulesProfiles underTest = new DropOrgUuidAndParentKeeFromRulesProfiles(db.database());
+ private DropOrgColumnsFromRulesProfiles underTest = new DropOrgColumnsFromRulesProfiles(db.database());
@Test
public void columns_are_dropped() throws SQLException {
@@ -39,5 +39,7 @@ public class DropOrgUuidAndParentKeeFromRulesProfilesTest {
db.assertColumnDoesNotExist(TABLE_NAME, "organization_uuid");
db.assertColumnDoesNotExist(TABLE_NAME, "parent_kee");
+ db.assertColumnDoesNotExist(TABLE_NAME, "last_used");
+ db.assertColumnDoesNotExist(TABLE_NAME, "user_updated_at");
}
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest.java
index 301fefc0e21..d897e841857 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest.java
@@ -24,6 +24,7 @@ import java.sql.SQLException;
import java.util.Map;
import java.util.Random;
import java.util.stream.IntStream;
+import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -34,7 +35,6 @@ import org.sonar.db.CoreDbTester;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
-
public class PopulateOrgQProfilesTest {
@Rule
@@ -48,8 +48,8 @@ public class PopulateOrgQProfilesTest {
@Test
public void migration_is_reentrant() throws SQLException {
- insertRulesProfile("ORG_1", "java", "u1", null,true);
- insertRulesProfile("ORG_2", "js", "u2", "u1", true);
+ insertRulesProfile("ORG_1", "java", "u1", null, true, 1_000L, 1_100L);
+ insertRulesProfile("ORG_2", "js", "u2", "u1", true, 1_000L, 1_100L);
// org1 is already processed
insertOrgQProfile("u1", "ORG_1", "RPU1");
@@ -69,6 +69,8 @@ public class PopulateOrgQProfilesTest {
assertThat(qprofile2.get("ORGANIZATION_UUID")).isEqualTo("ORG_2");
assertThat(qprofile2.get("RULES_PROFILE_UUID")).isEqualTo("u2");
assertThat(qprofile2.get("PARENT_UUID")).isEqualTo("u1");
+ assertThat(qprofile2.get("LAST_USED")).isEqualTo(1_000L);
+ assertThat(qprofile2.get("USER_UPDATED_AT")).isEqualTo(1_100L);
}
@Test
@@ -76,20 +78,18 @@ public class PopulateOrgQProfilesTest {
Random random = new Random();
int nbRulesProfile = 100 + random.nextInt(100);
IntStream.range(0, nbRulesProfile).forEach(
- i -> insertRulesProfile("ORG_" + i, "java", "uuid" + i, random.nextBoolean() ? "ORG_" + random.nextInt(i + 1) : null,random.nextBoolean())
- );
+ i -> insertRulesProfile("ORG_" + i, "java", "uuid" + i, random.nextBoolean() ? "ORG_" + random.nextInt(i + 1) : null, random.nextBoolean(), null, null));
underTest.execute();
assertThat(countRows()).isEqualTo(nbRulesProfile);
}
-
private int countRows() {
return db.countRowsOfTable("org_qprofiles");
}
- private void insertRulesProfile(String orgUuid, String language, String uuid, String parentKee, boolean isDefault) {
+ private void insertRulesProfile(String orgUuid, String language, String uuid, String parentKee, boolean isDefault, @Nullable Long lastUsed, @Nullable Long userUpdatedAt) {
db.executeInsert("RULES_PROFILES",
"NAME", "name_" + uuid,
"KEE", uuid,
@@ -97,7 +97,9 @@ public class PopulateOrgQProfilesTest {
"PARENT_KEE", parentKee,
"LANGUAGE", language,
"IS_DEFAULT", isDefault,
- "IS_BUILT_IN", true);
+ "IS_BUILT_IN", true,
+ "LAST_USED", lastUsed,
+ "USER_UPDATED_AT", userUpdatedAt);
}
private void insertOrgQProfile(String uuid, String orgUuid, String rulesProfileUuid) {
@@ -106,8 +108,7 @@ public class PopulateOrgQProfilesTest {
"RULES_PROFILE_UUID", rulesProfileUuid,
"UUID", uuid,
"CREATED_AT", system2.now(),
- "UPDATED_AT", system2.now()
- );
+ "UPDATED_AT", system2.now());
}
private Map<String, Object> selectOrgQProfile(String uuid, String orgUuid) {
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/UpdateOrgQProfilesToPointToBuiltInProfilesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/UpdateOrgQProfilesToPointToBuiltInProfilesTest.java
index c05b3738698..5e1c5abecea 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/UpdateOrgQProfilesToPointToBuiltInProfilesTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/UpdateOrgQProfilesToPointToBuiltInProfilesTest.java
@@ -181,13 +181,13 @@ public class UpdateOrgQProfilesToPointToBuiltInProfilesTest {
"UUID", orgQProfileUuid,
"RULES_PROFILE_UUID", rulesProfileUuid,
"CREATED_AT", 1_000L,
- "UPDATED_AT", 2_000L);
+ "UPDATED_AT", 2_000L,
+ "USER_UPDATED_AT", userUpdatedAt);
db.executeInsert("RULES_PROFILES",
"NAME", name,
"KEE", rulesProfileUuid,
"LANGUAGE", language,
- "IS_BUILT_IN", isBuiltIn,
- "USER_UPDATED_AT", userUpdatedAt);
+ "IS_BUILT_IN", isBuiltIn);
}
private void insertOrgQProfile(String orgUuid, String orgQProfileUuid, String rulesProfileUuid) {
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/DropOrgColumnsFromRulesProfilesTest/initial.sql
index 7c1c1fedab0..7c1c1fedab0 100644
--- 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/DropOrgColumnsFromRulesProfilesTest/initial.sql
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest/initial.sql
index 3d84b4a125f..2990757445e 100644
--- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest/initial.sql
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest/initial.sql
@@ -7,10 +7,10 @@ CREATE TABLE "RULES_PROFILES" (
"PARENT_KEE" VARCHAR(255),
"RULES_UPDATED_AT" VARCHAR(100),
"IS_DEFAULT" BOOLEAN NOT NULL DEFAULT FALSE,
- "CREATED_AT" TIMESTAMP,
- "UPDATED_AT" TIMESTAMP,
"LAST_USED" BIGINT,
"USER_UPDATED_AT" BIGINT,
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP,
"IS_BUILT_IN" BOOLEAN NOT NULL
);
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE");
@@ -20,6 +20,8 @@ CREATE TABLE "ORG_QPROFILES" (
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"RULES_PROFILE_UUID" VARCHAR(40) NOT NULL,
"PARENT_UUID" VARCHAR(40),
+ "LAST_USED" BIGINT,
+ "USER_UPDATED_AT" BIGINT,
"CREATED_AT" BIGINT NOT NULL,
"UPDATED_AT" BIGINT NOT NULL
);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/UpdateOrgQProfilesToPointToBuiltInProfilesTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/UpdateOrgQProfilesToPointToBuiltInProfilesTest/initial.sql
index 9b45fa47769..1cd770393e1 100644
--- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/UpdateOrgQProfilesToPointToBuiltInProfilesTest/initial.sql
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/UpdateOrgQProfilesToPointToBuiltInProfilesTest/initial.sql
@@ -6,8 +6,6 @@ CREATE TABLE "RULES_PROFILES" (
"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");
@@ -17,6 +15,8 @@ CREATE TABLE "ORG_QPROFILES" (
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"RULES_PROFILE_UUID" VARCHAR(40) NOT NULL,
"PARENT_UUID" VARCHAR(40),
+ "LAST_USED" BIGINT,
+ "USER_UPDATED_AT" BIGINT,
"CREATED_AT" BIGINT NOT NULL,
"UPDATED_AT" BIGINT NOT NULL
);