// Switch snapshot and purge
SwitchSnapshotStep.class,
+ UpdateQualityProfilesLastUsedDateStep.class,
IndexComponentsStep.class,
PurgeDatastoresStep.class,
ApplyPermissionsStep.class,
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.computation.step;
+
+import com.google.common.base.Optional;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.qualityprofile.QualityProfileDto;
+import org.sonar.server.computation.analysis.AnalysisMetadataHolder;
+import org.sonar.server.computation.component.Component;
+import org.sonar.server.computation.component.TreeRootHolder;
+import org.sonar.server.computation.measure.Measure;
+import org.sonar.server.computation.measure.MeasureRepository;
+import org.sonar.server.computation.metric.Metric;
+import org.sonar.server.computation.metric.MetricRepository;
+import org.sonar.server.computation.qualityprofile.QPMeasureData;
+import org.sonar.server.computation.qualityprofile.QualityProfile;
+
+import static java.util.Collections.emptySet;
+
+public class UpdateQualityProfilesLastUsedDateStep implements ComputationStep {
+
+ private final DbClient dbClient;
+ private final AnalysisMetadataHolder analysisMetadataHolder;
+ private final TreeRootHolder treeRootHolder;
+ private final MetricRepository metricRepository;
+ private final MeasureRepository measureRepository;
+
+ public UpdateQualityProfilesLastUsedDateStep(DbClient dbClient, AnalysisMetadataHolder analysisMetadataHolder, TreeRootHolder treeRootHolder, MetricRepository metricRepository,
+ MeasureRepository measureRepository) {
+ this.dbClient = dbClient;
+ this.analysisMetadataHolder = analysisMetadataHolder;
+ this.treeRootHolder = treeRootHolder;
+ this.metricRepository = metricRepository;
+ this.measureRepository = measureRepository;
+ }
+
+ @Override
+ public void execute() {
+ DbSession dbSession = dbClient.openSession(true);
+ try {
+ Component root = treeRootHolder.getRoot();
+ Metric metric = metricRepository.getByKey(CoreMetrics.QUALITY_PROFILES_KEY);
+ Set<QualityProfile> qualityProfiles = parseQualityProfiles(measureRepository.getRawMeasure(root, metric));
+ if (qualityProfiles.isEmpty()) {
+ return;
+ }
+
+ List<QualityProfileDto> dtos = dbClient.qualityProfileDao().selectByKeys(dbSession, qualityProfiles.stream().map(QualityProfile::getQpKey).collect(Collectors.toList()));
+ long analysisDate = analysisMetadataHolder.getAnalysisDate();
+ dtos.forEach(dto -> {
+ dto.setLastUsed(analysisDate);
+ dbClient.qualityProfileDao().update(dbSession, dto);
+ });
+
+ dbSession.commit();
+ } finally {
+ dbClient.closeSession(dbSession);
+ }
+ }
+
+ @Override
+ public String getDescription() {
+ return "Update quality profiles";
+ }
+
+ private static Set<QualityProfile> parseQualityProfiles(Optional<Measure> measure) {
+ if (!measure.isPresent()) {
+ return emptySet();
+ }
+
+ String data = measure.get().getStringValue();
+ return data == null ? emptySet() : QPMeasureData.fromJson(data).getProfiles();
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.computation.step;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.stream.Collectors;
+import javax.annotation.CheckForNull;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.measures.Metric;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.qualityprofile.QualityProfileDbTester;
+import org.sonar.db.qualityprofile.QualityProfileDto;
+import org.sonar.server.computation.analysis.AnalysisMetadataHolderRule;
+import org.sonar.server.computation.batch.TreeRootHolderRule;
+import org.sonar.server.computation.component.Component;
+import org.sonar.server.computation.component.ReportComponent;
+import org.sonar.server.computation.measure.Measure;
+import org.sonar.server.computation.measure.MeasureRepositoryRule;
+import org.sonar.server.computation.metric.Metric.MetricType;
+import org.sonar.server.computation.metric.MetricImpl;
+import org.sonar.server.computation.metric.MetricRepositoryRule;
+import org.sonar.server.computation.qualityprofile.QPMeasureData;
+import org.sonar.server.computation.qualityprofile.QualityProfile;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.api.measures.CoreMetrics.QUALITY_PROFILES_KEY;
+import static org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto;
+
+public class UpdateQualityProfilesLastUsedDateStepTest {
+ static final long ANALYSIS_DATE = 1_123_456_789L;
+ private static final Component PROJECT = ReportComponent.DUMB_PROJECT;
+ private QualityProfileDto sonarWayJava = newQualityProfileDto().setKey("sonar-way-java");
+ private QualityProfileDto sonarWayPhp = newQualityProfileDto().setKey("sonar-way-php");
+ private QualityProfileDto myQualityProfile = newQualityProfileDto().setKey("my-qp");
+
+ @Rule
+ public DbTester db = DbTester.create(System2.INSTANCE);
+ DbClient dbClient = db.getDbClient();
+ DbSession dbSession = db.getSession();
+ QualityProfileDbTester qualityProfileDb = new QualityProfileDbTester(db);
+ @Rule
+ public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
+ @Rule
+ public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
+ @Rule
+ public MetricRepositoryRule metricRepository = new MetricRepositoryRule();
+ @Rule
+ public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository);
+
+ UpdateQualityProfilesLastUsedDateStep underTest;
+
+ @Before
+ public void setUp() {
+ underTest = new UpdateQualityProfilesLastUsedDateStep(dbClient, analysisMetadataHolder, treeRootHolder, metricRepository, measureRepository);
+ analysisMetadataHolder.setAnalysisDate(ANALYSIS_DATE);
+ treeRootHolder.setRoot(PROJECT);
+ Metric<String> metric = CoreMetrics.QUALITY_PROFILES;
+ metricRepository.add(new MetricImpl(1, metric.getKey(), metric.getName(), MetricType.STRING));
+
+ qualityProfileDb.insertQualityProfiles(sonarWayJava, sonarWayPhp, myQualityProfile);
+ }
+
+ @Test
+ public void project_without_quality_profiles() {
+ underTest.execute();
+
+ assertQualityProfileIsTheSame(sonarWayJava);
+ assertQualityProfileIsTheSame(sonarWayPhp);
+ assertQualityProfileIsTheSame(myQualityProfile);
+ }
+
+ @Test
+ public void analysis_quality_profiles_are_updated() {
+ measureRepository.addRawMeasure(1, QUALITY_PROFILES_KEY, Measure.newMeasureBuilder().create(
+ toJson(sonarWayJava.getKey(), myQualityProfile.getKey())));
+
+ underTest.execute();
+
+ assertQualityProfileIsTheSame(sonarWayPhp);
+ assertQualityProfileIsUpdated(sonarWayJava);
+ assertQualityProfileIsUpdated(myQualityProfile);
+ }
+
+ @Test
+ public void description() {
+ assertThat(underTest.getDescription()).isEqualTo("Update quality profiles");
+ }
+
+ private void assertQualityProfileIsUpdated(QualityProfileDto qp) {
+ assertThat(selectLastUser(qp.getKey())).withFailMessage("Quality profile '%s' hasn't been updated. Value: %d", qp.getKey(), qp.getLastUsed()).isEqualTo(ANALYSIS_DATE);
+ }
+
+ private void assertQualityProfileIsTheSame(QualityProfileDto qp) {
+ assertThat(selectLastUser(qp.getKey())).isEqualTo(qp.getLastUsed());
+ }
+
+ @CheckForNull
+ private Long selectLastUser(String qualityProfileKey) {
+ return dbClient.qualityProfileDao().selectByKey(dbSession, qualityProfileKey).getLastUsed();
+ }
+
+ private static String toJson(String... keys) {
+ return QPMeasureData.toJson(new QPMeasureData(
+ Arrays.stream(keys)
+ .map(key -> new QualityProfile(key, key, key, new Date()))
+ .collect(Collectors.toList())));
+ }
+}
--- /dev/null
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube 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.
+#
+# SonarQube 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.
+#
+#
+# SonarQube 6.0
+# SONAR-7789
+#
+class AddLastUsedColumnToRulesProfiles < ActiveRecord::Migration
+ def self.up
+ execute_java_migration('org.sonar.db.version.v60.AddLastUsedColumnToRulesProfiles')
+ end
+end
--- /dev/null
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube 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.
+#
+# SonarQube 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.
+#
+#
+# SonarQube 6.0
+# SONAR-7789
+#
+class PopulateLastUsedOfRulesProfiles < ActiveRecord::Migration
+ def self.up
+ execute_java_migration('org.sonar.db.version.v60.PopulateLastUsedColumnOfRulesProfiles')
+ end
+end
return dto;
}
+ public List<QualityProfileDto> selectByKeys(DbSession session, List<String> keys) {
+ return executeLargeInputs(keys, mapper(session)::selectByKeys);
+ }
+
public List<QualityProfileDto> selectAll(DbSession session) {
return mapper(session).selectAll();
}
private String language;
private String parentKee;
private String rulesUpdatedAt;
+ private Long lastUsed;
private boolean isDefault;
/**
return this;
}
+ @CheckForNull
+ public Long getLastUsed() {
+ return lastUsed;
+ }
+
+ public QualityProfileDto setLastUsed(@Nullable Long lastUsed) {
+ this.lastUsed = lastUsed;
+ return this;
+ }
+
public boolean isDefault() {
return isDefault;
}
List<QualityProfileDto> selectByLanguage(String language);
+ List<QualityProfileDto> selectByKeys(@Param("keys") List<String> keys);
+
// INHERITANCE
@CheckForNull
public class DatabaseVersion {
- public static final int LAST_VERSION = 1_245;
+ public static final int LAST_VERSION = 1_247;
/**
* The minimum supported version which can be upgraded. Lower
"user_roles",
"user_tokens",
"widgets",
- "widget_properties"
- );
+ "widget_properties");
private MyBatis mybatis;
public DatabaseVersion(MyBatis mybatis) {
import org.sonar.db.version.v60.AddComponentUuidColumnToDuplicationsIndex;
import org.sonar.db.version.v60.AddComponentUuidColumnToMeasures;
import org.sonar.db.version.v60.AddComponentUuidColumnsToSnapshots;
+import org.sonar.db.version.v60.AddLastUsedColumnToRulesProfiles;
import org.sonar.db.version.v60.AddUuidColumnToSnapshots;
import org.sonar.db.version.v60.AddUuidColumnsToProjects;
import org.sonar.db.version.v60.AddUuidColumnsToResourceIndex;
import org.sonar.db.version.v60.PopulateComponentUuidColumnsOfSnapshots;
import org.sonar.db.version.v60.PopulateComponentUuidOfDuplicationsIndex;
import org.sonar.db.version.v60.PopulateComponentUuidOfMeasures;
+import org.sonar.db.version.v60.PopulateLastUsedColumnOfRulesProfiles;
import org.sonar.db.version.v60.PopulateUuidColumnOnSnapshots;
import org.sonar.db.version.v60.PopulateUuidColumnsOfProjects;
import org.sonar.db.version.v60.PopulateUuidColumnsOfResourceIndex;
CleanOrphanRowsInProjects.class,
MakeUuidColumnsNotNullOnProjects.class,
DropIdColumnsFromProjects.class,
+ AddLastUsedColumnToRulesProfiles.class,
+ PopulateLastUsedColumnOfRulesProfiles.class,
// SNAPSHOTS.UUID
AddUuidColumnToSnapshots.class,
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.db.version.v60;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.version.AddColumnsBuilder;
+import org.sonar.db.version.DdlChange;
+
+import static org.sonar.db.version.BigDecimalColumnDef.newBigDecimalColumnDefBuilder;
+
+public class AddLastUsedColumnToRulesProfiles extends DdlChange {
+
+ private static final String TABLE_QUALITY_PROFILES = "rules_profiles";
+
+ public AddLastUsedColumnToRulesProfiles(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_QUALITY_PROFILES)
+ .addColumn(newBigDecimalColumnDefBuilder().setColumnName("last_used").setIsNullable(true).build())
+ .build());
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.db.version.v60;
+
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.sonar.db.Database;
+import org.sonar.db.version.BaseDataChange;
+import org.sonar.db.version.MassUpdate;
+import org.sonar.db.version.Select;
+import org.sonar.db.version.SqlStatement;
+
+public class PopulateLastUsedColumnOfRulesProfiles extends BaseDataChange {
+
+ private static final Pattern PATTERN_QP_KEY = Pattern.compile("\"key\"\\s*:\\s*\"(.*?)\"");
+
+ public PopulateLastUsedColumnOfRulesProfiles(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ Map<String, Long> lastAnalysisDatesByQualityProfileKey = buildQualityProfilesMap(context);
+ if (lastAnalysisDatesByQualityProfileKey.isEmpty()) {
+ return;
+ }
+
+ populateLastUsedColumn(context, lastAnalysisDatesByQualityProfileKey);
+ }
+
+ private static Map<String, Long> buildQualityProfilesMap(Context context) throws SQLException {
+ Map<String, Long> lastAnalysisDatesByQPKeys = new HashMap<>();
+
+ context.prepareSelect("select s.created_at, pm.text_value " +
+ "from project_measures pm " +
+ " inner join snapshots s on pm.snapshot_id = s.id " +
+ " inner join metrics m on pm.metric_id=m.id " +
+ "where s.islast=? " +
+ " and m.name='quality_profiles' " +
+ "order by s.created_at ")
+ .setBoolean(1, true)
+ .scroll(row -> {
+ long analysisDate = row.getLong(1);
+ String json = row.getString(2);
+ Matcher matcher = PATTERN_QP_KEY.matcher(json);
+ while (matcher.find()) {
+ lastAnalysisDatesByQPKeys.put(matcher.group(1), analysisDate);
+ }
+ });
+ return lastAnalysisDatesByQPKeys;
+ }
+
+ private static void populateLastUsedColumn(Context context, Map<String, Long> lastAnalysisDatesByQualityProfileKey) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+ massUpdate.select("select id, kee from rules_profiles where last_used is null");
+ massUpdate.update("update rules_profiles set last_used=? where id=?");
+ massUpdate.rowPluralName("rules_profiles");
+ massUpdate.execute((row, update) -> handle(lastAnalysisDatesByQualityProfileKey, row, update));
+ }
+
+ private static boolean handle(Map<String, Long> lastAnalysisDatesByQualityProfileKey, Select.Row row, SqlStatement update) throws SQLException {
+ int qualityProfileId = row.getInt(1);
+ String qualityProfileKey = row.getString(2);
+
+ update.setLong(1, lastAnalysisDatesByQualityProfileKey.get(qualityProfileKey));
+ update.setInt(2, qualityProfileId);
+
+ return true;
+ }
+}
p.is_default as isDefault,
p.created_at as createdAt,
p.updated_at as updatedAt,
- p.rules_updated_at as rulesUpdatedAt
+ p.rules_updated_at as rulesUpdatedAt,
+ p.last_used as lastUsed
</sql>
<insert id="insert" parameterType="QualityProfile" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
- INSERT INTO rules_profiles (kee, parent_kee, name, language, is_default, created_at, updated_at, rules_updated_at)
- VALUES (#{kee}, #{parentKee}, #{name}, #{language}, #{isDefault}, #{createdAt}, #{updatedAt}, #{rulesUpdatedAt,})
+ INSERT INTO rules_profiles (kee, parent_kee, name, language, is_default, created_at, updated_at, rules_updated_at, last_used)
+ VALUES (#{kee, jdbcType=VARCHAR}, #{parentKee,jdbcType=VARCHAR}, #{name, jdbcType=VARCHAR}, #{language, jdbcType=VARCHAR}, #{isDefault, jdbcType=BOOLEAN},
+ #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP}, #{rulesUpdatedAt, jdbcType=VARCHAR}, #{lastUsed, jdbcType=BIGINT})
</insert>
<update id="update" parameterType="QualityProfile">
UPDATE rules_profiles SET
- name=#{name},
- language=#{language},
- is_default=#{isDefault},
- parent_kee=#{parentKee},
- updated_at=#{updatedAt},
- rules_updated_at=#{rulesUpdatedAt}
+ name=#{name, jdbcType=VARCHAR},
+ language=#{language, jdbcType=VARCHAR},
+ is_default=#{isDefault, jdbcType=BOOLEAN},
+ parent_kee=#{parentKee, jdbcType=VARCHAR},
+ updated_at=#{updatedAt, jdbcType=TIMESTAMP},
+ rules_updated_at=#{rulesUpdatedAt, jdbcType=VARCHAR},
+ last_used=#{lastUsed, jdbcType=BIGINT}
WHERE id=#{id}
</update>
WHERE p.kee=#{id}
</select>
+ <select id="selectByKeys" parameterType="string" resultType="QualityProfile">
+ SELECT
+ <include refid="profilesColumns"/>
+ FROM rules_profiles p
+ WHERE p.kee in
+ <foreach collection="keys" open="(" close=")" item="key" separator=",">
+ #{key}
+ </foreach>
+ </select>
+
<select id="selectByLanguage" parameterType="String" resultType="QualityProfile">
SELECT
<include refid="profilesColumns"/>
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1243');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1244');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1245');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1246');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1247');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482');
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
"RULES_UPDATED_AT" VARCHAR(100),
"IS_DEFAULT" BOOLEAN NOT NULL DEFAULT FALSE,
"CREATED_AT" TIMESTAMP,
- "UPDATED_AT" TIMESTAMP
+ "UPDATED_AT" TIMESTAMP,
+ "LAST_USED" BIGINT
);
CREATE TABLE "PROJECT_QPROFILES" (
import org.junit.Test;
import org.sonar.api.utils.System2;
import org.sonar.core.util.UtcDateUtils;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import static com.google.common.collect.ImmutableList.of;
+import static com.google.common.collect.Lists.newArrayList;
+import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-
+import static org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto;
public class QualityProfileDaoTest {
@Rule
public DbTester dbTester = DbTester.create(system);
+ DbClient dbClient = dbTester.getDbClient();
+ DbSession dbSession = dbTester.getSession();
+ QualityProfileDbTester qualityProfileDb = new QualityProfileDbTester(dbTester);
- QualityProfileDao dao = dbTester.getDbClient().qualityProfileDao();
+ QualityProfileDao underTest = dbTester.getDbClient().qualityProfileDao();
@Before
public void createDao() {
.setName("ABCDE")
.setLanguage("xoo");
- dao.insert(dto);
+ underTest.insert(dto);
- dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[]{"created_at", "updated_at", "rules_updated_at"}, "rules_profiles");
+ dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[] {"created_at", "updated_at", "rules_updated_at"}, "rules_profiles");
}
@Test
.setParentKee("fghij")
.setDefault(false);
- dao.update(dto);
+ underTest.update(dto);
- dbTester.assertDbUnit(getClass(), "update-result.xml", new String[]{"created_at", "updated_at", "rules_updated_at"}, "rules_profiles");
+ dbTester.assertDbUnit(getClass(), "update-result.xml", new String[] {"created_at", "updated_at", "rules_updated_at"}, "rules_profiles");
}
@Test
public void delete() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
- dao.delete(1);
+ underTest.delete(1);
dbTester.assertDbUnit(getClass(), "delete-result.xml", "rules_profiles");
}
public void find_all() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
- List<QualityProfileDto> dtos = dao.selectAll(dbTester.getSession());
+ List<QualityProfileDto> dtos = underTest.selectAll(dbTester.getSession());
assertThat(dtos).hasSize(2);
public void find_all_is_sorted_by_profile_name() {
dbTester.prepareDbUnit(getClass(), "select_all_is_sorted_by_profile_name.xml");
- List<QualityProfileDto> dtos = dao.selectAll();
+ List<QualityProfileDto> dtos = underTest.selectAll();
assertThat(dtos).hasSize(3);
assertThat(dtos.get(0).getName()).isEqualTo("First");
public void get_default_profile() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
- QualityProfileDto java = dao.selectDefaultProfile("java");
+ QualityProfileDto java = underTest.selectDefaultProfile("java");
assertThat(java).isNotNull();
assertThat(java.getKey()).isEqualTo("java_sonar_way");
- assertThat(dao.selectDefaultProfile("js")).isNull();
+ assertThat(underTest.selectDefaultProfile("js")).isNull();
}
@Test
public void get_default_profiles() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
- List<QualityProfileDto> java = dao.selectDefaultProfiles(dbTester.getSession(), singletonList("java"));
+ List<QualityProfileDto> java = underTest.selectDefaultProfiles(dbTester.getSession(), singletonList("java"));
assertThat(java).extracting("key").containsOnly("java_sonar_way");
- assertThat(dao.selectDefaultProfiles(dbTester.getSession(), singletonList("js"))).isEmpty();
- assertThat(dao.selectDefaultProfiles(dbTester.getSession(), of("java", "js"))).extracting("key").containsOnly("java_sonar_way");
- assertThat(dao.selectDefaultProfiles(dbTester.getSession(), of("js", "java"))).extracting("key").containsOnly("java_sonar_way");
+ assertThat(underTest.selectDefaultProfiles(dbTester.getSession(), singletonList("js"))).isEmpty();
+ assertThat(underTest.selectDefaultProfiles(dbTester.getSession(), of("java", "js"))).extracting("key").containsOnly("java_sonar_way");
+ assertThat(underTest.selectDefaultProfiles(dbTester.getSession(), of("js", "java"))).extracting("key").containsOnly("java_sonar_way");
}
@Test
public void get_by_name_and_language() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
- QualityProfileDto dto = dao.selectByNameAndLanguage("Sonar Way", "java", dbTester.getSession());
+ QualityProfileDto dto = underTest.selectByNameAndLanguage("Sonar Way", "java", dbTester.getSession());
assertThat(dto.getId()).isEqualTo(1);
assertThat(dto.getName()).isEqualTo("Sonar Way");
assertThat(dto.getLanguage()).isEqualTo("java");
assertThat(dto.getParentKee()).isNull();
- assertThat(dao.selectByNameAndLanguage("Sonar Way", "java", dbTester.getSession())).isNotNull();
- assertThat(dao.selectByNameAndLanguage("Sonar Way", "unknown", dbTester.getSession())).isNull();
+ assertThat(underTest.selectByNameAndLanguage("Sonar Way", "java", dbTester.getSession())).isNotNull();
+ assertThat(underTest.selectByNameAndLanguage("Sonar Way", "unknown", dbTester.getSession())).isNull();
}
@Test
public void get_by_name_and_languages() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
- List<QualityProfileDto> dtos = dao.selectByNameAndLanguages("Sonar Way", singletonList("java"), dbTester.getSession());
+ List<QualityProfileDto> dtos = underTest.selectByNameAndLanguages("Sonar Way", singletonList("java"), dbTester.getSession());
assertThat(dtos).hasSize(1);
QualityProfileDto dto = dtos.iterator().next();
assertThat(dto.getId()).isEqualTo(1);
assertThat(dto.getLanguage()).isEqualTo("java");
assertThat(dto.getParentKee()).isNull();
- assertThat(dao.selectByNameAndLanguages("Sonar Way", singletonList("unknown"), dbTester.getSession())).isEmpty();
- assertThat(dao.selectByNameAndLanguages("Sonar Way", of("java", "unknown"), dbTester.getSession())).extracting("id").containsOnly(1);
+ assertThat(underTest.selectByNameAndLanguages("Sonar Way", singletonList("unknown"), dbTester.getSession())).isEmpty();
+ assertThat(underTest.selectByNameAndLanguages("Sonar Way", of("java", "unknown"), dbTester.getSession())).extracting("id").containsOnly(1);
}
@Test
public void find_by_language() {
dbTester.prepareDbUnit(getClass(), "select_by_language.xml");
- List<QualityProfileDto> result = dao.selectByLanguage("java");
+ List<QualityProfileDto> result = underTest.selectByLanguage("java");
assertThat(result).hasSize(2);
assertThat(result.get(0).getName()).isEqualTo("Sonar Way 1");
assertThat(result.get(1).getName()).isEqualTo("Sonar Way 2");
public void get_by_id() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
- QualityProfileDto dto = dao.selectById(1);
+ QualityProfileDto dto = underTest.selectById(1);
assertThat(dto.getId()).isEqualTo(1);
assertThat(dto.getName()).isEqualTo("Sonar Way");
assertThat(dto.getLanguage()).isEqualTo("java");
assertThat(dto.getParentKee()).isNull();
- assertThat(dao.selectById(555)).isNull();
+ assertThat(underTest.selectById(555)).isNull();
}
@Test
public void get_parent_by_id() {
dbTester.prepareDbUnit(getClass(), "inheritance.xml");
- QualityProfileDto dto = dao.selectParentById(1);
+ QualityProfileDto dto = underTest.selectParentById(1);
assertThat(dto.getId()).isEqualTo(3);
}
public void find_children() {
dbTester.prepareDbUnit(getClass(), "inheritance.xml");
- List<QualityProfileDto> dtos = dao.selectChildren(dbTester.getSession(), "java_parent");
+ List<QualityProfileDto> dtos = underTest.selectChildren(dbTester.getSession(), "java_parent");
assertThat(dtos).hasSize(2);
public void select_projects() {
dbTester.prepareDbUnit(getClass(), "projects.xml");
- assertThat(dao.selectProjects("Sonar Way", "java")).hasSize(2);
+ assertThat(underTest.selectProjects("Sonar Way", "java")).hasSize(2);
}
@Test
public void count_projects() {
dbTester.prepareDbUnit(getClass(), "projects.xml");
- assertThat(dao.countProjects("Sonar Way", "java")).isEqualTo(2);
+ assertThat(underTest.countProjects("Sonar Way", "java")).isEqualTo(2);
}
@Test
public void count_projects_by_profile() {
dbTester.prepareDbUnit(getClass(), "projects.xml");
- assertThat(dao.countProjectsByProfileKey()).containsOnly(
+ assertThat(underTest.countProjectsByProfileKey()).containsOnly(
MapEntry.entry("java_sonar_way", 2L),
MapEntry.entry("js_sonar_way", 2L));
}
public void select_by_project_id_and_language() {
dbTester.prepareDbUnit(getClass(), "projects.xml");
- QualityProfileDto dto = dao.selectByProjectAndLanguage(1L, "java");
+ QualityProfileDto dto = underTest.selectByProjectAndLanguage(1L, "java");
assertThat(dto.getId()).isEqualTo(1);
}
public void select_by_project_key_and_language() {
dbTester.prepareDbUnit(getClass(), "projects.xml");
- QualityProfileDto dto = dao.selectByProjectAndLanguage(dbTester.getSession(), "org.codehaus.sonar:sonar", "java");
+ QualityProfileDto dto = underTest.selectByProjectAndLanguage(dbTester.getSession(), "org.codehaus.sonar:sonar", "java");
assertThat(dto.getId()).isEqualTo(1);
- assertThat(dao.selectByProjectAndLanguage(dbTester.getSession(), "org.codehaus.sonar:sonar", "unkown")).isNull();
- assertThat(dao.selectByProjectAndLanguage(dbTester.getSession(), "unknown", "java")).isNull();
+ assertThat(underTest.selectByProjectAndLanguage(dbTester.getSession(), "org.codehaus.sonar:sonar", "unkown")).isNull();
+ assertThat(underTest.selectByProjectAndLanguage(dbTester.getSession(), "unknown", "java")).isNull();
}
@Test
public void select_by_project_key_and_languages() {
dbTester.prepareDbUnit(getClass(), "projects.xml");
- List<QualityProfileDto> dto = dao.selectByProjectAndLanguages(dbTester.getSession(), "org.codehaus.sonar:sonar", singletonList("java"));
+ List<QualityProfileDto> dto = underTest.selectByProjectAndLanguages(dbTester.getSession(), "org.codehaus.sonar:sonar", singletonList("java"));
assertThat(dto).extracting("id").containsOnly(1);
- assertThat(dao.selectByProjectAndLanguages(dbTester.getSession(), "org.codehaus.sonar:sonar", singletonList("unkown"))).isEmpty();
- assertThat(dao.selectByProjectAndLanguages(dbTester.getSession(), "org.codehaus.sonar:sonar", of("java", "unkown"))).extracting("id").containsOnly(1);
- assertThat(dao.selectByProjectAndLanguages(dbTester.getSession(), "unknown", singletonList("java"))).isEmpty();
+ assertThat(underTest.selectByProjectAndLanguages(dbTester.getSession(), "org.codehaus.sonar:sonar", singletonList("unkown"))).isEmpty();
+ assertThat(underTest.selectByProjectAndLanguages(dbTester.getSession(), "org.codehaus.sonar:sonar", of("java", "unkown"))).extracting("id").containsOnly(1);
+ assertThat(underTest.selectByProjectAndLanguages(dbTester.getSession(), "unknown", singletonList("java"))).isEmpty();
+ }
+
+ @Test
+ public void selectByKeys() {
+ qualityProfileDb.insertQualityProfiles(newQualityProfileDto().setKey("qp-key-1"), newQualityProfileDto().setKee("qp-key-2"), newQualityProfileDto().setKee("qp-key-3"));
+
+ assertThat(underTest.selectOrFailByKey(dbSession, "qp-key-1")).isNotNull();
+ assertThat(underTest.selectByKey(dbSession, "qp-key-1")).isNotNull();
+ assertThat(underTest.selectByKey(dbSession, "qp-key-42")).isNull();
+ assertThat(underTest.selectByKeys(dbSession, newArrayList("qp-key-1", "qp-key-3", "qp-key-42")))
+ .hasSize(2)
+ .extracting(QualityProfileDto::getKey).containsOnlyOnce("qp-key-1", "qp-key-3");
+ assertThat(underTest.selectByKeys(dbSession, emptyList())).isEmpty();
}
}
public void insertQualityProfiles(QualityProfileDto qualityProfile, QualityProfileDto... qualityProfiles) {
dbClient.qualityProfileDao().insert(dbSession, qualityProfile, qualityProfiles);
+ dbSession.commit();
}
public void insertProjectWithQualityProfileAssociations(ComponentDto project, QualityProfileDto... qualityProfiles) {
for (QualityProfileDto qualityProfile : qualityProfiles) {
dbClient.qualityProfileDao().insertProjectProfileAssociation(project.uuid(), qualityProfile.getKey(), dbSession);
}
+
+ dbSession.commit();
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.db.qualityprofile;
+
+import java.util.Date;
+import org.sonar.core.util.Uuids;
+
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
+import static org.apache.commons.lang.math.RandomUtils.nextLong;
+
+public class QualityProfileTesting {
+ public static QualityProfileDto newQualityProfileDto() {
+ String uuid = Uuids.createFast();
+ QualityProfileDto dto = QualityProfileDto.createFor(uuid)
+ .setName(uuid)
+ .setLanguage(randomAlphanumeric(20))
+ .setLastUsed(nextLong());
+ dto.setCreatedAt(new Date())
+ .setUpdatedAt(new Date());
+ return dto;
+ }
+}
public void verify_count_of_added_MigrationStep_types() {
ComponentContainer container = new ComponentContainer();
new MigrationStepModule().configure(container);
- assertThat(container.size()).isEqualTo(102);
+ assertThat(container.size()).isEqualTo(104);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.db.version.v60;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+
+public class AddLastUsedColumnToRulesProfilesTest {
+
+ @Rule
+ public DbTester db = DbTester.createForSchema(System2.INSTANCE, AddLastUsedColumnToRulesProfilesTest.class, "rules_profiles.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private AddLastUsedColumnToRulesProfiles underTest = new AddLastUsedColumnToRulesProfiles(db.database());
+
+ @Test
+ public void migration_adds_column_to_empty_table() throws SQLException {
+ underTest.execute();
+
+ verifyAddedColumns();
+ }
+
+ @Test
+ public void migration_adds_column_to_populated_table() throws SQLException {
+ for (int i = 0; i < 9; i++) {
+ db.executeInsert(
+ "rules_profiles",
+ "name", "NAME_" + i,
+ "language", "java",
+ "kee", "" + i,
+ "rules_updated_at", "2016-06-21");
+ }
+ db.commit();
+
+ underTest.execute();
+
+ verifyAddedColumns();
+ }
+
+ @Test
+ public void migration_is_not_reentrant() throws SQLException {
+ underTest.execute();
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("Fail to execute ");
+ underTest.execute();
+ }
+
+ private void verifyAddedColumns() {
+ db.assertColumnDefinition("rules_profiles", "last_used", Types.BIGINT, null, true);
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.db.version.v60;
+
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.stream.Collectors;
+import javax.annotation.CheckForNull;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+
+import static java.lang.String.valueOf;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PopulateLastUsedColumnOfRulesProfilesTest {
+ private static final String QUALITY_PROFILES_TABLE = "rules_profiles";
+ private static final String METRICS_TABLE = "metrics";
+ private static final String MEASURES_TABLE = "project_measures";
+ private static final String SNAPSHOTS_TABLE = "snapshots";
+ private static final String METRIC_ID = "1";
+
+ @Rule
+ public DbTester db = DbTester.createForSchema(System2.INSTANCE, PopulateLastUsedColumnOfRulesProfilesTest.class, "rules_profiles.sql");
+
+ PopulateLastUsedColumnOfRulesProfiles underTest = new PopulateLastUsedColumnOfRulesProfiles(db.database());
+
+ @Test
+ public void migration_has_no_effect_on_empty_tables() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countRowsOfTable(QUALITY_PROFILES_TABLE)).isEqualTo(0);
+ assertThat(db.countRowsOfTable(METRICS_TABLE)).isEqualTo(0);
+ assertThat(db.countRowsOfTable(MEASURES_TABLE)).isEqualTo(0);
+ assertThat(db.countRowsOfTable(SNAPSHOTS_TABLE)).isEqualTo(0);
+ }
+
+ @Test
+ public void migration_update_quality_profiles_last_used() throws SQLException {
+ insertQualityProfilesMetric();
+ insertQualityProfile(1, "first-quality-profile");
+ insertQualityProfile(2, "second-quality-profile");
+ insertQualityProfile(3, "third-quality-profile");
+ insertQualityProfile(4, "fourth-quality-profile");
+ insertMeasure(1, "first-quality-profile", "second-quality-profile");
+ insertMeasure(2, "second-quality-profile", "third-quality-profile");
+
+ underTest.execute();
+
+ assertLastUsedForQP("first-quality-profile", 1);
+ assertLastUsedForQP("second-quality-profile", 2);
+ assertLastUsedForQP("third-quality-profile", 2);
+ assertNoLastUsedForQP("fourth-quality-profile");
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ insertQualityProfilesMetric();
+ insertQualityProfile(1, "first-quality-profile");
+ insertMeasure(1, "first-quality-profile");
+
+ underTest.execute();
+ assertLastUsedForQP("first-quality-profile", 1);
+
+ underTest.execute();
+ assertLastUsedForQP("first-quality-profile", 1);
+ }
+
+ private void assertLastUsedForQP(String qualityProfileKey, long expectedLastUsed) {
+ assertThat(selectLastUser(qualityProfileKey)).isEqualTo(expectedLastUsed);
+ }
+
+ private void assertNoLastUsedForQP(String qualityProfileKey) {
+ assertThat(selectLastUser(qualityProfileKey)).isNull();
+ }
+
+ @CheckForNull
+ private Long selectLastUser(String qualityProfileKey) {
+ return (Long) db.selectFirst(String.format("select last_used as \"lastUsed\" from rules_profiles where kee ='%s'", qualityProfileKey)).get("lastUsed");
+ }
+
+ private void insertQualityProfile(long id, String key) {
+ db.executeInsert(QUALITY_PROFILES_TABLE,
+ "id", valueOf(id),
+ "name", key,
+ "kee", key);
+ }
+
+ private void insertMeasure(long id, String... keys) {
+ db.executeInsert(
+ SNAPSHOTS_TABLE,
+ "id", valueOf(id),
+ "uuid", valueOf(id),
+ "component_uuid", valueOf(id),
+ "root_component_uuid", valueOf(id),
+ "islast", "TRUE",
+ "created_at", valueOf(id));
+
+ db.executeInsert(
+ MEASURES_TABLE,
+ "id", valueOf(id),
+ "snapshot_id", valueOf(id),
+ "metric_id", METRIC_ID,
+ "component_uuid", valueOf(id),
+ "text_value", toJson(keys));
+ }
+
+ private void insertQualityProfilesMetric() {
+ db.executeInsert(METRICS_TABLE,
+ "id", METRIC_ID,
+ "name", "quality_profiles");
+ }
+
+ private static String toJson(String... keys) {
+ return Arrays.stream(keys).map(key -> "\"key\" : \"" + key + "\"").collect(Collectors.joining(", ", "{", "}"));
+ }
+}
<dataset>
<rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789"/>
</dataset>
<dataset>
<rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way" is_default="[true]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]"/>
<rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789"/>
<rules_profiles id="3" name="ABCDE" language="xoo" parent_kee="[null]" kee="abcde" is_default="[false]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]"/>
</dataset>
<dataset>
<rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way" is_default="[true]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]"/>
<rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789"/>
</dataset>
<dataset>
<rules_profiles id="1" name="New Name" language="js" parent_kee="fghij" kee="java_sonar_way" is_default="[false]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]"/>
<rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789"/>
</dataset>
--- /dev/null
+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),
+ "KEE" VARCHAR(255) NOT NULL,
+ "PARENT_KEE" VARCHAR(255),
+ "RULES_UPDATED_AT" VARCHAR(100),
+ "IS_DEFAULT" BOOLEAN NOT NULL DEFAULT FALSE,
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP
+);
+
+CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE");
--- /dev/null
+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),
+ "KEE" VARCHAR(255) NOT NULL,
+ "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
+);
+
+CREATE TABLE "PROJECT_MEASURES" (
+ "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "VALUE" DOUBLE,
+ "METRIC_ID" INTEGER NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "SNAPSHOT_ID" INTEGER,
+ "TEXT_VALUE" VARCHAR(4000),
+ "ALERT_STATUS" VARCHAR(5),
+ "ALERT_TEXT" VARCHAR(4000),
+ "DESCRIPTION" VARCHAR(4000),
+ "PERSON_ID" INTEGER,
+ "VARIATION_VALUE_1" DOUBLE,
+ "VARIATION_VALUE_2" DOUBLE,
+ "VARIATION_VALUE_3" DOUBLE,
+ "VARIATION_VALUE_4" DOUBLE,
+ "VARIATION_VALUE_5" DOUBLE,
+ "MEASURE_DATA" BINARY(167772150)
+);
+
+CREATE TABLE "SNAPSHOTS" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "UUID" VARCHAR(50) NOT NULL,
+ "CREATED_AT" BIGINT,
+ "BUILD_DATE" BIGINT,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "PARENT_SNAPSHOT_ID" INTEGER,
+ "STATUS" VARCHAR(4) NOT NULL DEFAULT 'U',
+ "PURGE_STATUS" INTEGER,
+ "ISLAST" BOOLEAN NOT NULL DEFAULT FALSE,
+ "SCOPE" VARCHAR(3),
+ "QUALIFIER" VARCHAR(10),
+ "ROOT_SNAPSHOT_ID" INTEGER,
+ "VERSION" VARCHAR(500),
+ "PATH" VARCHAR(500),
+ "DEPTH" INTEGER,
+ "ROOT_COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "PERIOD1_MODE" VARCHAR(100),
+ "PERIOD1_PARAM" VARCHAR(100),
+ "PERIOD1_DATE" BIGINT,
+ "PERIOD2_MODE" VARCHAR(100),
+ "PERIOD2_PARAM" VARCHAR(100),
+ "PERIOD2_DATE" BIGINT,
+ "PERIOD3_MODE" VARCHAR(100),
+ "PERIOD3_PARAM" VARCHAR(100),
+ "PERIOD3_DATE" BIGINT,
+ "PERIOD4_MODE" VARCHAR(100),
+ "PERIOD4_PARAM" VARCHAR(100),
+ "PERIOD4_DATE" BIGINT,
+ "PERIOD5_MODE" VARCHAR(100),
+ "PERIOD5_PARAM" VARCHAR(100),
+ "PERIOD5_DATE" BIGINT
+);
+
+CREATE TABLE "METRICS" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER NOT NULL DEFAULT 0,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN NOT NULL DEFAULT FALSE,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER
+);