aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/OrgQProfileDto.java26
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java28
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml18
-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
16 files changed, 86 insertions, 69 deletions
diff --git a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
index eda17e61f32..3947300eb40 100644
--- a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
+++ b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
@@ -51,8 +51,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");
@@ -63,6 +61,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-dao/src/main/java/org/sonar/db/qualityprofile/OrgQProfileDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/OrgQProfileDto.java
index c7c2ffe1d37..479e14e37ef 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/OrgQProfileDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/OrgQProfileDto.java
@@ -31,6 +31,8 @@ public class OrgQProfileDto {
private String organizationUuid;
private String rulesProfileUuid;
private String parentUuid;
+ private Long lastUsed;
+ private Long userUpdatedAt;
public String getOrganizationUuid() {
return organizationUuid;
@@ -69,11 +71,33 @@ public class OrgQProfileDto {
return this;
}
+ @CheckForNull
+ public Long getLastUsed() {
+ return lastUsed;
+ }
+
+ public OrgQProfileDto setLastUsed(@Nullable Long lastUsed) {
+ this.lastUsed = lastUsed;
+ return this;
+ }
+
+ @CheckForNull
+ public Long getUserUpdatedAt() {
+ return userUpdatedAt;
+ }
+
+ public OrgQProfileDto setUserUpdatedAt(@Nullable Long userUpdatedAt) {
+ this.userUpdatedAt = userUpdatedAt;
+ return this;
+ }
+
public static OrgQProfileDto from(QProfileDto qProfileDto) {
return new OrgQProfileDto()
.setUuid(qProfileDto.getKee())
.setOrganizationUuid(qProfileDto.getOrganizationUuid())
.setRulesProfileUuid(qProfileDto.getRulesProfileUuid())
- .setParentUuid(qProfileDto.getParentKee());
+ .setParentUuid(qProfileDto.getParentKee())
+ .setLastUsed(qProfileDto.getLastUsed())
+ .setUserUpdatedAt(qProfileDto.getUserUpdatedAt());
}
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java
index 385ce1b6629..69e0176d044 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java
@@ -165,7 +165,7 @@ public class QProfileDto {
.setLanguage(rules.getLanguage())
.setName(rules.getName())
.setRulesUpdatedAt(rules.getRulesUpdatedAt())
- .setLastUsed(rules.getLastUsed())
- .setUserUpdatedAt(rules.getUserUpdatedAt());
+ .setLastUsed(org.getLastUsed())
+ .setUserUpdatedAt(org.getUserUpdatedAt());
}
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java
index ae487c75411..b1d2ad5a95d 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java
@@ -20,8 +20,6 @@
package org.sonar.db.qualityprofile;
import java.util.Date;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
import org.sonar.core.util.UtcDateUtils;
/**
@@ -34,8 +32,6 @@ public class RulesProfileDto {
private String name;
private String language;
private String rulesUpdatedAt;
- private Long lastUsed;
- private Long userUpdatedAt;
private boolean isBuiltIn;
public String getKee() {
@@ -88,26 +84,6 @@ public class RulesProfileDto {
return this;
}
- @CheckForNull
- public Long getLastUsed() {
- return lastUsed;
- }
-
- public RulesProfileDto setLastUsed(@Nullable Long lastUsed) {
- this.lastUsed = lastUsed;
- return this;
- }
-
- @CheckForNull
- public Long getUserUpdatedAt() {
- return userUpdatedAt;
- }
-
- public RulesProfileDto setUserUpdatedAt(@Nullable Long userUpdatedAt) {
- this.userUpdatedAt = userUpdatedAt;
- return this;
- }
-
public boolean isBuiltIn() {
return isBuiltIn;
}
@@ -124,8 +100,6 @@ public class RulesProfileDto {
.setName(qProfileDto.getName())
.setIsBuiltIn(qProfileDto.isBuiltIn())
.setId(qProfileDto.getId())
- .setLastUsed(qProfileDto.getLastUsed())
- .setRulesUpdatedAt(qProfileDto.getRulesUpdatedAt())
- .setUserUpdatedAt(qProfileDto.getUserUpdatedAt());
+ .setRulesUpdatedAt(qProfileDto.getRulesUpdatedAt());
}
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
index b09d6fc0f97..35b8cbdfcb0 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
@@ -7,13 +7,13 @@
oqp.uuid as kee,
oqp.organization_uuid as organizationUuid,
oqp.parent_uuid as parentKee,
+ oqp.last_used as lastUsed,
+ oqp.user_updated_at as userUpdatedAt,
rp.id as id,
rp.kee as rulesProfileUuid,
rp.name as name,
rp.language as language,
rp.rules_updated_at as rulesUpdatedAt,
- rp.last_used as lastUsed,
- rp.user_updated_at as userUpdatedAt,
rp.is_built_in as isBuiltIn
</sql>
@@ -23,8 +23,6 @@
rp.name as name,
rp.language as language,
rp.rules_updated_at as rulesUpdatedAt,
- rp.last_used as lastUsed,
- rp.user_updated_at as userUpdatedAt,
rp.is_built_in as isBuiltIn
</sql>
@@ -36,8 +34,6 @@
created_at,
updated_at,
rules_updated_at,
- last_used,
- user_updated_at,
is_built_in
) values (
#{dto.kee, jdbcType=VARCHAR},
@@ -46,8 +42,6 @@
#{now, jdbcType=TIMESTAMP},
#{now, jdbcType=TIMESTAMP},
#{dto.rulesUpdatedAt, jdbcType=VARCHAR},
- #{dto.lastUsed, jdbcType=BIGINT},
- #{dto.userUpdatedAt, jdbcType=BIGINT},
#{dto.isBuiltIn, jdbcType=BOOLEAN}
)
</insert>
@@ -58,6 +52,8 @@
organization_uuid,
rules_profile_uuid,
parent_uuid,
+ last_used,
+ user_updated_at,
created_at,
updated_at
) values (
@@ -65,6 +61,8 @@
#{dto.organizationUuid, jdbcType=VARCHAR},
#{dto.rulesProfileUuid, jdbcType=VARCHAR},
#{dto.parentUuid, jdbcType=VARCHAR},
+ #{dto.lastUsed, jdbcType=BIGINT},
+ #{dto.userUpdatedAt, jdbcType=BIGINT},
#{now, jdbcType=BIGINT},
#{now, jdbcType=BIGINT}
)
@@ -77,8 +75,6 @@
language = #{dto.language, jdbcType=VARCHAR},
updated_at = #{now, jdbcType=TIMESTAMP},
rules_updated_at = #{dto.rulesUpdatedAt, jdbcType=VARCHAR},
- last_used = #{dto.lastUsed, jdbcType=BIGINT},
- user_updated_at = #{dto.userUpdatedAt, jdbcType=BIGINT},
is_built_in = #{dto.isBuiltIn, jdbcType=BOOLEAN}
where
kee = #{dto.rulesProfileUuid, jdbcType=VARCHAR}
@@ -88,6 +84,8 @@
update org_qprofiles
set
parent_uuid = #{dto.parentKee, jdbcType=VARCHAR},
+ last_used = #{dto.lastUsed, jdbcType=BIGINT},
+ user_updated_at = #{dto.userUpdatedAt, jdbcType=BIGINT},
updated_at = #{now, jdbcType=BIGINT}
where
uuid = #{dto.kee, jdbcType=VARCHAR}
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
);