From: Sébastien Lesaint Date: Thu, 16 Apr 2015 14:27:25 +0000 (+0200) Subject: SONAR-6366 rename DatabaseMigration to MigrationStep X-Git-Tag: 5.2-RC1~2229 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=505cf2ae5649aaee04a8d86c4c9ba7505b9071f9;p=sonarqube.git SONAR-6366 rename DatabaseMigration to MigrationStep also rename DatabaseMigrations to MigrationSteps this is required to to make room for the more appropriatly named DatabaseMigration class that deals with triggering the database migration --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/AddColumnsBuilder.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/AddColumnsBuilder.java index 34aca9d0e41..4010c94067e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/AddColumnsBuilder.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/AddColumnsBuilder.java @@ -19,19 +19,20 @@ */ package org.sonar.server.db.migrations; -import com.google.common.base.CharMatcher; -import com.google.common.base.Preconditions; -import org.sonar.core.persistence.dialect.Dialect; -import org.sonar.core.persistence.dialect.MsSql; -import org.sonar.core.persistence.dialect.Oracle; -import org.sonar.core.persistence.dialect.PostgreSql; +import static com.google.common.collect.Lists.newArrayList; + +import java.util.List; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import java.util.List; +import org.sonar.core.persistence.dialect.Dialect; +import org.sonar.core.persistence.dialect.MsSql; +import org.sonar.core.persistence.dialect.Oracle; +import org.sonar.core.persistence.dialect.PostgreSql; -import static com.google.common.collect.Lists.newArrayList; +import com.google.common.base.CharMatcher; +import com.google.common.base.Preconditions; public class AddColumnsBuilder { diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/BaseDataChange.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/BaseDataChange.java index b90886eb3f4..0631b2e1cf2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/BaseDataChange.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/BaseDataChange.java @@ -19,13 +19,13 @@ */ package org.sonar.server.db.migrations; -import org.apache.commons.dbutils.DbUtils; -import org.sonar.core.persistence.Database; - import java.sql.Connection; import java.sql.SQLException; -public abstract class BaseDataChange implements DataChange, DatabaseMigration { +import org.apache.commons.dbutils.DbUtils; +import org.sonar.core.persistence.Database; + +public abstract class BaseDataChange implements DataChange, MigrationStep { private final Database db; diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/BaseSqlStatement.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/BaseSqlStatement.java index e4416b9401d..8983e7ecb5c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/BaseSqlStatement.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/BaseSqlStatement.java @@ -19,16 +19,16 @@ */ package org.sonar.server.db.migrations; -import org.apache.commons.dbutils.DbUtils; - -import javax.annotation.Nullable; - import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Timestamp; import java.sql.Types; import java.util.Date; +import javax.annotation.Nullable; + +import org.apache.commons.dbutils.DbUtils; + class BaseSqlStatement implements SqlStatement { protected PreparedStatement pstmt; diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DataChange.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DataChange.java index c901a782594..8b513ffcd2e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DataChange.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DataChange.java @@ -19,11 +19,11 @@ */ package org.sonar.server.db.migrations; -import org.sonar.core.persistence.Database; - import java.sql.Connection; import java.sql.SQLException; +import org.sonar.core.persistence.Database; + public interface DataChange { class Context { diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigration.java deleted file mode 100644 index b20a35c9c4f..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigration.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ -package org.sonar.server.db.migrations; - -import java.sql.SQLException; - -/** - * Java alternative of ActiveRecord::Migration. Do not forget to declare implementation classes in {@link DatabaseMigrations#CLASSES} - * @since 3.7 - */ -public interface DatabaseMigration { - - void execute() throws SQLException; - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java deleted file mode 100644 index 96411abea50..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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. - */ -package org.sonar.server.db.migrations; - -import com.google.common.collect.ImmutableList; -import org.sonar.server.db.migrations.v36.ViolationMigration; -import org.sonar.server.db.migrations.v42.CompleteIssueMessageMigration; -import org.sonar.server.db.migrations.v42.PackageKeysMigration; -import org.sonar.server.db.migrations.v43.*; -import org.sonar.server.db.migrations.v44.*; -import org.sonar.server.db.migrations.v45.AddMissingRuleParameterDefaultValuesMigration; -import org.sonar.server.db.migrations.v45.DeleteMeasuresOnDeletedProfilesMigration; -import org.sonar.server.db.migrations.v451.AddMissingCustomRuleParametersMigration; -import org.sonar.server.db.migrations.v451.DeleteUnescapedActivities; -import org.sonar.server.db.migrations.v50.*; -import org.sonar.server.db.migrations.v51.*; -import org.sonar.server.db.migrations.v52.FeedEventsComponentUuid; -import org.sonar.server.db.migrations.v52.FeedProjectLinksComponentUuid; -import org.sonar.server.db.migrations.v52.MoveProjectProfileAssociation; - -import java.util.List; - -public interface DatabaseMigrations { - - List> CLASSES = ImmutableList.of( - // 3.6 - ViolationMigration.class, - - // 4.2 - PackageKeysMigration.class, CompleteIssueMessageMigration.class, - - // 4.3 - ConvertIssueDebtToMinutesMigration.class, - IssueChangelogMigration.class, - TechnicalDebtMeasuresMigration.class, - DevelopmentCostMeasuresMigration.class, - RequirementMeasuresMigration.class, - NotResolvedIssuesOnRemovedComponentsMigration.class, - - // 4.4 - IssueActionPlanKeyMigration.class, - MeasureDataMigration.class, - FeedQProfileKeysMigration.class, - FeedQProfileDatesMigration.class, - ChangeLogMigration.class, - ConvertProfileMeasuresMigration.class, - - // 4.5 - AddMissingRuleParameterDefaultValuesMigration.class, - DeleteMeasuresOnDeletedProfilesMigration.class, - - // 4.5.1 - AddMissingCustomRuleParametersMigration.class, - DeleteUnescapedActivities.class, - - // 5.0 - InsertProjectsAuthorizationUpdatedAtMigration.class, - PopulateProjectsUuidColumnsMigration.class, - ReplaceIssueFiltersProjectKeyByUuid.class, - FeedSnapshotSourcesUpdatedAt.class, - FeedFileSources.class, - FeedIssueLongDates.class, - RemoveSortFieldFromIssueFiltersMigration.class, - - // 5.1 - FeedIssueTags.class, - FeedUsersLongDates.class, - RenameComponentRelatedParamsInIssueFilters.class, - CopyScmAccountsFromAuthorsToUsers.class, - FeedIssueChangesLongDates.class, - FeedAnalysisReportsLongDates.class, - UpdateProjectsModuleUuidPath.class, - FeedIssueComponentUuids.class, - FeedSnapshotsLongDates.class, - FeedIssuesLongDates.class, - FeedFileSourcesBinaryData.class, - FeedSemaphoresLongDates.class, - FeedManualMeasuresLongDates.class, - FeedEventsLongDates.class, - AddNewCharacteristics.class, - RemovePermissionsOnModulesMigration.class, - AddIssuesColumns.class, - DropIssuesColumns.class, - - // 5.2 - FeedProjectLinksComponentUuid.class, - FeedEventsComponentUuid.class, - MoveProjectProfileAssociation.class - ); -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrator.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrator.java index e13c246802d..b506fc5244a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrator.java @@ -19,18 +19,19 @@ */ package org.sonar.server.db.migrations; -import com.google.common.annotations.VisibleForTesting; +import java.sql.Connection; + import org.apache.commons.dbutils.DbUtils; import org.apache.ibatis.session.SqlSession; import org.picocontainer.Startable; -import org.sonar.api.utils.log.Loggers; import org.sonar.api.ServerComponent; import org.sonar.api.platform.ServerUpgradeStatus; +import org.sonar.api.utils.log.Loggers; import org.sonar.core.persistence.DdlUtils; import org.sonar.server.db.DbClient; import org.sonar.server.plugins.ServerPluginRepository; -import java.sql.Connection; +import com.google.common.annotations.VisibleForTesting; /** * Restore schema by executing DDL scripts. Only H2 database is supported. @@ -41,14 +42,14 @@ import java.sql.Connection; public class DatabaseMigrator implements ServerComponent, Startable { private final DbClient dbClient; - private final DatabaseMigration[] migrations; + private final MigrationStep[] migrations; private final ServerUpgradeStatus serverUpgradeStatus; /** * ServerPluginRepository is used to ensure H2 schema creation is done only after copy of bundle plugins have been done */ - public DatabaseMigrator(DbClient dbClient, DatabaseMigration[] migrations, ServerUpgradeStatus serverUpgradeStatus, - ServerPluginRepository serverPluginRepository) { + public DatabaseMigrator(DbClient dbClient, MigrationStep[] migrations, ServerUpgradeStatus serverUpgradeStatus, + ServerPluginRepository serverPluginRepository) { this.dbClient = dbClient; this.migrations = migrations; this.serverUpgradeStatus = serverUpgradeStatus; @@ -89,7 +90,7 @@ public class DatabaseMigrator implements ServerComponent, Startable { } public void executeMigration(String className) { - DatabaseMigration migration = getMigration(className); + MigrationStep migration = getMigration(className); try { migration.execute(); @@ -101,8 +102,8 @@ public class DatabaseMigrator implements ServerComponent, Startable { } } - private DatabaseMigration getMigration(String className) { - for (DatabaseMigration migration : migrations) { + private MigrationStep getMigration(String className) { + for (MigrationStep migration : migrations) { if (migration.getClass().getName().equals(className)) { return migration; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DdlChange.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DdlChange.java index 39944bae8e7..00320c1a3fe 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DdlChange.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DdlChange.java @@ -19,13 +19,13 @@ */ package org.sonar.server.db.migrations; -import org.apache.commons.dbutils.DbUtils; -import org.sonar.core.persistence.Database; - import java.sql.Connection; import java.sql.SQLException; -public abstract class DdlChange implements DatabaseMigration { +import org.apache.commons.dbutils.DbUtils; +import org.sonar.core.persistence.Database; + +public abstract class DdlChange implements MigrationStep { private final Database db; diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DropColumnsBuilder.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DropColumnsBuilder.java index ce61d645b16..a0a2ee1d2c6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DropColumnsBuilder.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DropColumnsBuilder.java @@ -19,7 +19,11 @@ */ package org.sonar.server.db.migrations; -import org.sonar.core.persistence.dialect.*; +import org.sonar.core.persistence.dialect.Dialect; +import org.sonar.core.persistence.dialect.MsSql; +import org.sonar.core.persistence.dialect.MySql; +import org.sonar.core.persistence.dialect.Oracle; +import org.sonar.core.persistence.dialect.PostgreSql; public class DropColumnsBuilder { diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdate.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdate.java index 4c2594dd496..c670ae5333d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdate.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdate.java @@ -19,13 +19,13 @@ */ package org.sonar.server.db.migrations; -import org.sonar.core.persistence.Database; -import org.sonar.server.util.ProgressLogger; - import java.sql.Connection; import java.sql.SQLException; import java.util.concurrent.atomic.AtomicLong; +import org.sonar.core.persistence.Database; +import org.sonar.server.util.ProgressLogger; + public class MassUpdate { public static interface Handler { diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationStep.java new file mode 100644 index 00000000000..eddf1244a55 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationStep.java @@ -0,0 +1,32 @@ +/* + * 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. + */ +package org.sonar.server.db.migrations; + +import java.sql.SQLException; + +/** + * Java alternative of ActiveRecord::Migration. Do not forget to declare implementation classes in {@link MigrationSteps#CLASSES} + * @since 3.7 + */ +public interface MigrationStep { + + void execute() throws SQLException; + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationSteps.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationSteps.java new file mode 100644 index 00000000000..2944902fe34 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationSteps.java @@ -0,0 +1,140 @@ +/* + * 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. + */ +package org.sonar.server.db.migrations; + +import com.google.common.collect.ImmutableList; +import org.sonar.server.db.migrations.v36.ViolationMigrationStep; +import org.sonar.server.db.migrations.v42.CompleteIssueMessageMigrationStep; +import org.sonar.server.db.migrations.v42.PackageKeysMigrationStep; +import org.sonar.server.db.migrations.v43.ConvertIssueDebtToMinutesMigrationStep; +import org.sonar.server.db.migrations.v43.DevelopmentCostMeasuresMigrationStep; +import org.sonar.server.db.migrations.v43.IssueChangelogMigrationStep; +import org.sonar.server.db.migrations.v43.NotResolvedIssuesOnRemovedComponentsMigrationStep; +import org.sonar.server.db.migrations.v43.RequirementMeasuresMigrationStep; +import org.sonar.server.db.migrations.v43.TechnicalDebtMeasuresMigrationStep; +import org.sonar.server.db.migrations.v44.ChangeLogMigrationStep; +import org.sonar.server.db.migrations.v44.ConvertProfileMeasuresMigrationStep; +import org.sonar.server.db.migrations.v44.FeedQProfileDatesMigrationStep; +import org.sonar.server.db.migrations.v44.FeedQProfileKeysMigrationStep; +import org.sonar.server.db.migrations.v44.IssueActionPlanKeyMigrationStep; +import org.sonar.server.db.migrations.v44.MeasureDataMigrationStep; +import org.sonar.server.db.migrations.v45.AddMissingRuleParameterDefaultValuesMigrationStep; +import org.sonar.server.db.migrations.v45.DeleteMeasuresOnDeletedProfilesMigrationStep; +import org.sonar.server.db.migrations.v451.AddMissingCustomRuleParametersMigrationStep; +import org.sonar.server.db.migrations.v451.DeleteUnescapedActivities; +import org.sonar.server.db.migrations.v50.FeedFileSources; +import org.sonar.server.db.migrations.v50.FeedIssueLongDates; +import org.sonar.server.db.migrations.v50.FeedSnapshotSourcesUpdatedAt; +import org.sonar.server.db.migrations.v50.InsertProjectsAuthorizationUpdatedAtMigrationStep; +import org.sonar.server.db.migrations.v50.PopulateProjectsUuidColumnsMigrationStep; +import org.sonar.server.db.migrations.v50.RemoveSortFieldFromIssueFiltersMigrationStep; +import org.sonar.server.db.migrations.v50.ReplaceIssueFiltersProjectKeyByUuid; +import org.sonar.server.db.migrations.v51.AddIssuesColumns; +import org.sonar.server.db.migrations.v51.AddNewCharacteristics; +import org.sonar.server.db.migrations.v51.CopyScmAccountsFromAuthorsToUsers; +import org.sonar.server.db.migrations.v51.DropIssuesColumns; +import org.sonar.server.db.migrations.v51.FeedAnalysisReportsLongDates; +import org.sonar.server.db.migrations.v51.FeedEventsLongDates; +import org.sonar.server.db.migrations.v51.FeedFileSourcesBinaryData; +import org.sonar.server.db.migrations.v51.FeedIssueChangesLongDates; +import org.sonar.server.db.migrations.v51.FeedIssueComponentUuids; +import org.sonar.server.db.migrations.v51.FeedIssueTags; +import org.sonar.server.db.migrations.v51.FeedIssuesLongDates; +import org.sonar.server.db.migrations.v51.FeedManualMeasuresLongDates; +import org.sonar.server.db.migrations.v51.FeedSemaphoresLongDates; +import org.sonar.server.db.migrations.v51.FeedSnapshotsLongDates; +import org.sonar.server.db.migrations.v51.FeedUsersLongDates; +import org.sonar.server.db.migrations.v51.RemovePermissionsOnModulesMigrationStep; +import org.sonar.server.db.migrations.v51.RenameComponentRelatedParamsInIssueFilters; +import org.sonar.server.db.migrations.v51.UpdateProjectsModuleUuidPath; +import org.sonar.server.db.migrations.v52.FeedEventsComponentUuid; +import org.sonar.server.db.migrations.v52.FeedProjectLinksComponentUuid; +import org.sonar.server.db.migrations.v52.MoveProjectProfileAssociation; + +import java.util.List; + +public interface MigrationSteps { + + List> CLASSES = ImmutableList.of( + // 3.6 + ViolationMigrationStep.class, + + // 4.2 + PackageKeysMigrationStep.class, CompleteIssueMessageMigrationStep.class, + + // 4.3 + ConvertIssueDebtToMinutesMigrationStep.class, + IssueChangelogMigrationStep.class, + TechnicalDebtMeasuresMigrationStep.class, + DevelopmentCostMeasuresMigrationStep.class, + RequirementMeasuresMigrationStep.class, + NotResolvedIssuesOnRemovedComponentsMigrationStep.class, + + // 4.4 + IssueActionPlanKeyMigrationStep.class, + MeasureDataMigrationStep.class, + FeedQProfileKeysMigrationStep.class, + FeedQProfileDatesMigrationStep.class, + ChangeLogMigrationStep.class, + ConvertProfileMeasuresMigrationStep.class, + + // 4.5 + AddMissingRuleParameterDefaultValuesMigrationStep.class, + DeleteMeasuresOnDeletedProfilesMigrationStep.class, + + // 4.5.1 + AddMissingCustomRuleParametersMigrationStep.class, + DeleteUnescapedActivities.class, + + // 5.0 + InsertProjectsAuthorizationUpdatedAtMigrationStep.class, + PopulateProjectsUuidColumnsMigrationStep.class, + ReplaceIssueFiltersProjectKeyByUuid.class, + FeedSnapshotSourcesUpdatedAt.class, + FeedFileSources.class, + FeedIssueLongDates.class, + RemoveSortFieldFromIssueFiltersMigrationStep.class, + + // 5.1 + FeedIssueTags.class, + FeedUsersLongDates.class, + RenameComponentRelatedParamsInIssueFilters.class, + CopyScmAccountsFromAuthorsToUsers.class, + FeedIssueChangesLongDates.class, + FeedAnalysisReportsLongDates.class, + UpdateProjectsModuleUuidPath.class, + FeedIssueComponentUuids.class, + FeedSnapshotsLongDates.class, + FeedIssuesLongDates.class, + FeedFileSourcesBinaryData.class, + FeedSemaphoresLongDates.class, + FeedManualMeasuresLongDates.class, + FeedEventsLongDates.class, + AddNewCharacteristics.class, + RemovePermissionsOnModulesMigrationStep.class, + AddIssuesColumns.class, + DropIssuesColumns.class, + + // 5.2 + FeedProjectLinksComponentUuid.class, + FeedEventsComponentUuid.class, + MoveProjectProfileAssociation.class + ); +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/Select.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/Select.java index 869c74e33c9..8259660f63e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/Select.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/Select.java @@ -19,8 +19,6 @@ */ package org.sonar.server.db.migrations; -import javax.annotation.CheckForNull; - import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; @@ -28,6 +26,8 @@ import java.sql.Timestamp; import java.util.Date; import java.util.List; +import javax.annotation.CheckForNull; + public interface Select extends SqlStatement implements Select { private SelectImpl(PreparedStatement pstmt) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/SqlStatement.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/SqlStatement.java index 1cf7d925ba4..c6f8264567b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/SqlStatement.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/SqlStatement.java @@ -19,11 +19,11 @@ */ package org.sonar.server.db.migrations; -import javax.annotation.Nullable; - import java.sql.SQLException; import java.util.Date; +import javax.annotation.Nullable; + public interface SqlStatement { CHILD setBoolean(int columnIndex, @Nullable Boolean value) throws SQLException; diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/SqlUtil.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/SqlUtil.java index 17b0f16b1de..f528218723f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/SqlUtil.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/SqlUtil.java @@ -19,16 +19,15 @@ */ package org.sonar.server.db.migrations; - -import org.sonar.api.utils.log.Logger; - -import javax.annotation.CheckForNull; - import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.util.Date; +import javax.annotation.CheckForNull; + +import org.sonar.api.utils.log.Logger; + public class SqlUtil { private SqlUtil() { diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/UpsertImpl.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/UpsertImpl.java index 3d5d88e30d0..456e6d42a0d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/UpsertImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/UpsertImpl.java @@ -19,12 +19,12 @@ */ package org.sonar.server.db.migrations; -import org.sonar.core.persistence.BatchSession; - import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; +import org.sonar.core.persistence.BatchSession; + public class UpsertImpl extends BaseSqlStatement implements Upsert { private long batchCount = 0L; diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/Progress.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/Progress.java index 0e4c2e08273..0e4f1a10d78 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/Progress.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/Progress.java @@ -19,13 +19,12 @@ */ package org.sonar.server.db.migrations.v36; +import java.util.TimerTask; +import java.util.concurrent.atomic.AtomicLong; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; -import java.util.TimerTask; -import java.util.concurrent.atomic.AtomicLong; - /** * This task logs every minute the status of migration. It is destroyed * when migration is finished. @@ -64,7 +63,7 @@ class Progress extends TimerTask { long remaining = (totalViolations - totalIssues) / frequency; logger.info(String.format( "%d%% [%d/%d violations, %d minutes remaining]", percents, totalIssues, totalViolations, remaining) - ); + ); } else { logger.info(String.format("%d%% [%d/%d violations]", percents, totalIssues, totalViolations)); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/Referentials.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/Referentials.java index f3bf398b1f7..f7ee441c668 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/Referentials.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/Referentials.java @@ -19,14 +19,6 @@ */ package org.sonar.server.db.migrations.v36; -import com.google.common.collect.Maps; -import org.apache.commons.dbutils.DbUtils; -import org.apache.commons.dbutils.QueryRunner; -import org.apache.commons.dbutils.ResultSetHandler; -import org.sonar.core.persistence.Database; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -35,6 +27,16 @@ import java.util.Map; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +import org.apache.commons.dbutils.DbUtils; +import org.apache.commons.dbutils.QueryRunner; +import org.apache.commons.dbutils.ResultSetHandler; +import org.sonar.core.persistence.Database; + +import com.google.common.collect.Maps; + /** * Data loaded from database before migrating violations. It is * shared amongst converter parallel tasks. diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/ViolationConverter.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/ViolationConverter.java index c31aeb8b5f8..8e8bea4e63f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/ViolationConverter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/ViolationConverter.java @@ -19,10 +19,14 @@ */ package org.sonar.server.db.migrations.v36; -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; +import java.sql.Connection; +import java.sql.Date; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; + import org.apache.commons.dbutils.DbUtils; import org.apache.commons.dbutils.QueryRunner; import org.apache.commons.dbutils.handlers.AbstractListHandler; @@ -31,13 +35,10 @@ import org.sonar.api.utils.internal.Uuids; import org.sonar.core.persistence.Database; import org.sonar.server.db.migrations.SqlUtil; -import java.sql.Connection; -import java.sql.Date; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Callable; +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; class ViolationConverter implements Callable { diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/ViolationConverters.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/ViolationConverters.java index 6942c304f23..8b127f323eb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/ViolationConverters.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/ViolationConverters.java @@ -19,10 +19,6 @@ */ package org.sonar.server.db.migrations.v36; -import com.google.common.collect.Lists; -import org.sonar.api.config.Settings; -import org.sonar.core.persistence.Database; - import java.util.List; import java.util.Timer; import java.util.TimerTask; @@ -31,6 +27,11 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import org.sonar.api.config.Settings; +import org.sonar.core.persistence.Database; + +import com.google.common.collect.Lists; + class ViolationConverters { static final int DEFAULT_THREADS = 5; diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/ViolationMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/ViolationMigration.java deleted file mode 100644 index c5e955b2c94..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/ViolationMigration.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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. - */ -package org.sonar.server.db.migrations.v36; - - -import org.sonar.api.config.Settings; -import org.sonar.api.utils.MessageException; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.core.persistence.Database; -import org.sonar.server.db.migrations.DatabaseMigration; -import org.sonar.server.db.migrations.SqlUtil; - -import java.sql.SQLException; - -/** - * Used in the Active Record Migration 401 - */ -public class ViolationMigration implements DatabaseMigration { - - private static final Logger LOGGER = Loggers.get(ViolationMigration.class); - - private static final String FAILURE_MESSAGE = "Fail to convert violations to issues"; - - private final Settings settings; - private final Database db; - - public ViolationMigration(Database database, Settings settings) { - this.db = database; - this.settings = settings; - } - - @Override - public void execute() { - try { - LOGGER.info("Initialize input"); - Referentials referentials = new Referentials(db); - if (referentials.totalViolations() > 0) { - LOGGER.info("Migrate {} violations", referentials.totalViolations()); - ViolationConverters converters = new ViolationConverters(settings); - converters.execute(referentials, db); - } - } catch (SQLException e) { - LOGGER.error(FAILURE_MESSAGE, e); - SqlUtil.log(LOGGER, e); - throw MessageException.of(FAILURE_MESSAGE); - - } catch (Exception e) { - LOGGER.error(FAILURE_MESSAGE, e); - throw MessageException.of(FAILURE_MESSAGE); - } - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/ViolationMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/ViolationMigrationStep.java new file mode 100644 index 00000000000..2e51fa07006 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v36/ViolationMigrationStep.java @@ -0,0 +1,70 @@ +/* + * 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. + */ +package org.sonar.server.db.migrations.v36; + +import java.sql.SQLException; + +import org.sonar.api.config.Settings; +import org.sonar.api.utils.MessageException; +import org.sonar.api.utils.log.Logger; +import org.sonar.api.utils.log.Loggers; +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.MigrationStep; +import org.sonar.server.db.migrations.SqlUtil; + +/** + * Used in the Active Record Migration 401 + */ +public class ViolationMigrationStep implements MigrationStep { + + private static final Logger LOGGER = Loggers.get(ViolationMigrationStep.class); + + private static final String FAILURE_MESSAGE = "Fail to convert violations to issues"; + + private final Settings settings; + private final Database db; + + public ViolationMigrationStep(Database database, Settings settings) { + this.db = database; + this.settings = settings; + } + + @Override + public void execute() { + try { + LOGGER.info("Initialize input"); + Referentials referentials = new Referentials(db); + if (referentials.totalViolations() > 0) { + LOGGER.info("Migrate {} violations", referentials.totalViolations()); + ViolationConverters converters = new ViolationConverters(settings); + converters.execute(referentials, db); + } + } catch (SQLException e) { + LOGGER.error(FAILURE_MESSAGE, e); + SqlUtil.log(LOGGER, e); + throw MessageException.of(FAILURE_MESSAGE); + + } catch (Exception e) { + LOGGER.error(FAILURE_MESSAGE, e); + throw MessageException.of(FAILURE_MESSAGE); + } + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v42/CompleteIssueMessageMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v42/CompleteIssueMessageMigration.java deleted file mode 100644 index 14259d6b617..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v42/CompleteIssueMessageMigration.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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. - */ -package org.sonar.server.db.migrations.v42; - -import org.sonar.core.persistence.Database; -import org.sonar.server.db.migrations.BaseDataChange; -import org.sonar.server.db.migrations.MassUpdate; -import org.sonar.server.db.migrations.Select; -import org.sonar.server.db.migrations.SqlStatement; - -import java.sql.SQLException; - -/** - * Used in Rails migration 497 - * - * @since 4.2 - */ -public class CompleteIssueMessageMigration extends BaseDataChange { - - public CompleteIssueMessageMigration(Database database) { - super(database); - } - - @Override - public void execute(Context context) throws SQLException { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("SELECT i.id, r.name FROM issues i INNER JOIN rules r ON r.id=i.rule_id WHERE i.message IS NULL"); - massUpdate.update("UPDATE issues SET message=? WHERE id=?"); - massUpdate.execute(new MassUpdate.Handler() { - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - Long issueId = row.getNullableLong(1); - String ruleName = row.getNullableString(2); - - update.setString(1, ruleName); - update.setLong(2, issueId); - return true; - } - }); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v42/CompleteIssueMessageMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v42/CompleteIssueMessageMigrationStep.java new file mode 100644 index 00000000000..71b4edca569 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v42/CompleteIssueMessageMigrationStep.java @@ -0,0 +1,58 @@ +/* + * 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. + */ +package org.sonar.server.db.migrations.v42; + +import java.sql.SQLException; + +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; + +/** + * Used in Rails migration 497 + * + * @since 4.2 + */ +public class CompleteIssueMessageMigrationStep extends BaseDataChange { + + public CompleteIssueMessageMigrationStep(Database database) { + super(database); + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("SELECT i.id, r.name FROM issues i INNER JOIN rules r ON r.id=i.rule_id WHERE i.message IS NULL"); + massUpdate.update("UPDATE issues SET message=? WHERE id=?"); + massUpdate.execute(new MassUpdate.Handler() { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + Long issueId = row.getNullableLong(1); + String ruleName = row.getNullableString(2); + + update.setString(1, ruleName); + update.setLong(2, issueId); + return true; + } + }); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v42/PackageKeysMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v42/PackageKeysMigration.java deleted file mode 100644 index 1a2e22bc815..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v42/PackageKeysMigration.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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. - */ -package org.sonar.server.db.migrations.v42; - -import org.apache.commons.lang.StringUtils; -import org.sonar.core.persistence.Database; -import org.sonar.server.db.migrations.BaseDataChange; -import org.sonar.server.db.migrations.MassUpdate; -import org.sonar.server.db.migrations.Select; -import org.sonar.server.db.migrations.SqlStatement; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.sql.SQLException; - -/** - * Used in Rails migration 490 - * - * @since 4.2 - */ -public class PackageKeysMigration extends BaseDataChange { - - public PackageKeysMigration(Database database) { - super(database); - } - - @Override - public void execute(Context context) throws SQLException { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("SELECT id, kee FROM projects WHERE qualifier='PAC'"); - massUpdate.update("UPDATE projects SET qualifier='DIR', kee=? WHERE id=?"); - massUpdate.execute(new MassUpdate.Handler() { - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - Long id = row.getNullableLong(1); - String key = row.getNullableString(2); - update.setString(1, convertKey(key)); - update.setLong(2, id); - return true; - } - }); - } - - @CheckForNull - String convertKey(@Nullable String packageKey) { - if (packageKey != null) { - String prefix = StringUtils.substringBeforeLast(packageKey, ":") + ":"; - String key = StringUtils.substringAfterLast(packageKey, ":"); - if ("[default]".equals(key)) { - return prefix + "[root]"; - } - return prefix + StringUtils.replace(key, ".", "/"); - } - return null; - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v42/PackageKeysMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v42/PackageKeysMigrationStep.java new file mode 100644 index 00000000000..cf9c4715a7f --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v42/PackageKeysMigrationStep.java @@ -0,0 +1,74 @@ +/* + * 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. + */ +package org.sonar.server.db.migrations.v42; + +import java.sql.SQLException; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +import org.apache.commons.lang.StringUtils; +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; + +/** + * Used in Rails migration 490 + * + * @since 4.2 + */ +public class PackageKeysMigrationStep extends BaseDataChange { + + public PackageKeysMigrationStep(Database database) { + super(database); + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("SELECT id, kee FROM projects WHERE qualifier='PAC'"); + massUpdate.update("UPDATE projects SET qualifier='DIR', kee=? WHERE id=?"); + massUpdate.execute(new MassUpdate.Handler() { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + Long id = row.getNullableLong(1); + String key = row.getNullableString(2); + update.setString(1, convertKey(key)); + update.setLong(2, id); + return true; + } + }); + } + + @CheckForNull + String convertKey(@Nullable String packageKey) { + if (packageKey != null) { + String prefix = StringUtils.substringBeforeLast(packageKey, ":") + ":"; + String key = StringUtils.substringAfterLast(packageKey, ":"); + if ("[default]".equals(key)) { + return prefix + "[root]"; + } + return prefix + StringUtils.replace(key, ".", "/"); + } + return null; + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigration.java deleted file mode 100644 index 091eb2a7e0d..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigration.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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. - */ - -package org.sonar.server.db.migrations.v43; - -import org.sonar.api.utils.System2; -import org.sonar.core.persistence.Database; -import org.sonar.core.properties.PropertiesDao; -import org.sonar.server.db.migrations.BaseDataChange; -import org.sonar.server.db.migrations.MassUpdate; -import org.sonar.server.db.migrations.Select; -import org.sonar.server.db.migrations.SqlStatement; - -import java.sql.SQLException; -import java.util.Date; - -/** - * Used in the Active Record Migration 513. - * WARNING - this migration is not re-entrant. - * - * @since 4.3 - */ -public class ConvertIssueDebtToMinutesMigration extends BaseDataChange { - - private final WorkDurationConvertor workDurationConvertor; - private final System2 system2; - - public ConvertIssueDebtToMinutesMigration(Database database, PropertiesDao propertiesDao, System2 system2) { - super(database); - this.workDurationConvertor = new WorkDurationConvertor(propertiesDao); - this.system2 = system2; - } - - @Override - public void execute(Context context) throws SQLException { - workDurationConvertor.init(); - final Date now = new Date(system2.now()); - MassUpdate massUpdate = context.prepareMassUpdate(); - - // See https://jira.codehaus.org/browse/SONAR-5394 - // The SQL request should not set the filter on technical_debt is not null. There's no index - // on this column, so filtering is done programmatically. - massUpdate.select("select id, technical_debt from issues"); - - massUpdate.update("update issues set technical_debt=?, updated_at=? where id=?"); - massUpdate.execute(new MassUpdate.Handler() { - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - Long debt = row.getNullableLong(2); - if (debt != null) { - Long id = row.getNullableLong(1); - update.setLong(1, workDurationConvertor.createFromLong(debt)); - update.setDate(2, now); - update.setLong(3, id); - return true; - } - return false; - } - }); - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationStep.java new file mode 100644 index 00000000000..9f29e1ec628 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationStep.java @@ -0,0 +1,79 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v43; + +import java.sql.SQLException; +import java.util.Date; + +import org.sonar.api.utils.System2; +import org.sonar.core.persistence.Database; +import org.sonar.core.properties.PropertiesDao; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; + +/** + * Used in the Active Record Migration 513. + * WARNING - this migration is not re-entrant. + * + * @since 4.3 + */ +public class ConvertIssueDebtToMinutesMigrationStep extends BaseDataChange { + + private final WorkDurationConvertor workDurationConvertor; + private final System2 system2; + + public ConvertIssueDebtToMinutesMigrationStep(Database database, PropertiesDao propertiesDao, System2 system2) { + super(database); + this.workDurationConvertor = new WorkDurationConvertor(propertiesDao); + this.system2 = system2; + } + + @Override + public void execute(Context context) throws SQLException { + workDurationConvertor.init(); + final Date now = new Date(system2.now()); + MassUpdate massUpdate = context.prepareMassUpdate(); + + // See https://jira.codehaus.org/browse/SONAR-5394 + // The SQL request should not set the filter on technical_debt is not null. There's no index + // on this column, so filtering is done programmatically. + massUpdate.select("select id, technical_debt from issues"); + + massUpdate.update("update issues set technical_debt=?, updated_at=? where id=?"); + massUpdate.execute(new MassUpdate.Handler() { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + Long debt = row.getNullableLong(2); + if (debt != null) { + Long id = row.getNullableLong(1); + update.setLong(1, workDurationConvertor.createFromLong(debt)); + update.setDate(2, now); + update.setLong(3, id); + return true; + } + return false; + } + }); + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigration.java deleted file mode 100644 index 6345bc53b03..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigration.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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. - */ - -package org.sonar.server.db.migrations.v43; - -import org.sonar.core.persistence.Database; -import org.sonar.core.properties.PropertiesDao; -import org.sonar.server.db.migrations.BaseDataChange; -import org.sonar.server.db.migrations.MassUpdate; -import org.sonar.server.db.migrations.Select; -import org.sonar.server.db.migrations.SqlStatement; - -import javax.annotation.CheckForNull; - -import java.sql.SQLException; - -/** - * Used in the Active Record Migration 516 - * - * @since 4.3 - */ -public class DevelopmentCostMeasuresMigration extends BaseDataChange { - - private final WorkDurationConvertor workDurationConvertor; - - public DevelopmentCostMeasuresMigration(Database database, PropertiesDao propertiesDao) { - super(database); - this.workDurationConvertor = new WorkDurationConvertor(propertiesDao); - } - - @Override - public void execute(Context context) throws SQLException { - workDurationConvertor.init(); - - Long metricId = context.prepareSelect("select id from metrics where name='development_cost'").get(Select.LONG_READER); - if (metricId != null) { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("select id, value from project_measures where metric_id=? and value is not null").setLong(1, metricId); - massUpdate.update("update project_measures set value=NULL,text_value=? where id=?"); - massUpdate.execute(new MassUpdate.Handler() { - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - Long id = row.getNullableLong(1); - Double value = row.getNullableDouble(2); - - update.setString(1, convertDebtForDays(value)); - update.setLong(2, id); - return true; - } - }); - } - } - - @CheckForNull - private String convertDebtForDays(Double data) { - return Long.toString(workDurationConvertor.createFromDays(data)); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigrationStep.java new file mode 100644 index 00000000000..3f0ef33b29b --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigrationStep.java @@ -0,0 +1,75 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v43; + +import java.sql.SQLException; + +import javax.annotation.CheckForNull; + +import org.sonar.core.persistence.Database; +import org.sonar.core.properties.PropertiesDao; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; + +/** + * Used in the Active Record Migration 516 + * + * @since 4.3 + */ +public class DevelopmentCostMeasuresMigrationStep extends BaseDataChange { + + private final WorkDurationConvertor workDurationConvertor; + + public DevelopmentCostMeasuresMigrationStep(Database database, PropertiesDao propertiesDao) { + super(database); + this.workDurationConvertor = new WorkDurationConvertor(propertiesDao); + } + + @Override + public void execute(Context context) throws SQLException { + workDurationConvertor.init(); + + Long metricId = context.prepareSelect("select id from metrics where name='development_cost'").get(Select.LONG_READER); + if (metricId != null) { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("select id, value from project_measures where metric_id=? and value is not null").setLong(1, metricId); + massUpdate.update("update project_measures set value=NULL,text_value=? where id=?"); + massUpdate.execute(new MassUpdate.Handler() { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + Long id = row.getNullableLong(1); + Double value = row.getNullableDouble(2); + + update.setString(1, convertDebtForDays(value)); + update.setLong(2, id); + return true; + } + }); + } + } + + @CheckForNull + private String convertDebtForDays(Double data) { + return Long.toString(workDurationConvertor.createFromDays(data)); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigration.java deleted file mode 100644 index de3c557dc93..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigration.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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. - */ - -package org.sonar.server.db.migrations.v43; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Strings; -import org.sonar.api.utils.System2; -import org.sonar.core.persistence.Database; -import org.sonar.core.properties.PropertiesDao; -import org.sonar.server.db.migrations.BaseDataChange; -import org.sonar.server.db.migrations.MassUpdate; -import org.sonar.server.db.migrations.Select; -import org.sonar.server.db.migrations.SqlStatement; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.sql.SQLException; -import java.util.Date; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Used in the Active Record Migration 514 - * - * @since 4.3 - */ -public class IssueChangelogMigration extends BaseDataChange { - - private final WorkDurationConvertor workDurationConvertor; - private final System2 system2; - private final Pattern pattern = Pattern.compile("technicalDebt=(\\d*)\\|(\\d*)", Pattern.CASE_INSENSITIVE); - - public IssueChangelogMigration(Database database, System2 system2, PropertiesDao propertiesDao) { - this(database, system2, new WorkDurationConvertor(propertiesDao)); - } - - @VisibleForTesting - IssueChangelogMigration(Database database, System2 system2, WorkDurationConvertor convertor) { - super(database); - this.workDurationConvertor = convertor; - this.system2 = system2; - } - - @Override - public void execute(Context context) throws SQLException { - workDurationConvertor.init(); - final Date now = new Date(system2.now()); - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("SELECT ic.id, ic.change_data FROM issue_changes ic " + - "WHERE ic.change_type = 'diff' AND ic.change_data LIKE '%technicalDebt%'"); - massUpdate.update("UPDATE issue_changes SET change_data=?,updated_at=? WHERE id=?"); - massUpdate.execute(new MassUpdate.Handler() { - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - Long id = row.getNullableLong(1); - String changeData = row.getNullableString(2); - - update.setString(1, convertChangelog(changeData)); - update.setDate(2, now); - update.setLong(3, id); - return true; - } - }); - } - - @VisibleForTesting - @CheckForNull - String convertChangelog(@Nullable String data) { - if (data == null) { - return null; - } - Matcher matcher = pattern.matcher(data); - StringBuffer sb = new StringBuffer(); - if (matcher.find()) { - String replacement = "technicalDebt="; - String oldValue = matcher.group(1); - if (!Strings.isNullOrEmpty(oldValue)) { - long oldDebt = workDurationConvertor.createFromLong(Long.parseLong(oldValue)); - replacement += Long.toString(oldDebt); - } - replacement += "|"; - String newValue = matcher.group(2); - if (!Strings.isNullOrEmpty(newValue)) { - long newDebt = workDurationConvertor.createFromLong(Long.parseLong(newValue)); - replacement += Long.toString(newDebt); - } - matcher.appendReplacement(sb, replacement); - } - matcher.appendTail(sb); - return sb.toString(); - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationStep.java new file mode 100644 index 00000000000..edeab04db62 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationStep.java @@ -0,0 +1,113 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v43; + +import java.sql.SQLException; +import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +import org.sonar.api.utils.System2; +import org.sonar.core.persistence.Database; +import org.sonar.core.properties.PropertiesDao; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Strings; + +/** + * Used in the Active Record Migration 514 + * + * @since 4.3 + */ +public class IssueChangelogMigrationStep extends BaseDataChange { + + private final WorkDurationConvertor workDurationConvertor; + private final System2 system2; + private final Pattern pattern = Pattern.compile("technicalDebt=(\\d*)\\|(\\d*)", Pattern.CASE_INSENSITIVE); + + public IssueChangelogMigrationStep(Database database, System2 system2, PropertiesDao propertiesDao) { + this(database, system2, new WorkDurationConvertor(propertiesDao)); + } + + @VisibleForTesting + IssueChangelogMigrationStep(Database database, System2 system2, WorkDurationConvertor convertor) { + super(database); + this.workDurationConvertor = convertor; + this.system2 = system2; + } + + @Override + public void execute(Context context) throws SQLException { + workDurationConvertor.init(); + final Date now = new Date(system2.now()); + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("SELECT ic.id, ic.change_data FROM issue_changes ic " + + "WHERE ic.change_type = 'diff' AND ic.change_data LIKE '%technicalDebt%'"); + massUpdate.update("UPDATE issue_changes SET change_data=?,updated_at=? WHERE id=?"); + massUpdate.execute(new MassUpdate.Handler() { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + Long id = row.getNullableLong(1); + String changeData = row.getNullableString(2); + + update.setString(1, convertChangelog(changeData)); + update.setDate(2, now); + update.setLong(3, id); + return true; + } + }); + } + + @VisibleForTesting + @CheckForNull + String convertChangelog(@Nullable String data) { + if (data == null) { + return null; + } + Matcher matcher = pattern.matcher(data); + StringBuffer sb = new StringBuffer(); + if (matcher.find()) { + String replacement = "technicalDebt="; + String oldValue = matcher.group(1); + if (!Strings.isNullOrEmpty(oldValue)) { + long oldDebt = workDurationConvertor.createFromLong(Long.parseLong(oldValue)); + replacement += Long.toString(oldDebt); + } + replacement += "|"; + String newValue = matcher.group(2); + if (!Strings.isNullOrEmpty(newValue)) { + long newDebt = workDurationConvertor.createFromLong(Long.parseLong(newValue)); + replacement += Long.toString(newDebt); + } + matcher.appendReplacement(sb, replacement); + } + matcher.appendTail(sb); + return sb.toString(); + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/NotResolvedIssuesOnRemovedComponentsMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/NotResolvedIssuesOnRemovedComponentsMigration.java deleted file mode 100644 index 6c740c6d35b..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/NotResolvedIssuesOnRemovedComponentsMigration.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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. - */ - -package org.sonar.server.db.migrations.v43; - -import org.sonar.api.issue.Issue; -import org.sonar.api.utils.System2; -import org.sonar.core.persistence.Database; -import org.sonar.server.db.migrations.BaseDataChange; -import org.sonar.server.db.migrations.MassUpdate; -import org.sonar.server.db.migrations.Select; -import org.sonar.server.db.migrations.SqlStatement; - -import java.sql.SQLException; -import java.util.Date; - -/** - * Used in the Active Record Migration 525 - * - * @since 4.3 - */ -public class NotResolvedIssuesOnRemovedComponentsMigration extends BaseDataChange { - - private final System2 system2; - - public NotResolvedIssuesOnRemovedComponentsMigration(Database database, System2 system2) { - super(database); - this.system2 = system2; - } - - @Override - public void execute(Context context) throws SQLException { - final Date now = new Date(system2.now()); - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("SELECT i.id FROM issues i " + - "INNER JOIN projects p on p.id=i.component_id " + - "WHERE p.enabled=? AND i.resolution IS NULL ").setBoolean(1, false); - massUpdate.update("UPDATE issues SET status=?,resolution=?,updated_at=? WHERE id=?"); - massUpdate.execute(new MassUpdate.Handler() { - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - Long id = row.getNullableLong(1); - update.setString(1, Issue.STATUS_CLOSED); - update.setString(2, Issue.RESOLUTION_REMOVED); - update.setDate(3, now); - update.setLong(4, id); - return true; - } - }); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/NotResolvedIssuesOnRemovedComponentsMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/NotResolvedIssuesOnRemovedComponentsMigrationStep.java new file mode 100644 index 00000000000..d8e0271564c --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/NotResolvedIssuesOnRemovedComponentsMigrationStep.java @@ -0,0 +1,68 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v43; + +import java.sql.SQLException; +import java.util.Date; + +import org.sonar.api.issue.Issue; +import org.sonar.api.utils.System2; +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; + +/** + * Used in the Active Record Migration 525 + * + * @since 4.3 + */ +public class NotResolvedIssuesOnRemovedComponentsMigrationStep extends BaseDataChange { + + private final System2 system2; + + public NotResolvedIssuesOnRemovedComponentsMigrationStep(Database database, System2 system2) { + super(database); + this.system2 = system2; + } + + @Override + public void execute(Context context) throws SQLException { + final Date now = new Date(system2.now()); + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("SELECT i.id FROM issues i " + + "INNER JOIN projects p on p.id=i.component_id " + + "WHERE p.enabled=? AND i.resolution IS NULL ").setBoolean(1, false); + massUpdate.update("UPDATE issues SET status=?,resolution=?,updated_at=? WHERE id=?"); + massUpdate.execute(new MassUpdate.Handler() { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + Long id = row.getNullableLong(1); + update.setString(1, Issue.STATUS_CLOSED); + update.setString(2, Issue.RESOLUTION_REMOVED); + update.setDate(3, now); + update.setLong(4, id); + return true; + } + }); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/RequirementMeasuresMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/RequirementMeasuresMigration.java deleted file mode 100644 index ba68b29e87b..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/RequirementMeasuresMigration.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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. - */ - -package org.sonar.server.db.migrations.v43; - -import org.sonar.core.persistence.Database; -import org.sonar.server.db.migrations.BaseDataChange; -import org.sonar.server.db.migrations.MassUpdate; -import org.sonar.server.db.migrations.Select; -import org.sonar.server.db.migrations.SqlStatement; - -import java.sql.SQLException; - -/** - * Used in the Active Record Migration 521 - * - * @since 4.3 - */ -public class RequirementMeasuresMigration extends BaseDataChange { - - public RequirementMeasuresMigration(Database database) { - super(database); - } - - @Override - public void execute(Context context) throws SQLException { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("SELECT project_measures.id,characteristics.rule_id FROM project_measures " + - "INNER JOIN characteristics ON characteristics.id = project_measures.characteristic_id " + - "WHERE characteristics.rule_id IS NOT NULL"); - massUpdate.update("UPDATE project_measures SET characteristic_id=null,rule_id=? WHERE id=?"); - massUpdate.execute(new MassUpdate.Handler() { - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - Long id = row.getNullableLong(1); - Long ruleId = row.getNullableLong(2); - - update.setLong(1, ruleId); - update.setLong(2, id); - return true; - } - }); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/RequirementMeasuresMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/RequirementMeasuresMigrationStep.java new file mode 100644 index 00000000000..5474d9785f2 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/RequirementMeasuresMigrationStep.java @@ -0,0 +1,61 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v43; + +import java.sql.SQLException; + +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; + +/** + * Used in the Active Record Migration 521 + * + * @since 4.3 + */ +public class RequirementMeasuresMigrationStep extends BaseDataChange { + + public RequirementMeasuresMigrationStep(Database database) { + super(database); + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("SELECT project_measures.id,characteristics.rule_id FROM project_measures " + + "INNER JOIN characteristics ON characteristics.id = project_measures.characteristic_id " + + "WHERE characteristics.rule_id IS NOT NULL"); + massUpdate.update("UPDATE project_measures SET characteristic_id=null,rule_id=? WHERE id=?"); + massUpdate.execute(new MassUpdate.Handler() { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + Long id = row.getNullableLong(1); + Long ruleId = row.getNullableLong(2); + + update.setLong(1, ruleId); + update.setLong(2, id); + return true; + } + }); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigration.java deleted file mode 100644 index 2ce40849d72..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigration.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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. - */ - -package org.sonar.server.db.migrations.v43; - -import org.apache.commons.lang.StringUtils; -import org.sonar.core.persistence.Database; -import org.sonar.core.properties.PropertiesDao; -import org.sonar.server.db.migrations.BaseDataChange; -import org.sonar.server.db.migrations.MassUpdate; -import org.sonar.server.db.migrations.Select; -import org.sonar.server.db.migrations.SqlStatement; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.sql.SQLException; -import java.util.List; - -/** - * Used in the Active Record Migration 515 - * - * @since 4.3 - */ -public class TechnicalDebtMeasuresMigration extends BaseDataChange { - - private final WorkDurationConvertor workDurationConvertor; - - public TechnicalDebtMeasuresMigration(Database database, PropertiesDao propertiesDao) { - super(database); - this.workDurationConvertor = new WorkDurationConvertor(propertiesDao); - } - - @Override - public void execute(Context context) throws SQLException { - workDurationConvertor.init(); - - List metricIds = context.prepareSelect("select id from metrics " + - "where name='sqale_index' or name='new_technical_debt' " + - "or name='sqale_effort_to_grade_a' or name='sqale_effort_to_grade_b' or name='sqale_effort_to_grade_c' " + - "or name='sqale_effort_to_grade_d' or name='blocker_remediation_cost' or name='critical_remediation_cost' " + - "or name='major_remediation_cost' or name='minor_remediation_cost' or name='info_remediation_cost'").list(Select.LONG_READER); - - if (!metricIds.isEmpty()) { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.rowPluralName("measures"); - - SqlStatement select = massUpdate.select("SELECT pm.id, pm.value " + - ", pm.variation_value_1 , pm.variation_value_2, pm.variation_value_3 " + - ", pm.variation_value_4 , pm.variation_value_5 " + - " FROM project_measures pm " + - " WHERE pm.metric_id IN (" + StringUtils.repeat("?", ",", metricIds.size()) + ")"); - for (int i = 0; i < metricIds.size(); i++) { - select.setLong(i + 1, metricIds.get(i)); - } - massUpdate.update("UPDATE project_measures SET value=?," + - "variation_value_1=?,variation_value_2=?,variation_value_3=?,variation_value_4=?,variation_value_5=? WHERE id=?"); - massUpdate.execute(new Converter()); - } - } - - private class Converter implements MassUpdate.Handler { - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - Long id = row.getNullableLong(1); - Double value = row.getNullableDouble(2); - Double var1 = row.getNullableDouble(3); - Double var2 = row.getNullableDouble(4); - Double var3 = row.getNullableDouble(5); - Double var4 = row.getNullableDouble(6); - Double var5 = row.getNullableDouble(7); - - update.setLong(1, convertDebtForDays(value)); - update.setLong(2, convertDebtForDays(var1)); - update.setLong(3, convertDebtForDays(var2)); - update.setLong(4, convertDebtForDays(var3)); - update.setLong(5, convertDebtForDays(var4)); - update.setLong(6, convertDebtForDays(var5)); - update.setLong(7, id); - return true; - } - - @CheckForNull - private Long convertDebtForDays(@Nullable Double data) { - if (data != null) { - return workDurationConvertor.createFromDays(data); - } - return null; - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigrationStep.java new file mode 100644 index 00000000000..b892e4667d0 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigrationStep.java @@ -0,0 +1,108 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v43; + +import java.sql.SQLException; +import java.util.List; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +import org.apache.commons.lang.StringUtils; +import org.sonar.core.persistence.Database; +import org.sonar.core.properties.PropertiesDao; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; + +/** + * Used in the Active Record Migration 515 + * + * @since 4.3 + */ +public class TechnicalDebtMeasuresMigrationStep extends BaseDataChange { + + private final WorkDurationConvertor workDurationConvertor; + + public TechnicalDebtMeasuresMigrationStep(Database database, PropertiesDao propertiesDao) { + super(database); + this.workDurationConvertor = new WorkDurationConvertor(propertiesDao); + } + + @Override + public void execute(Context context) throws SQLException { + workDurationConvertor.init(); + + List metricIds = context.prepareSelect("select id from metrics " + + "where name='sqale_index' or name='new_technical_debt' " + + "or name='sqale_effort_to_grade_a' or name='sqale_effort_to_grade_b' or name='sqale_effort_to_grade_c' " + + "or name='sqale_effort_to_grade_d' or name='blocker_remediation_cost' or name='critical_remediation_cost' " + + "or name='major_remediation_cost' or name='minor_remediation_cost' or name='info_remediation_cost'").list(Select.LONG_READER); + + if (!metricIds.isEmpty()) { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.rowPluralName("measures"); + + SqlStatement select = massUpdate.select("SELECT pm.id, pm.value " + + ", pm.variation_value_1 , pm.variation_value_2, pm.variation_value_3 " + + ", pm.variation_value_4 , pm.variation_value_5 " + + " FROM project_measures pm " + + " WHERE pm.metric_id IN (" + StringUtils.repeat("?", ",", metricIds.size()) + ")"); + for (int i = 0; i < metricIds.size(); i++) { + select.setLong(i + 1, metricIds.get(i)); + } + massUpdate.update("UPDATE project_measures SET value=?," + + "variation_value_1=?,variation_value_2=?,variation_value_3=?,variation_value_4=?,variation_value_5=? WHERE id=?"); + massUpdate.execute(new Converter()); + } + } + + private class Converter implements MassUpdate.Handler { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + Long id = row.getNullableLong(1); + Double value = row.getNullableDouble(2); + Double var1 = row.getNullableDouble(3); + Double var2 = row.getNullableDouble(4); + Double var3 = row.getNullableDouble(5); + Double var4 = row.getNullableDouble(6); + Double var5 = row.getNullableDouble(7); + + update.setLong(1, convertDebtForDays(value)); + update.setLong(2, convertDebtForDays(var1)); + update.setLong(3, convertDebtForDays(var2)); + update.setLong(4, convertDebtForDays(var3)); + update.setLong(5, convertDebtForDays(var4)); + update.setLong(6, convertDebtForDays(var5)); + update.setLong(7, id); + return true; + } + + @CheckForNull + private Long convertDebtForDays(@Nullable Double data) { + if (data != null) { + return workDurationConvertor.createFromDays(data); + } + return null; + } + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/WorkDurationConvertor.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/WorkDurationConvertor.java index bcdab54e5cb..fd127cf2170 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/WorkDurationConvertor.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/WorkDurationConvertor.java @@ -78,7 +78,7 @@ class WorkDurationConvertor { } } - private void checkHoursInDay(){ + private void checkHoursInDay() { if (hoursInDay == null) { throw new IllegalStateException("init() has not been called"); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ChangeLogMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ChangeLogMigration.java deleted file mode 100644 index ca1ca126cd8..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ChangeLogMigration.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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. - */ -package org.sonar.server.db.migrations.v44; - -import org.apache.commons.lang.StringUtils; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.KeyValueFormat; -import org.sonar.api.utils.internal.Uuids; -import org.sonar.core.activity.db.ActivityDto; -import org.sonar.core.persistence.DbSession; -import org.sonar.core.persistence.migration.v44.ChangeLog; -import org.sonar.core.persistence.migration.v44.Migration44Mapper; -import org.sonar.core.qualityprofile.db.ActiveRuleKey; -import org.sonar.core.rule.SeverityUtil; -import org.sonar.server.activity.Activity; -import org.sonar.server.activity.db.ActivityDao; -import org.sonar.server.db.DbClient; -import org.sonar.server.db.migrations.DatabaseMigration; -import org.sonar.server.qualityprofile.ActiveRuleChange; - -import java.util.Date; -import java.util.Iterator; -import java.util.List; - -/** - * SONAR-5329 - * Transition ActiveRuleChanges to ActivityLog - *

- * Used in the Active Record Migration 548. - * - * @since 4.4 - */ -public class ChangeLogMigration implements DatabaseMigration { - - private final ActivityDao dao; - private final DbClient db; - - public ChangeLogMigration(ActivityDao dao, DbClient db) { - this.dao = dao; - this.db = db; - } - - @Override - public void execute() { - DbSession session = db.openSession(false); - Migration44Mapper migrationMapper = session.getMapper(Migration44Mapper.class); - try { - executeUpsert(session, ActiveRuleChange.Type.ACTIVATED, migrationMapper.selectActiveRuleChange(true)); - executeUpsert(session, ActiveRuleChange.Type.UPDATED, migrationMapper.selectActiveRuleChange(null)); - executeUpsert(session, ActiveRuleChange.Type.DEACTIVATED, migrationMapper.selectActiveRuleChange(false)); - session.commit(); - } finally { - session.close(); - } - } - - private void executeUpsert(DbSession session, ActiveRuleChange.Type type, List changes) { - - Iterator changeLogIterator = changes.iterator(); - if (changeLogIterator.hasNext()) { - // startCase - ChangeLog change = changeLogIterator.next(); - int currentId = change.getId(); - Date currentTimeStamp = change.getCreatedAt(); - String currentAuthor = change.getUserLogin(); - ActiveRuleChange ruleChange = newActiveRuleChance(type, change); - processRuleChange(ruleChange, change); - - while (changeLogIterator.hasNext()) { - change = changeLogIterator.next(); - int id = change.getId(); - if (id != currentId) { - saveActiveRuleChange(session, ruleChange, currentAuthor, currentTimeStamp); - currentId = id; - currentTimeStamp = change.getCreatedAt(); - currentAuthor = change.getUserLogin(); - ruleChange = newActiveRuleChance(type, change); - } - processRuleChange(ruleChange, change); - } - // save the last - saveActiveRuleChange(session, ruleChange, currentAuthor, currentTimeStamp); - } - } - - private void saveActiveRuleChange(DbSession session, ActiveRuleChange ruleChange, String author, Date currentTimeStamp) { - Activity activity = ruleChange.toActivity(); - ActivityDto dto = new ActivityDto(); - dto.setKey(Uuids.create()); - dto.setType(Activity.Type.QPROFILE.name()); - dto.setAction(activity.getAction()); - dto.setMessage(activity.getMessage()); - dto.setAuthor(author); - dto.setData(KeyValueFormat.format(activity.getData())); - dto.setCreatedAt(currentTimeStamp); - dao.insert(session, dto); - } - - private void processRuleChange(ActiveRuleChange ruleChange, ChangeLog change) { - ruleChange.setSeverity(SeverityUtil.getSeverityFromOrdinal(change.getSeverity())); - String paramName = change.getParamKey(); - String paramValue = change.getParamValue(); - if (StringUtils.isNotEmpty(paramName)) { - ruleChange.setParameter(paramName, paramValue); - } - } - - private ActiveRuleChange newActiveRuleChance(ActiveRuleChange.Type type, ChangeLog change) { - return ActiveRuleChange.createFor(type, - ActiveRuleKey.of(change.getProfileKey(), RuleKey.of(change.getRepository(), change.getRuleKey()))); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ChangeLogMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ChangeLogMigrationStep.java new file mode 100644 index 00000000000..9f52b1ef5f9 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ChangeLogMigrationStep.java @@ -0,0 +1,129 @@ +/* + * 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. + */ +package org.sonar.server.db.migrations.v44; + +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import org.apache.commons.lang.StringUtils; +import org.sonar.api.rule.RuleKey; +import org.sonar.api.utils.KeyValueFormat; +import org.sonar.api.utils.internal.Uuids; +import org.sonar.core.activity.db.ActivityDto; +import org.sonar.core.persistence.DbSession; +import org.sonar.core.persistence.migration.v44.ChangeLog; +import org.sonar.core.persistence.migration.v44.Migration44Mapper; +import org.sonar.core.qualityprofile.db.ActiveRuleKey; +import org.sonar.core.rule.SeverityUtil; +import org.sonar.server.activity.Activity; +import org.sonar.server.activity.db.ActivityDao; +import org.sonar.server.db.DbClient; +import org.sonar.server.db.migrations.MigrationStep; +import org.sonar.server.qualityprofile.ActiveRuleChange; + +/** + * SONAR-5329 + * Transition ActiveRuleChanges to ActivityLog + *

+ * Used in the Active Record Migration 548. + * + * @since 4.4 + */ +public class ChangeLogMigrationStep implements MigrationStep { + + private final ActivityDao dao; + private final DbClient db; + + public ChangeLogMigrationStep(ActivityDao dao, DbClient db) { + this.dao = dao; + this.db = db; + } + + @Override + public void execute() { + DbSession session = db.openSession(false); + Migration44Mapper migrationMapper = session.getMapper(Migration44Mapper.class); + try { + executeUpsert(session, ActiveRuleChange.Type.ACTIVATED, migrationMapper.selectActiveRuleChange(true)); + executeUpsert(session, ActiveRuleChange.Type.UPDATED, migrationMapper.selectActiveRuleChange(null)); + executeUpsert(session, ActiveRuleChange.Type.DEACTIVATED, migrationMapper.selectActiveRuleChange(false)); + session.commit(); + } finally { + session.close(); + } + } + + private void executeUpsert(DbSession session, ActiveRuleChange.Type type, List changes) { + + Iterator changeLogIterator = changes.iterator(); + if (changeLogIterator.hasNext()) { + // startCase + ChangeLog change = changeLogIterator.next(); + int currentId = change.getId(); + Date currentTimeStamp = change.getCreatedAt(); + String currentAuthor = change.getUserLogin(); + ActiveRuleChange ruleChange = newActiveRuleChance(type, change); + processRuleChange(ruleChange, change); + + while (changeLogIterator.hasNext()) { + change = changeLogIterator.next(); + int id = change.getId(); + if (id != currentId) { + saveActiveRuleChange(session, ruleChange, currentAuthor, currentTimeStamp); + currentId = id; + currentTimeStamp = change.getCreatedAt(); + currentAuthor = change.getUserLogin(); + ruleChange = newActiveRuleChance(type, change); + } + processRuleChange(ruleChange, change); + } + // save the last + saveActiveRuleChange(session, ruleChange, currentAuthor, currentTimeStamp); + } + } + + private void saveActiveRuleChange(DbSession session, ActiveRuleChange ruleChange, String author, Date currentTimeStamp) { + Activity activity = ruleChange.toActivity(); + ActivityDto dto = new ActivityDto(); + dto.setKey(Uuids.create()); + dto.setType(Activity.Type.QPROFILE.name()); + dto.setAction(activity.getAction()); + dto.setMessage(activity.getMessage()); + dto.setAuthor(author); + dto.setData(KeyValueFormat.format(activity.getData())); + dto.setCreatedAt(currentTimeStamp); + dao.insert(session, dto); + } + + private void processRuleChange(ActiveRuleChange ruleChange, ChangeLog change) { + ruleChange.setSeverity(SeverityUtil.getSeverityFromOrdinal(change.getSeverity())); + String paramName = change.getParamKey(); + String paramValue = change.getParamValue(); + if (StringUtils.isNotEmpty(paramName)) { + ruleChange.setParameter(paramName, paramValue); + } + } + + private ActiveRuleChange newActiveRuleChance(ActiveRuleChange.Type type, ChangeLog change) { + return ActiveRuleChange.createFor(type, + ActiveRuleKey.of(change.getProfileKey(), RuleKey.of(change.getRepository(), change.getRuleKey()))); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ConvertProfileMeasuresMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ConvertProfileMeasuresMigration.java deleted file mode 100644 index 994e8f15f4a..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ConvertProfileMeasuresMigration.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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. - */ - -package org.sonar.server.db.migrations.v44; - -import org.apache.commons.lang.ObjectUtils; -import org.sonar.api.utils.text.JsonWriter; -import org.sonar.core.UtcDateUtils; -import org.sonar.core.persistence.DbSession; -import org.sonar.core.persistence.migration.v44.Migration44Mapper; -import org.sonar.core.persistence.migration.v44.ProfileMeasure; -import org.sonar.core.persistence.migration.v44.QProfileDto44; -import org.sonar.server.db.DbClient; -import org.sonar.server.db.migrations.DatabaseMigration; - -import java.io.StringWriter; -import java.util.Date; - -/** - * Feed the new columns RULES_PROFILE.KEE and PARENT_KEE. - * - * @since 4.4 - */ -public class ConvertProfileMeasuresMigration implements DatabaseMigration { - - private final DbClient db; - - public ConvertProfileMeasuresMigration(DbClient db) { - this.db = db; - } - - @Override - public void execute() { - DbSession session = db.openSession(false); - try { - int i = 0; - Date now = new Date(); - Migration44Mapper mapper = session.getMapper(Migration44Mapper.class); - for (ProfileMeasure profileMeasure : mapper.selectProfileMeasures()) { - boolean updated = false; - Integer version = mapper.selectProfileVersion(profileMeasure.getSnapshotId()); - QProfileDto44 profile = mapper.selectProfileById(profileMeasure.getProfileId()); - if (profile != null) { - Date date = now; - if (version != null) { - date = (Date)ObjectUtils.defaultIfNull( - mapper.selectProfileVersionDate(profileMeasure.getProfileId(), version), now); - } - // see format of JSON in org.sonar.batch.rule.UsedQProfiles - StringWriter writer = new StringWriter(); - JsonWriter json = JsonWriter.of(writer); - json - .beginArray() - .beginObject() - .prop("key", profile.getKee()) - .prop("language", profile.getLanguage()) - .prop("name", profile.getName()) - .prop("rulesUpdatedAt", UtcDateUtils.formatDateTime(date)) - .endObject() - .endArray() - .close(); - mapper.updateProfileMeasure(profileMeasure.getId(), writer.toString()); - updated = true; - } - if (!updated) { - mapper.deleteProfileMeasure(profileMeasure.getId()); - } - if (i % 100 == 0) { - session.commit(); - i++; - } - } - session.commit(); - } finally { - session.close(); - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ConvertProfileMeasuresMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ConvertProfileMeasuresMigrationStep.java new file mode 100644 index 00000000000..228c834a0c7 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ConvertProfileMeasuresMigrationStep.java @@ -0,0 +1,95 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v44; + +import java.io.StringWriter; +import java.util.Date; + +import org.apache.commons.lang.ObjectUtils; +import org.sonar.api.utils.text.JsonWriter; +import org.sonar.core.UtcDateUtils; +import org.sonar.core.persistence.DbSession; +import org.sonar.core.persistence.migration.v44.Migration44Mapper; +import org.sonar.core.persistence.migration.v44.ProfileMeasure; +import org.sonar.core.persistence.migration.v44.QProfileDto44; +import org.sonar.server.db.DbClient; +import org.sonar.server.db.migrations.MigrationStep; + +/** + * Feed the new columns RULES_PROFILE.KEE and PARENT_KEE. + * + * @since 4.4 + */ +public class ConvertProfileMeasuresMigrationStep implements MigrationStep { + + private final DbClient db; + + public ConvertProfileMeasuresMigrationStep(DbClient db) { + this.db = db; + } + + @Override + public void execute() { + DbSession session = db.openSession(false); + try { + int i = 0; + Date now = new Date(); + Migration44Mapper mapper = session.getMapper(Migration44Mapper.class); + for (ProfileMeasure profileMeasure : mapper.selectProfileMeasures()) { + boolean updated = false; + Integer version = mapper.selectProfileVersion(profileMeasure.getSnapshotId()); + QProfileDto44 profile = mapper.selectProfileById(profileMeasure.getProfileId()); + if (profile != null) { + Date date = now; + if (version != null) { + date = (Date) ObjectUtils.defaultIfNull( + mapper.selectProfileVersionDate(profileMeasure.getProfileId(), version), now); + } + // see format of JSON in org.sonar.batch.rule.UsedQProfiles + StringWriter writer = new StringWriter(); + JsonWriter json = JsonWriter.of(writer); + json + .beginArray() + .beginObject() + .prop("key", profile.getKee()) + .prop("language", profile.getLanguage()) + .prop("name", profile.getName()) + .prop("rulesUpdatedAt", UtcDateUtils.formatDateTime(date)) + .endObject() + .endArray() + .close(); + mapper.updateProfileMeasure(profileMeasure.getId(), writer.toString()); + updated = true; + } + if (!updated) { + mapper.deleteProfileMeasure(profileMeasure.getId()); + } + if (i % 100 == 0) { + session.commit(); + i++; + } + } + session.commit(); + } finally { + session.close(); + } + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigration.java deleted file mode 100644 index 24a52f1be5f..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigration.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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. - */ - -package org.sonar.server.db.migrations.v44; - -import org.apache.commons.lang.ObjectUtils; -import org.sonar.api.utils.System2; -import org.sonar.core.UtcDateUtils; -import org.sonar.core.persistence.DbSession; -import org.sonar.core.persistence.migration.v44.Migration44Mapper; -import org.sonar.core.persistence.migration.v44.QProfileDto44; -import org.sonar.server.db.DbClient; -import org.sonar.server.db.migrations.DatabaseMigration; - -import java.util.Date; - -/** - * Feed the new columns RULES_PROFILES.CREATED_AT and UPDATED_AT - * - * @since 4.4 - */ -public class FeedQProfileDatesMigration implements DatabaseMigration { - - private final DbClient db; - private final System2 system; - - public FeedQProfileDatesMigration(DbClient db, System2 system) { - this.db = db; - this.system = system; - } - - @Override - public void execute() { - DbSession session = db.openSession(false); - try { - Date now = new Date(system.now()); - int i = 0; - Migration44Mapper migrationMapper = session.getMapper(Migration44Mapper.class); - for (QProfileDto44 profile : migrationMapper.selectAllProfiles()) { - Date createdAt = (Date) ObjectUtils.defaultIfNull(migrationMapper.selectProfileCreatedAt(profile.getId()), now); - Date updatedAt = (Date) ObjectUtils.defaultIfNull(migrationMapper.selectProfileUpdatedAt(profile.getId()), now); - - migrationMapper.updateProfileDates(profile.getId(), createdAt, updatedAt, UtcDateUtils.formatDateTime(updatedAt)); - if (i % 100 == 0) { - session.commit(); - i++; - } - } - session.commit(); - } finally { - session.close(); - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationStep.java new file mode 100644 index 00000000000..7ca01fac3f8 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationStep.java @@ -0,0 +1,71 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v44; + +import java.util.Date; + +import org.apache.commons.lang.ObjectUtils; +import org.sonar.api.utils.System2; +import org.sonar.core.UtcDateUtils; +import org.sonar.core.persistence.DbSession; +import org.sonar.core.persistence.migration.v44.Migration44Mapper; +import org.sonar.core.persistence.migration.v44.QProfileDto44; +import org.sonar.server.db.DbClient; +import org.sonar.server.db.migrations.MigrationStep; + +/** + * Feed the new columns RULES_PROFILES.CREATED_AT and UPDATED_AT + * + * @since 4.4 + */ +public class FeedQProfileDatesMigrationStep implements MigrationStep { + + private final DbClient db; + private final System2 system; + + public FeedQProfileDatesMigrationStep(DbClient db, System2 system) { + this.db = db; + this.system = system; + } + + @Override + public void execute() { + DbSession session = db.openSession(false); + try { + Date now = new Date(system.now()); + int i = 0; + Migration44Mapper migrationMapper = session.getMapper(Migration44Mapper.class); + for (QProfileDto44 profile : migrationMapper.selectAllProfiles()) { + Date createdAt = (Date) ObjectUtils.defaultIfNull(migrationMapper.selectProfileCreatedAt(profile.getId()), now); + Date updatedAt = (Date) ObjectUtils.defaultIfNull(migrationMapper.selectProfileUpdatedAt(profile.getId()), now); + + migrationMapper.updateProfileDates(profile.getId(), createdAt, updatedAt, UtcDateUtils.formatDateTime(updatedAt)); + if (i % 100 == 0) { + session.commit(); + i++; + } + } + session.commit(); + } finally { + session.close(); + } + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigration.java deleted file mode 100644 index 90c9ed80ffa..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigration.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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. - */ - -package org.sonar.server.db.migrations.v44; - -import org.apache.commons.lang.RandomStringUtils; -import org.sonar.core.persistence.Database; -import org.sonar.server.db.migrations.BaseDataChange; -import org.sonar.server.db.migrations.MassUpdate; -import org.sonar.server.db.migrations.Select; -import org.sonar.server.db.migrations.SqlStatement; -import org.sonar.server.util.Slug; - -import java.sql.SQLException; - -/** - * Feed the new columns RULES_PROFILES.KEE and PARENT_KEE. - * - * @since 4.4 - */ -public class FeedQProfileKeysMigration extends BaseDataChange { - - public FeedQProfileKeysMigration(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - updateKeys(context); - updateParentKeys(context); - } - - private void updateKeys(Context context) throws SQLException { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("SELECT id,language,name FROM rules_profiles"); - massUpdate.update("UPDATE rules_profiles SET kee=? WHERE id=?"); - massUpdate.rowPluralName("profiles"); - massUpdate.execute(new MassUpdate.Handler() { - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - Long id = row.getNullableLong(1); - String lang = row.getNullableString(2); - String name = row.getNullableString(3); - - update.setString(1, Slug.slugify(String.format("%s %s %s", lang, name, RandomStringUtils.randomNumeric(5)))); - update.setLong(2, id); - return true; - } - }); - } - - private void updateParentKeys(Context context) throws SQLException { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("SELECT child.id,parent.kee FROM rules_profiles child, rules_profiles parent WHERE child.parent_name=parent.name " + - "and child.language=parent.language AND child.parent_name IS NOT NULL"); - massUpdate.update("UPDATE rules_profiles SET parent_kee=? WHERE id=?"); - massUpdate.execute(new MassUpdate.Handler() { - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - Long id = row.getNullableLong(1); - String parentKey = row.getNullableString(2); - - update.setString(1, parentKey); - update.setLong(2, id); - return true; - } - }); - - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigrationStep.java new file mode 100644 index 00000000000..7e981341588 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigrationStep.java @@ -0,0 +1,87 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v44; + +import java.sql.SQLException; + +import org.apache.commons.lang.RandomStringUtils; +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; +import org.sonar.server.util.Slug; + +/** + * Feed the new columns RULES_PROFILES.KEE and PARENT_KEE. + * + * @since 4.4 + */ +public class FeedQProfileKeysMigrationStep extends BaseDataChange { + + public FeedQProfileKeysMigrationStep(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + updateKeys(context); + updateParentKeys(context); + } + + private void updateKeys(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("SELECT id,language,name FROM rules_profiles"); + massUpdate.update("UPDATE rules_profiles SET kee=? WHERE id=?"); + massUpdate.rowPluralName("profiles"); + massUpdate.execute(new MassUpdate.Handler() { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + Long id = row.getNullableLong(1); + String lang = row.getNullableString(2); + String name = row.getNullableString(3); + + update.setString(1, Slug.slugify(String.format("%s %s %s", lang, name, RandomStringUtils.randomNumeric(5)))); + update.setLong(2, id); + return true; + } + }); + } + + private void updateParentKeys(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("SELECT child.id,parent.kee FROM rules_profiles child, rules_profiles parent WHERE child.parent_name=parent.name " + + "and child.language=parent.language AND child.parent_name IS NOT NULL"); + massUpdate.update("UPDATE rules_profiles SET parent_kee=? WHERE id=?"); + massUpdate.execute(new MassUpdate.Handler() { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + Long id = row.getNullableLong(1); + String parentKey = row.getNullableString(2); + + update.setString(1, parentKey); + update.setLong(2, id); + return true; + } + }); + + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/IssueActionPlanKeyMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/IssueActionPlanKeyMigration.java deleted file mode 100644 index 9adad2dab5f..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/IssueActionPlanKeyMigration.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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. - */ - -package org.sonar.server.db.migrations.v44; - -import org.sonar.api.utils.System2; -import org.sonar.core.persistence.Database; -import org.sonar.server.db.migrations.BaseDataChange; -import org.sonar.server.db.migrations.MassUpdate; -import org.sonar.server.db.migrations.Select; -import org.sonar.server.db.migrations.SqlStatement; - -import java.sql.SQLException; -import java.util.Date; - -/** - * SONAR-5218 - * Update all issues having action plan linked on removed action plan. - *

- * Used in the Active Record Migration 531. - * - * @since 4.4 - */ -public class IssueActionPlanKeyMigration extends BaseDataChange { - - private final System2 system2; - - public IssueActionPlanKeyMigration(Database database, System2 system2) { - super(database); - this.system2 = system2; - } - - @Override - public void execute(Context context) throws SQLException { - final Date now = new Date(system2.now()); - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("SELECT i.id FROM issues i " + - "LEFT OUTER JOIN action_plans ap ON ap.kee=i.action_plan_key " + - "WHERE i.action_plan_key IS NOT NULL " + - "AND ap.kee is null"); - massUpdate.update("UPDATE issues SET action_plan_key=NULL,updated_at=? WHERE id=?"); - massUpdate.execute(new MassUpdate.Handler() { - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - Long id = row.getNullableLong(1); - - update.setDate(1, now); - update.setLong(2, id); - return true; - } - }); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/IssueActionPlanKeyMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/IssueActionPlanKeyMigrationStep.java new file mode 100644 index 00000000000..408301595e5 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/IssueActionPlanKeyMigrationStep.java @@ -0,0 +1,70 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v44; + +import java.sql.SQLException; +import java.util.Date; + +import org.sonar.api.utils.System2; +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; + +/** + * SONAR-5218 + * Update all issues having action plan linked on removed action plan. + *

+ * Used in the Active Record Migration 531. + * + * @since 4.4 + */ +public class IssueActionPlanKeyMigrationStep extends BaseDataChange { + + private final System2 system2; + + public IssueActionPlanKeyMigrationStep(Database database, System2 system2) { + super(database); + this.system2 = system2; + } + + @Override + public void execute(Context context) throws SQLException { + final Date now = new Date(system2.now()); + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("SELECT i.id FROM issues i " + + "LEFT OUTER JOIN action_plans ap ON ap.kee=i.action_plan_key " + + "WHERE i.action_plan_key IS NOT NULL " + + "AND ap.kee is null"); + massUpdate.update("UPDATE issues SET action_plan_key=NULL,updated_at=? WHERE id=?"); + massUpdate.execute(new MassUpdate.Handler() { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + Long id = row.getNullableLong(1); + + update.setDate(1, now); + update.setLong(2, id); + return true; + } + }); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/MeasureDataMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/MeasureDataMigration.java deleted file mode 100644 index 23ecb4c450b..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/MeasureDataMigration.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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. - */ - -package org.sonar.server.db.migrations.v44; - -import org.sonar.core.persistence.Database; -import org.sonar.server.db.migrations.BaseDataChange; -import org.sonar.server.db.migrations.MassUpdate; -import org.sonar.server.db.migrations.Select; -import org.sonar.server.db.migrations.SqlStatement; - -import java.sql.SQLException; - -/** - * SONAR-5249 - * Merge measure data table into project_measure - * - * Used in the Active Record Migration 530. - * @since 4.4 - */ -public class MeasureDataMigration extends BaseDataChange { - - public MeasureDataMigration(Database database) { - super(database); - } - - @Override - public void execute(Context context) throws SQLException { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.rowPluralName("measures"); - massUpdate.select("select md.id, md.measure_id FROM measure_data md " + - "inner join project_measures m on m.id=md.measure_id and m.measure_data is null"); - massUpdate.update("update project_measures SET measure_data = (SELECT md.data FROM measure_data md WHERE md.id = ?) WHERE id=?"); - massUpdate.execute(new MassUpdate.Handler() { - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - Long id = row.getNullableLong(1); - Long measureId = row.getNullableLong(2); - - update.setLong(1, id); - update.setLong(2, measureId); - return true; - } - }); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/MeasureDataMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/MeasureDataMigrationStep.java new file mode 100644 index 00000000000..b48870d4eb5 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/MeasureDataMigrationStep.java @@ -0,0 +1,63 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v44; + +import java.sql.SQLException; + +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; + +/** + * SONAR-5249 + * Merge measure data table into project_measure + * + * Used in the Active Record Migration 530. + * @since 4.4 + */ +public class MeasureDataMigrationStep extends BaseDataChange { + + public MeasureDataMigrationStep(Database database) { + super(database); + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.rowPluralName("measures"); + massUpdate.select("select md.id, md.measure_id FROM measure_data md " + + "inner join project_measures m on m.id=md.measure_id and m.measure_data is null"); + massUpdate.update("update project_measures SET measure_data = (SELECT md.data FROM measure_data md WHERE md.id = ?) WHERE id=?"); + massUpdate.execute(new MassUpdate.Handler() { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + Long id = row.getNullableLong(1); + Long measureId = row.getNullableLong(2); + + update.setLong(1, id); + update.setLong(2, measureId); + return true; + } + }); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/AddMissingRuleParameterDefaultValuesMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/AddMissingRuleParameterDefaultValuesMigration.java deleted file mode 100644 index 02b02f8d727..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/AddMissingRuleParameterDefaultValuesMigration.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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. - */ -package org.sonar.server.db.migrations.v45; - -import org.sonar.api.utils.System2; -import org.sonar.core.persistence.Database; -import org.sonar.server.db.migrations.BaseDataChange; -import org.sonar.server.db.migrations.Select; -import org.sonar.server.db.migrations.Upsert; - -import javax.annotation.Nullable; - -import java.sql.SQLException; -import java.util.Date; -import java.util.List; - -/** - * SONAR-5446 - */ -public class AddMissingRuleParameterDefaultValuesMigration extends BaseDataChange { - - private final System2 system; - - public AddMissingRuleParameterDefaultValuesMigration(Database db, System2 system) { - super(db); - this.system = system; - } - - @Override - public void execute(Context context) throws SQLException { - // get all the parameters with default value - List ruleParameters = context.prepareSelect("select id,rule_id,name,default_value from rules_parameters where default_value is not null") - .list(new Select.RowReader() { - @Override - public RuleParam read(Select.Row row) throws SQLException { - return new RuleParam(row.getNullableLong(1), row.getNullableLong(2), row.getNullableString(3), row.getNullableString(4)); - } - }); - - for (RuleParam ruleParameter : ruleParameters) { - List activeRules = context.prepareSelect("select ar.id, ar.profile_id from active_rules ar " + - "left outer join active_rule_parameters arp on arp.active_rule_id=ar.id and arp.rules_parameter_id=? " + - "where ar.rule_id=? and arp.id is null") - .setLong(1, ruleParameter.id) - .setLong(2, ruleParameter.ruleId) - .list(new Select.RowReader() { - @Override - public ActiveRule read(Select.Row row) throws SQLException { - return new ActiveRule(row.getNullableLong(1), row.getNullableLong(2)); - } - }); - - Upsert upsert = context.prepareUpsert("insert into active_rule_parameters(active_rule_id, rules_parameter_id, value, rules_parameter_key) values (?, ?, ?, ?)"); - for (ActiveRule activeRule : activeRules) { - upsert - .setLong(1, activeRule.id) - .setLong(2, ruleParameter.id) - .setString(3, ruleParameter.defaultValue) - .setString(4, ruleParameter.name) - .addBatch(); - } - if (!activeRules.isEmpty()) { - upsert.execute().commit().close(); - } - - // update date for ES indexation - upsert = context.prepareUpsert("update active_rules set updated_at=? where id=?"); - Date now = new Date(system.now()); - for (ActiveRule activeRule : activeRules) { - upsert - .setDate(1, now) - .setLong(2, activeRule.id) - .addBatch(); - } - if (!activeRules.isEmpty()) { - upsert.execute().commit().close(); - } - } - } - - private static class RuleParam { - final Long id, ruleId; - final String defaultValue, name; - - RuleParam(@Nullable Long id, @Nullable Long ruleId, @Nullable String name, @Nullable String defaultValue) { - this.id = id; - this.ruleId = ruleId; - this.name = name; - this.defaultValue = defaultValue; - } - } - - private static class ActiveRule { - final Long id, profileId; - - ActiveRule(@Nullable Long id, @Nullable Long profileId) { - this.id = id; - this.profileId = profileId; - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/AddMissingRuleParameterDefaultValuesMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/AddMissingRuleParameterDefaultValuesMigrationStep.java new file mode 100644 index 00000000000..0000e546596 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/AddMissingRuleParameterDefaultValuesMigrationStep.java @@ -0,0 +1,118 @@ +/* + * 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. + */ +package org.sonar.server.db.migrations.v45; + +import java.sql.SQLException; +import java.util.Date; +import java.util.List; + +import javax.annotation.Nullable; + +import org.sonar.api.utils.System2; +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.Upsert; + +/** + * SONAR-5446 + */ +public class AddMissingRuleParameterDefaultValuesMigrationStep extends BaseDataChange { + + private final System2 system; + + public AddMissingRuleParameterDefaultValuesMigrationStep(Database db, System2 system) { + super(db); + this.system = system; + } + + @Override + public void execute(Context context) throws SQLException { + // get all the parameters with default value + List ruleParameters = context.prepareSelect("select id,rule_id,name,default_value from rules_parameters where default_value is not null") + .list(new Select.RowReader() { + @Override + public RuleParam read(Select.Row row) throws SQLException { + return new RuleParam(row.getNullableLong(1), row.getNullableLong(2), row.getNullableString(3), row.getNullableString(4)); + } + }); + + for (RuleParam ruleParameter : ruleParameters) { + List activeRules = context.prepareSelect("select ar.id, ar.profile_id from active_rules ar " + + "left outer join active_rule_parameters arp on arp.active_rule_id=ar.id and arp.rules_parameter_id=? " + + "where ar.rule_id=? and arp.id is null") + .setLong(1, ruleParameter.id) + .setLong(2, ruleParameter.ruleId) + .list(new Select.RowReader() { + @Override + public ActiveRule read(Select.Row row) throws SQLException { + return new ActiveRule(row.getNullableLong(1), row.getNullableLong(2)); + } + }); + + Upsert upsert = context.prepareUpsert("insert into active_rule_parameters(active_rule_id, rules_parameter_id, value, rules_parameter_key) values (?, ?, ?, ?)"); + for (ActiveRule activeRule : activeRules) { + upsert + .setLong(1, activeRule.id) + .setLong(2, ruleParameter.id) + .setString(3, ruleParameter.defaultValue) + .setString(4, ruleParameter.name) + .addBatch(); + } + if (!activeRules.isEmpty()) { + upsert.execute().commit().close(); + } + + // update date for ES indexation + upsert = context.prepareUpsert("update active_rules set updated_at=? where id=?"); + Date now = new Date(system.now()); + for (ActiveRule activeRule : activeRules) { + upsert + .setDate(1, now) + .setLong(2, activeRule.id) + .addBatch(); + } + if (!activeRules.isEmpty()) { + upsert.execute().commit().close(); + } + } + } + + private static class RuleParam { + final Long id, ruleId; + final String defaultValue, name; + + RuleParam(@Nullable Long id, @Nullable Long ruleId, @Nullable String name, @Nullable String defaultValue) { + this.id = id; + this.ruleId = ruleId; + this.name = name; + this.defaultValue = defaultValue; + } + } + + private static class ActiveRule { + final Long id, profileId; + + ActiveRule(@Nullable Long id, @Nullable Long profileId) { + this.id = id; + this.profileId = profileId; + } + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigration.java deleted file mode 100644 index 0a79bd6beda..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigration.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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. - */ - -package org.sonar.server.db.migrations.v45; - -import org.sonar.core.persistence.DbSession; -import org.sonar.core.persistence.migration.v44.Migration44Mapper; -import org.sonar.server.db.DbClient; -import org.sonar.server.db.migrations.DatabaseMigration; - -/** - * See http://jira.codehaus.org/browse/SONAR-5580 - * {@link org.sonar.server.db.migrations.v44.ConvertProfileMeasuresMigration} - * introduced a regression in 4.4. Measures on orphan profiles were kept - * in old format (no JSON data but numeric value of profile id) - * - * @see org.sonar.server.db.migrations.v44.ConvertProfileMeasuresMigration - * @since 4.5 - */ -public class DeleteMeasuresOnDeletedProfilesMigration implements DatabaseMigration { - - private final DbClient db; - - public DeleteMeasuresOnDeletedProfilesMigration(DbClient db) { - this.db = db; - } - - @Override - public void execute() { - DbSession session = db.openSession(false); - try { - Migration44Mapper mapper = session.getMapper(Migration44Mapper.class); - for (Long measureId : mapper.selectMeasuresOnDeletedQualityProfiles()) { - mapper.deleteProfileMeasure(measureId); - } - session.commit(); - - } finally { - session.close(); - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigrationStep.java new file mode 100644 index 00000000000..b61c62a09ad --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigrationStep.java @@ -0,0 +1,60 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v45; + +import org.sonar.core.persistence.DbSession; +import org.sonar.core.persistence.migration.v44.Migration44Mapper; +import org.sonar.server.db.DbClient; +import org.sonar.server.db.migrations.MigrationStep; +import org.sonar.server.db.migrations.v44.ConvertProfileMeasuresMigrationStep; + +/** + * See http://jira.codehaus.org/browse/SONAR-5580 + * {@link ConvertProfileMeasuresMigrationStep} + * introduced a regression in 4.4. Measures on orphan profiles were kept + * in old format (no JSON data but numeric value of profile id) + * + * @see ConvertProfileMeasuresMigrationStep + * @since 4.5 + */ +public class DeleteMeasuresOnDeletedProfilesMigrationStep implements MigrationStep { + + private final DbClient db; + + public DeleteMeasuresOnDeletedProfilesMigrationStep(DbClient db) { + this.db = db; + } + + @Override + public void execute() { + DbSession session = db.openSession(false); + try { + Migration44Mapper mapper = session.getMapper(Migration44Mapper.class); + for (Long measureId : mapper.selectMeasuresOnDeletedQualityProfiles()) { + mapper.deleteProfileMeasure(measureId); + } + session.commit(); + + } finally { + session.close(); + } + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigration.java deleted file mode 100644 index 5d87dc3f60f..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigration.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * 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. - */ -package org.sonar.server.db.migrations.v451; - -import com.google.common.base.Predicate; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Multimap; -import org.sonar.api.utils.System2; -import org.sonar.core.persistence.DbSession; -import org.sonar.core.persistence.migration.v45.Migration45Mapper; -import org.sonar.core.persistence.migration.v45.Rule; -import org.sonar.core.persistence.migration.v45.RuleParameter; -import org.sonar.server.db.DbClient; -import org.sonar.server.db.migrations.DatabaseMigration; -import org.sonar.server.util.ProgressLogger; - -import javax.annotation.Nullable; - -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.concurrent.atomic.AtomicLong; - -/** - * See http://jira.codehaus.org/browse/SONAR-5575 - * - * Add missing parameters (with no value) on each custom rules - * - * @since 4.5.1 - */ -public class AddMissingCustomRuleParametersMigration implements DatabaseMigration { - - private final DbClient db; - private final System2 system; - private final AtomicLong counter = new AtomicLong(0L); - - public AddMissingCustomRuleParametersMigration(DbClient db, System2 system) { - this.db = db; - this.system = system; - } - - @Override - public void execute() { - ProgressLogger progress = ProgressLogger.create(getClass(), counter); - progress.start(); - - DbSession session = db.openSession(false); - try { - Migration45Mapper mapper = session.getMapper(Migration45Mapper.class); - - List templateRuleParams = mapper.selectAllTemplateRuleParameters(); - Multimap templateRuleParamsByRuleId = ArrayListMultimap.create(); - for (RuleParameter templateRuleParam : templateRuleParams) { - templateRuleParamsByRuleId.put(templateRuleParam.getRuleId(), templateRuleParam); - } - - List customRules = mapper.selectAllCustomRules(); - Multimap customRuleIdsByTemplateRuleId = HashMultimap.create(); - for (Rule customRule : customRules) { - customRuleIdsByTemplateRuleId.put(customRule.getTemplateId(), customRule.getId()); - } - - List customRuleParams = mapper.selectAllCustomRuleParameters(); - Multimap customRuleParamsByRuleId = ArrayListMultimap.create(); - for (RuleParameter customRuleParam : customRuleParams) { - customRuleParamsByRuleId.put(customRuleParam.getRuleId(), customRuleParam); - } - - // For each parameters of template rules, verify that each custom rules has the parameter - for (Integer templateRuleId : templateRuleParamsByRuleId.keySet()) { - for (RuleParameter templateRuleParam : templateRuleParamsByRuleId.get(templateRuleId)) { - // Each custom rule should have this parameter - insertCustomRuleParameterIfNotAlreadyExisting(templateRuleParam, templateRuleId, customRuleIdsByTemplateRuleId, customRuleParamsByRuleId, session); - } - } - - session.commit(); - - // log the total number of process rows - progress.log(); - } finally { - session.close(); - progress.stop(); - } - } - - private void insertCustomRuleParameterIfNotAlreadyExisting(RuleParameter templateRuleParam, Integer templateRuleId, - Multimap customRuleIdsByTemplateRuleId, - Multimap customRuleParamsByRuleId, - DbSession session) { - for (Integer customRuleId : customRuleIdsByTemplateRuleId.get(templateRuleId)) { - if (!hasParameter(templateRuleParam.getName(), customRuleParamsByRuleId.get(customRuleId))) { - // Insert new custom rule parameter - session.getMapper(Migration45Mapper.class).insertRuleParameter(new RuleParameter() - .setRuleId(customRuleId) - .setRuleTemplateId(templateRuleId) - .setName(templateRuleParam.getName()) - .setDescription(templateRuleParam.getDescription()) - .setType(templateRuleParam.getType()) - ); - - // Update updated at date of custom rule in order to allow E/S indexation - session.getMapper(Migration45Mapper.class).updateRuleUpdateAt(customRuleId, new Date(system.now())); - - counter.getAndIncrement(); - } - } - } - - private boolean hasParameter(final String parameter, Collection customRuleParams) { - return Iterables.any(customRuleParams, new Predicate() { - @Override - public boolean apply(@Nullable RuleParameter input) { - return input != null && input.getName().equals(parameter); - } - }); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationStep.java new file mode 100644 index 00000000000..55e26815b53 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationStep.java @@ -0,0 +1,138 @@ +/* + * 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. + */ +package org.sonar.server.db.migrations.v451; + +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.concurrent.atomic.AtomicLong; + +import javax.annotation.Nullable; + +import org.sonar.api.utils.System2; +import org.sonar.core.persistence.DbSession; +import org.sonar.core.persistence.migration.v45.Migration45Mapper; +import org.sonar.core.persistence.migration.v45.Rule; +import org.sonar.core.persistence.migration.v45.RuleParameter; +import org.sonar.server.db.DbClient; +import org.sonar.server.db.migrations.MigrationStep; +import org.sonar.server.util.ProgressLogger; + +import com.google.common.base.Predicate; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Iterables; +import com.google.common.collect.Multimap; + +/** + * See http://jira.codehaus.org/browse/SONAR-5575 + * + * Add missing parameters (with no value) on each custom rules + * + * @since 4.5.1 + */ +public class AddMissingCustomRuleParametersMigrationStep implements MigrationStep { + + private final DbClient db; + private final System2 system; + private final AtomicLong counter = new AtomicLong(0L); + + public AddMissingCustomRuleParametersMigrationStep(DbClient db, System2 system) { + this.db = db; + this.system = system; + } + + @Override + public void execute() { + ProgressLogger progress = ProgressLogger.create(getClass(), counter); + progress.start(); + + DbSession session = db.openSession(false); + try { + Migration45Mapper mapper = session.getMapper(Migration45Mapper.class); + + List templateRuleParams = mapper.selectAllTemplateRuleParameters(); + Multimap templateRuleParamsByRuleId = ArrayListMultimap.create(); + for (RuleParameter templateRuleParam : templateRuleParams) { + templateRuleParamsByRuleId.put(templateRuleParam.getRuleId(), templateRuleParam); + } + + List customRules = mapper.selectAllCustomRules(); + Multimap customRuleIdsByTemplateRuleId = HashMultimap.create(); + for (Rule customRule : customRules) { + customRuleIdsByTemplateRuleId.put(customRule.getTemplateId(), customRule.getId()); + } + + List customRuleParams = mapper.selectAllCustomRuleParameters(); + Multimap customRuleParamsByRuleId = ArrayListMultimap.create(); + for (RuleParameter customRuleParam : customRuleParams) { + customRuleParamsByRuleId.put(customRuleParam.getRuleId(), customRuleParam); + } + + // For each parameters of template rules, verify that each custom rules has the parameter + for (Integer templateRuleId : templateRuleParamsByRuleId.keySet()) { + for (RuleParameter templateRuleParam : templateRuleParamsByRuleId.get(templateRuleId)) { + // Each custom rule should have this parameter + insertCustomRuleParameterIfNotAlreadyExisting(templateRuleParam, templateRuleId, customRuleIdsByTemplateRuleId, customRuleParamsByRuleId, session); + } + } + + session.commit(); + + // log the total number of process rows + progress.log(); + } finally { + session.close(); + progress.stop(); + } + } + + private void insertCustomRuleParameterIfNotAlreadyExisting(RuleParameter templateRuleParam, Integer templateRuleId, + Multimap customRuleIdsByTemplateRuleId, + Multimap customRuleParamsByRuleId, + DbSession session) { + for (Integer customRuleId : customRuleIdsByTemplateRuleId.get(templateRuleId)) { + if (!hasParameter(templateRuleParam.getName(), customRuleParamsByRuleId.get(customRuleId))) { + // Insert new custom rule parameter + session.getMapper(Migration45Mapper.class).insertRuleParameter(new RuleParameter() + .setRuleId(customRuleId) + .setRuleTemplateId(templateRuleId) + .setName(templateRuleParam.getName()) + .setDescription(templateRuleParam.getDescription()) + .setType(templateRuleParam.getType()) + ); + + // Update updated at date of custom rule in order to allow E/S indexation + session.getMapper(Migration45Mapper.class).updateRuleUpdateAt(customRuleId, new Date(system.now())); + + counter.getAndIncrement(); + } + } + } + + private boolean hasParameter(final String parameter, Collection customRuleParams) { + return Iterables.any(customRuleParams, new Predicate() { + @Override + public boolean apply(@Nullable RuleParameter input) { + return input != null && input.getName().equals(parameter); + } + }); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivities.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivities.java index 49c50bc0980..234867cbb3c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivities.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivities.java @@ -19,6 +19,10 @@ */ package org.sonar.server.db.migrations.v451; +import java.sql.SQLException; + +import javax.annotation.Nullable; + import org.apache.commons.lang.StringUtils; import org.sonar.core.persistence.Database; import org.sonar.server.db.migrations.BaseDataChange; @@ -26,10 +30,6 @@ import org.sonar.server.db.migrations.MassUpdate; import org.sonar.server.db.migrations.Select; import org.sonar.server.db.migrations.SqlStatement; -import javax.annotation.Nullable; - -import java.sql.SQLException; - /** * See http://jira.codehaus.org/browse/SONAR-5758 * diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java index 03ad53ab61c..be975171650 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java @@ -19,6 +19,13 @@ */ package org.sonar.server.db.migrations.v50; +import static com.google.common.base.Charsets.UTF_8; + +import java.sql.SQLException; +import java.util.Date; + +import javax.annotation.Nullable; + import org.apache.commons.lang.StringUtils; import org.sonar.api.utils.System2; import org.sonar.core.persistence.Database; @@ -28,13 +35,6 @@ import org.sonar.server.db.migrations.Select.Row; import org.sonar.server.db.migrations.Select.RowReader; import org.sonar.server.db.migrations.SqlStatement; -import javax.annotation.Nullable; - -import java.sql.SQLException; -import java.util.Date; - -import static com.google.common.base.Charsets.UTF_8; - /** * Used in the Active Record Migration 714 * diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedIssueLongDates.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedIssueLongDates.java index 9b4dfca0e31..7bbfde25d5c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedIssueLongDates.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedIssueLongDates.java @@ -19,6 +19,9 @@ */ package org.sonar.server.db.migrations.v50; +import java.sql.SQLException; +import java.util.Date; + import org.sonar.api.utils.System2; import org.sonar.core.persistence.Database; import org.sonar.server.db.migrations.BaseDataChange; @@ -26,9 +29,6 @@ import org.sonar.server.db.migrations.MassUpdate; import org.sonar.server.db.migrations.Select; import org.sonar.server.db.migrations.SqlStatement; -import java.sql.SQLException; -import java.util.Date; - public class FeedIssueLongDates extends BaseDataChange { private final System2 system; diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedSnapshotSourcesUpdatedAt.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedSnapshotSourcesUpdatedAt.java index 589c080501e..f0a6e89393f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedSnapshotSourcesUpdatedAt.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedSnapshotSourcesUpdatedAt.java @@ -20,14 +20,14 @@ package org.sonar.server.db.migrations.v50; +import java.sql.SQLException; + import org.sonar.core.persistence.Database; import org.sonar.server.db.migrations.BaseDataChange; import org.sonar.server.db.migrations.MassUpdate; import org.sonar.server.db.migrations.Select; import org.sonar.server.db.migrations.SqlStatement; -import java.sql.SQLException; - /** * Used in the Active Record Migration 712 * diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java index ea3aa3ca172..fc26516b454 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java @@ -19,8 +19,20 @@ */ package org.sonar.server.db.migrations.v50; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableList; +import static com.google.common.base.Charsets.UTF_8; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStreamWriter; +import java.io.StringReader; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; + import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang.StringUtils; import org.codehaus.stax2.XMLInputFactory2; @@ -31,15 +43,8 @@ import org.sonar.api.measures.CoreMetrics; import org.sonar.api.utils.KeyValueFormat; import org.sonar.api.utils.text.CsvWriter; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; - -import java.io.ByteArrayOutputStream; -import java.io.OutputStreamWriter; -import java.io.StringReader; -import java.util.*; - -import static com.google.common.base.Charsets.UTF_8; +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableList; class FileSourceDto { diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/InsertProjectsAuthorizationUpdatedAtMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/InsertProjectsAuthorizationUpdatedAtMigration.java deleted file mode 100644 index c4688c28cb6..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/InsertProjectsAuthorizationUpdatedAtMigration.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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. - */ - -package org.sonar.server.db.migrations.v50; - -import org.sonar.api.utils.System2; -import org.sonar.core.persistence.Database; -import org.sonar.server.db.migrations.BaseDataChange; -import org.sonar.server.db.migrations.MassUpdate; -import org.sonar.server.db.migrations.Select; -import org.sonar.server.db.migrations.SqlStatement; - -import java.sql.SQLException; - -/** - * Used in the Active Record Migration 716 - * - * @since 5.0 - */ -public class InsertProjectsAuthorizationUpdatedAtMigration extends BaseDataChange { - - private final System2 system; - - public InsertProjectsAuthorizationUpdatedAtMigration(Database db, System2 system) { - super(db); - this.system = system; - } - - @Override - public void execute(Context context) throws SQLException { - final long now = system.now(); - - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("SELECT p.id FROM projects p WHERE p.scope=? AND p.enabled=? and p.authorization_updated_at IS NULL").setString(1, "PRJ").setBoolean(2, true); - massUpdate.update("UPDATE projects SET authorization_updated_at=? WHERE id=?"); - massUpdate.rowPluralName("projects"); - massUpdate.execute(new MassUpdate.Handler() { - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - Long id = row.getNullableLong(1); - update.setLong(1, now); - update.setLong(2, id); - return true; - } - }); - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/InsertProjectsAuthorizationUpdatedAtMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/InsertProjectsAuthorizationUpdatedAtMigrationStep.java new file mode 100644 index 00000000000..ca4e1083ca0 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/InsertProjectsAuthorizationUpdatedAtMigrationStep.java @@ -0,0 +1,65 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v50; + +import java.sql.SQLException; + +import org.sonar.api.utils.System2; +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; + +/** + * Used in the Active Record Migration 716 + * + * @since 5.0 + */ +public class InsertProjectsAuthorizationUpdatedAtMigrationStep extends BaseDataChange { + + private final System2 system; + + public InsertProjectsAuthorizationUpdatedAtMigrationStep(Database db, System2 system) { + super(db); + this.system = system; + } + + @Override + public void execute(Context context) throws SQLException { + final long now = system.now(); + + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("SELECT p.id FROM projects p WHERE p.scope=? AND p.enabled=? and p.authorization_updated_at IS NULL").setString(1, "PRJ").setBoolean(2, true); + massUpdate.update("UPDATE projects SET authorization_updated_at=? WHERE id=?"); + massUpdate.rowPluralName("projects"); + massUpdate.execute(new MassUpdate.Handler() { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + Long id = row.getNullableLong(1); + update.setLong(1, now); + update.setLong(2, id); + return true; + } + }); + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigration.java deleted file mode 100644 index c1ce39f0b36..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigration.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * 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. - */ - -package org.sonar.server.db.migrations.v50; - -import com.google.common.base.Splitter; -import com.google.common.base.Strings; -import org.apache.ibatis.session.ResultContext; -import org.apache.ibatis.session.ResultHandler; -import org.sonar.api.resources.Scopes; -import org.sonar.api.utils.internal.Uuids; -import org.sonar.core.persistence.DbSession; -import org.sonar.core.persistence.migration.v50.Component; -import org.sonar.core.persistence.migration.v50.Migration50Mapper; -import org.sonar.server.db.DbClient; -import org.sonar.server.db.migrations.DatabaseMigration; -import org.sonar.server.util.ProgressLogger; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicLong; - -import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Maps.newHashMap; - -/** - * Used in the Active Record Migration 705 - * - * @since 5.0 - */ -public class PopulateProjectsUuidColumnsMigration implements DatabaseMigration { - - private final DbClient db; - private final AtomicLong counter = new AtomicLong(0L); - - public PopulateProjectsUuidColumnsMigration(DbClient db) { - this.db = db; - } - - @Override - public void execute() { - ProgressLogger progress = ProgressLogger.create(getClass(), counter); - progress.start(); - - final DbSession readSession = db.openSession(false); - final DbSession writeSession = db.openSession(true); - try { - readSession.select("org.sonar.core.persistence.migration.v50.Migration50Mapper.selectRootProjects", new ResultHandler() { - @Override - public void handleResult(ResultContext context) { - Component project = (Component) context.getResultObject(); - Map uuidByComponentId = newHashMap(); - migrateEnabledComponents(readSession, writeSession, project, uuidByComponentId); - migrateDisabledComponents(readSession, writeSession, project, uuidByComponentId); - } - }); - writeSession.commit(true); - readSession.commit(true); - - migrateComponentsWithoutUuid(readSession, writeSession); - writeSession.commit(true); - - // log the total number of process rows - progress.log(); - } finally { - readSession.close(); - writeSession.close(); - progress.stop(); - } - } - - private void migrateEnabledComponents(DbSession readSession, DbSession writeSession, Component project, Map uuidByComponentId) { - Map componentsBySnapshotId = newHashMap(); - - List components = readSession.getMapper(Migration50Mapper.class).selectComponentChildrenForProjects(project.getId()); - components.add(project); - List componentsToMigrate = newArrayList(); - for (Component component : components) { - componentsBySnapshotId.put(component.getSnapshotId(), component); - - // Not migrate components already having an UUID - if (component.getUuid() == null) { - component.setUuid(getOrCreateUuid(component, uuidByComponentId)); - component.setProjectUuid(getOrCreateUuid(project, uuidByComponentId)); - component.setModuleUuidPath(""); - componentsToMigrate.add(component); - } - } - - for (Component component : componentsToMigrate) { - updateComponent(component, project, componentsBySnapshotId, uuidByComponentId); - writeSession.getMapper(Migration50Mapper.class).updateComponentUuids(component); - counter.getAndIncrement(); - } - } - - private void migrateDisabledComponents(DbSession readSession, DbSession writeSession, Component project, Map uuidByComponentId) { - String projectUuid = getOrCreateUuid(project, uuidByComponentId); - for (Component component : readSession.getMapper(Migration50Mapper.class).selectDisabledDirectComponentChildrenForProjects(project.getId())) { - component.setUuid(getOrCreateUuid(component, uuidByComponentId)); - component.setProjectUuid(projectUuid); - component.setModuleUuidPath(""); - - writeSession.getMapper(Migration50Mapper.class).updateComponentUuids(component); - counter.getAndIncrement(); - } - for (Component component : readSession.getMapper(Migration50Mapper.class).selectDisabledNoneDirectComponentChildrenForProjects(project.getId())) { - component.setUuid(getOrCreateUuid(component, uuidByComponentId)); - component.setProjectUuid(projectUuid); - component.setModuleUuidPath(""); - - writeSession.getMapper(Migration50Mapper.class).updateComponentUuids(component); - counter.getAndIncrement(); - } - } - - private void updateComponent(Component component, Component project, Map componentsBySnapshotId, Map uuidByComponentId) { - String snapshotPath = component.getSnapshotPath(); - StringBuilder moduleUuidPath = new StringBuilder(); - Component lastModule = null; - if (!Strings.isNullOrEmpty(snapshotPath)) { - for (String s : Splitter.on(".").omitEmptyStrings().split(snapshotPath)) { - Long snapshotId = Long.valueOf(s); - Component currentComponent = componentsBySnapshotId.get(snapshotId); - if (currentComponent.getScope().equals(Scopes.PROJECT)) { - lastModule = currentComponent; - moduleUuidPath.append(currentComponent.getUuid()).append("."); - } - } - } - if (moduleUuidPath.length() > 0) { - // Remove last '.' - moduleUuidPath.deleteCharAt(moduleUuidPath.length() - 1); - component.setModuleUuidPath(moduleUuidPath.toString()); - } - - // Module UUID contains direct module of a component - if (lastModule != null) { - component.setModuleUuid(getOrCreateUuid(lastModule, uuidByComponentId)); - } - } - - private void migrateComponentsWithoutUuid(DbSession readSession, DbSession writeSession) { - for (Component component : readSession.getMapper(Migration50Mapper.class).selectComponentsWithoutUuid()) { - String uuid = Uuids.create(); - component.setUuid(uuid); - component.setProjectUuid(uuid); - component.setModuleUuidPath(""); - - writeSession.getMapper(Migration50Mapper.class).updateComponentUuids(component); - counter.getAndIncrement(); - } - } - - private static String getOrCreateUuid(Component component, Map uuidByComponentId) { - String existingUuid = component.getUuid(); - String uuid = existingUuid == null ? uuidByComponentId.get(component.getId()) : existingUuid; - if (uuid == null) { - String newUuid = Uuids.create(); - uuidByComponentId.put(component.getId(), newUuid); - return newUuid; - } - return uuid; - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationStep.java new file mode 100644 index 00000000000..e6e51dcc498 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationStep.java @@ -0,0 +1,184 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v50; + +import static com.google.common.collect.Lists.newArrayList; +import static com.google.common.collect.Maps.newHashMap; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; + +import org.apache.ibatis.session.ResultContext; +import org.apache.ibatis.session.ResultHandler; +import org.sonar.api.resources.Scopes; +import org.sonar.api.utils.internal.Uuids; +import org.sonar.core.persistence.DbSession; +import org.sonar.core.persistence.migration.v50.Component; +import org.sonar.core.persistence.migration.v50.Migration50Mapper; +import org.sonar.server.db.DbClient; +import org.sonar.server.db.migrations.MigrationStep; +import org.sonar.server.util.ProgressLogger; + +import com.google.common.base.Splitter; +import com.google.common.base.Strings; + +/** + * Used in the Active Record Migration 705 + * + * @since 5.0 + */ +public class PopulateProjectsUuidColumnsMigrationStep implements MigrationStep { + + private final DbClient db; + private final AtomicLong counter = new AtomicLong(0L); + + public PopulateProjectsUuidColumnsMigrationStep(DbClient db) { + this.db = db; + } + + @Override + public void execute() { + ProgressLogger progress = ProgressLogger.create(getClass(), counter); + progress.start(); + + final DbSession readSession = db.openSession(false); + final DbSession writeSession = db.openSession(true); + try { + readSession.select("org.sonar.core.persistence.migration.v50.Migration50Mapper.selectRootProjects", new ResultHandler() { + @Override + public void handleResult(ResultContext context) { + Component project = (Component) context.getResultObject(); + Map uuidByComponentId = newHashMap(); + migrateEnabledComponents(readSession, writeSession, project, uuidByComponentId); + migrateDisabledComponents(readSession, writeSession, project, uuidByComponentId); + } + }); + writeSession.commit(true); + readSession.commit(true); + + migrateComponentsWithoutUuid(readSession, writeSession); + writeSession.commit(true); + + // log the total number of process rows + progress.log(); + } finally { + readSession.close(); + writeSession.close(); + progress.stop(); + } + } + + private void migrateEnabledComponents(DbSession readSession, DbSession writeSession, Component project, Map uuidByComponentId) { + Map componentsBySnapshotId = newHashMap(); + + List components = readSession.getMapper(Migration50Mapper.class).selectComponentChildrenForProjects(project.getId()); + components.add(project); + List componentsToMigrate = newArrayList(); + for (Component component : components) { + componentsBySnapshotId.put(component.getSnapshotId(), component); + + // Not migrate components already having an UUID + if (component.getUuid() == null) { + component.setUuid(getOrCreateUuid(component, uuidByComponentId)); + component.setProjectUuid(getOrCreateUuid(project, uuidByComponentId)); + component.setModuleUuidPath(""); + componentsToMigrate.add(component); + } + } + + for (Component component : componentsToMigrate) { + updateComponent(component, project, componentsBySnapshotId, uuidByComponentId); + writeSession.getMapper(Migration50Mapper.class).updateComponentUuids(component); + counter.getAndIncrement(); + } + } + + private void migrateDisabledComponents(DbSession readSession, DbSession writeSession, Component project, Map uuidByComponentId) { + String projectUuid = getOrCreateUuid(project, uuidByComponentId); + for (Component component : readSession.getMapper(Migration50Mapper.class).selectDisabledDirectComponentChildrenForProjects(project.getId())) { + component.setUuid(getOrCreateUuid(component, uuidByComponentId)); + component.setProjectUuid(projectUuid); + component.setModuleUuidPath(""); + + writeSession.getMapper(Migration50Mapper.class).updateComponentUuids(component); + counter.getAndIncrement(); + } + for (Component component : readSession.getMapper(Migration50Mapper.class).selectDisabledNoneDirectComponentChildrenForProjects(project.getId())) { + component.setUuid(getOrCreateUuid(component, uuidByComponentId)); + component.setProjectUuid(projectUuid); + component.setModuleUuidPath(""); + + writeSession.getMapper(Migration50Mapper.class).updateComponentUuids(component); + counter.getAndIncrement(); + } + } + + private void updateComponent(Component component, Component project, Map componentsBySnapshotId, Map uuidByComponentId) { + String snapshotPath = component.getSnapshotPath(); + StringBuilder moduleUuidPath = new StringBuilder(); + Component lastModule = null; + if (!Strings.isNullOrEmpty(snapshotPath)) { + for (String s : Splitter.on(".").omitEmptyStrings().split(snapshotPath)) { + Long snapshotId = Long.valueOf(s); + Component currentComponent = componentsBySnapshotId.get(snapshotId); + if (currentComponent.getScope().equals(Scopes.PROJECT)) { + lastModule = currentComponent; + moduleUuidPath.append(currentComponent.getUuid()).append("."); + } + } + } + if (moduleUuidPath.length() > 0) { + // Remove last '.' + moduleUuidPath.deleteCharAt(moduleUuidPath.length() - 1); + component.setModuleUuidPath(moduleUuidPath.toString()); + } + + // Module UUID contains direct module of a component + if (lastModule != null) { + component.setModuleUuid(getOrCreateUuid(lastModule, uuidByComponentId)); + } + } + + private void migrateComponentsWithoutUuid(DbSession readSession, DbSession writeSession) { + for (Component component : readSession.getMapper(Migration50Mapper.class).selectComponentsWithoutUuid()) { + String uuid = Uuids.create(); + component.setUuid(uuid); + component.setProjectUuid(uuid); + component.setModuleUuidPath(""); + + writeSession.getMapper(Migration50Mapper.class).updateComponentUuids(component); + counter.getAndIncrement(); + } + } + + private static String getOrCreateUuid(Component component, Map uuidByComponentId) { + String existingUuid = component.getUuid(); + String uuid = existingUuid == null ? uuidByComponentId.get(component.getId()) : existingUuid; + if (uuid == null) { + String newUuid = Uuids.create(); + uuidByComponentId.put(component.getId(), newUuid); + return newUuid; + } + return uuid; + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigration.java deleted file mode 100644 index 0f8c7f5ab60..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigration.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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. - */ -package org.sonar.server.db.migrations.v50; - -import com.google.common.collect.Lists; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.utils.System2; -import org.sonar.core.persistence.Database; -import org.sonar.server.db.migrations.BaseDataChange; -import org.sonar.server.db.migrations.MassUpdate; -import org.sonar.server.db.migrations.Select; -import org.sonar.server.db.migrations.SqlStatement; - -import java.sql.SQLException; -import java.util.Date; -import java.util.List; - -// TODO could be refactored to benefit from existing code of ReplaceIssueFiltersProjectKeyByUuid -// -> make any change of issue_filters easier -public class RemoveSortFieldFromIssueFiltersMigration extends BaseDataChange { - - private static final char FIELD_SEPARATOR = '|'; - private static final String SORT_KEY = "sort="; - private static final String ASC_KEY = "asc="; - - private final System2 system; - - public RemoveSortFieldFromIssueFiltersMigration(Database db, System2 system) { - super(db); - this.system = system; - } - - @Override - public void execute(Context context) throws SQLException { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("select id,data from issue_filters where data like '%" + SORT_KEY + "%' or data like '%" + ASC_KEY +"%'"); - massUpdate.update("update issue_filters set data=?, updated_at=? where id=?"); - massUpdate.rowPluralName("issue filters"); - massUpdate.execute(new FilterHandler(new Date(system.now()))); - } - - private static class FilterHandler implements MassUpdate.Handler { - private final Date now; - - private FilterHandler(Date now) { - this.now = now; - } - - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - String data = row.getNullableString(2); - String[] fields = StringUtils.split(data, FIELD_SEPARATOR); - - boolean found = false; - List fieldsToKeep = Lists.newArrayList(); - for (String field : fields) { - if (field.startsWith(SORT_KEY) || field.startsWith(ASC_KEY)) { - found = true; - } else { - fieldsToKeep.add(field); - } - } - if (found) { - // data without 'sort' field - update.setString(1, StringUtils.join(fieldsToKeep, FIELD_SEPARATOR)); - update.setDate(2, now); - update.setLong(3, row.getNullableLong(1)); - } - return found; - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigrationStep.java new file mode 100644 index 00000000000..874d1cca2e8 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigrationStep.java @@ -0,0 +1,90 @@ +/* + * 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. + */ +package org.sonar.server.db.migrations.v50; + +import java.sql.SQLException; +import java.util.Date; +import java.util.List; + +import org.apache.commons.lang.StringUtils; +import org.sonar.api.utils.System2; +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; + +import com.google.common.collect.Lists; + +// TODO could be refactored to benefit from existing code of ReplaceIssueFiltersProjectKeyByUuid +// -> make any change of issue_filters easier +public class RemoveSortFieldFromIssueFiltersMigrationStep extends BaseDataChange { + + private static final char FIELD_SEPARATOR = '|'; + private static final String SORT_KEY = "sort="; + private static final String ASC_KEY = "asc="; + + private final System2 system; + + public RemoveSortFieldFromIssueFiltersMigrationStep(Database db, System2 system) { + super(db); + this.system = system; + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("select id,data from issue_filters where data like '%" + SORT_KEY + "%' or data like '%" + ASC_KEY + "%'"); + massUpdate.update("update issue_filters set data=?, updated_at=? where id=?"); + massUpdate.rowPluralName("issue filters"); + massUpdate.execute(new FilterHandler(new Date(system.now()))); + } + + private static class FilterHandler implements MassUpdate.Handler { + private final Date now; + + private FilterHandler(Date now) { + this.now = now; + } + + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + String data = row.getNullableString(2); + String[] fields = StringUtils.split(data, FIELD_SEPARATOR); + + boolean found = false; + List fieldsToKeep = Lists.newArrayList(); + for (String field : fields) { + if (field.startsWith(SORT_KEY) || field.startsWith(ASC_KEY)) { + found = true; + } else { + fieldsToKeep.add(field); + } + } + if (found) { + // data without 'sort' field + update.setString(1, StringUtils.join(fieldsToKeep, FIELD_SEPARATOR)); + update.setDate(2, now); + update.setLong(3, row.getNullableLong(1)); + } + return found; + } + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuid.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuid.java index 2632f3b27c7..0beb52287df 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuid.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuid.java @@ -20,19 +20,23 @@ package org.sonar.server.db.migrations.v50; -import org.apache.commons.dbutils.DbUtils; -import org.sonar.api.utils.System2; -import org.sonar.core.persistence.Database; -import org.sonar.server.db.migrations.*; - -import javax.annotation.Nullable; - import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Date; +import javax.annotation.Nullable; + +import org.apache.commons.dbutils.DbUtils; +import org.sonar.api.utils.System2; +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; +import org.sonar.server.db.migrations.SqlUtil; + /** * Used in the Active Record Migration 710 * @@ -84,7 +88,7 @@ public class ReplaceIssueFiltersProjectKeyByUuid extends BaseDataChange { private String convertData(PreparedStatement pstmt, String data) throws SQLException { StringBuilder newFields = new StringBuilder(); String[] fields = data.split("\\|"); - for (int i=0; i> profiles = db.select("SELECT kee, name, language, parent_kee FROM rules_profiles ORDER BY id ASC"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/IssueActionPlanKeyMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/IssueActionPlanKeyMigrationTest.java index 5ad6c22c533..67331c22225 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/IssueActionPlanKeyMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/IssueActionPlanKeyMigrationTest.java @@ -41,13 +41,13 @@ public class IssueActionPlanKeyMigrationTest { @Mock System2 system2; - IssueActionPlanKeyMigration migration; + IssueActionPlanKeyMigrationStep migration; @Before public void setUp() throws Exception { when(system2.now()).thenReturn(DateUtils.parseDate("2014-04-28").getTime()); - migration = new IssueActionPlanKeyMigration(db.database(), system2); + migration = new IssueActionPlanKeyMigrationStep(db.database(), system2); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/MeasureDataMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/MeasureDataMigrationTest.java index 495746e994b..33f7683fbbb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/MeasureDataMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/MeasureDataMigrationTest.java @@ -33,11 +33,11 @@ public class MeasureDataMigrationTest { @ClassRule public static DbTester db = new DbTester().schema(MeasureDataMigrationTest.class, "schema.sql"); - MeasureDataMigration migration; + MeasureDataMigrationStep migration; @Before public void setUp() throws Exception { - migration = new MeasureDataMigration(db.database()); + migration = new MeasureDataMigrationStep(db.database()); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/AddMissingRuleParameterDefaultValuesMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/AddMissingRuleParameterDefaultValuesMigrationTest.java index d48dc7ccdfd..797b71f360d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/AddMissingRuleParameterDefaultValuesMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/AddMissingRuleParameterDefaultValuesMigrationTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -35,7 +35,7 @@ public class AddMissingRuleParameterDefaultValuesMigrationTest { @ClassRule public static DbTester db = new DbTester().schema(AddMissingRuleParameterDefaultValuesMigrationTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; System2 system = mock(System2.class); @Before @@ -43,7 +43,7 @@ public class AddMissingRuleParameterDefaultValuesMigrationTest { db.executeUpdateSql("truncate table rules_parameters"); db.executeUpdateSql("truncate table active_rules"); db.executeUpdateSql("truncate table active_rule_parameters"); - migration = new AddMissingRuleParameterDefaultValuesMigration(db.database(), system); + migration = new AddMissingRuleParameterDefaultValuesMigrationStep(db.database(), system); when(system.now()).thenReturn(DateUtils.parseDate("2014-04-28").getTime()); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigrationTest.java index 6b5b85be6d1..ef1efb8ebff 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigrationTest.java @@ -25,7 +25,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.sonar.core.persistence.DbTester; import org.sonar.server.db.DbClient; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import java.sql.Connection; import java.sql.ResultSet; @@ -38,12 +38,12 @@ public class DeleteMeasuresOnDeletedProfilesMigrationTest { @ClassRule public static DbTester db = new DbTester().schema(DeleteMeasuresOnDeletedProfilesMigrationTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; @Before public void setUp() throws Exception { DbClient dbClient = new DbClient(db.database(), db.myBatis()); - migration = new DeleteMeasuresOnDeletedProfilesMigration(dbClient); + migration = new DeleteMeasuresOnDeletedProfilesMigrationStep(dbClient); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest.java index decad8753bb..c55f58310c0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest.java @@ -26,7 +26,7 @@ import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; import org.sonar.server.db.DbClient; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -36,7 +36,7 @@ public class AddMissingCustomRuleParametersMigrationTest { @ClassRule public static DbTester db = new DbTester().schema(AddMissingCustomRuleParametersMigrationTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; System2 system = mock(System2.class); @Before @@ -44,7 +44,7 @@ public class AddMissingCustomRuleParametersMigrationTest { db.executeUpdateSql("truncate table rules"); db.executeUpdateSql("truncate table rules_parameters"); DbClient dbClient = new DbClient(db.database(), db.myBatis()); - migration = new AddMissingCustomRuleParametersMigration(dbClient, system); + migration = new AddMissingCustomRuleParametersMigrationStep(dbClient, system); when(system.now()).thenReturn(DateUtils.parseDate("2014-10-09").getTime()); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java index 1560bce72e4..510281bde6c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java @@ -22,7 +22,7 @@ package org.sonar.server.db.migrations.v451; import org.junit.ClassRule; import org.junit.Test; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.assertj.core.api.Assertions.assertThat; @@ -31,7 +31,7 @@ public class DeleteUnescapedActivitiesTest { @ClassRule public static DbTester db = new DbTester().schema(DeleteUnescapedActivitiesTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; @Test public void execute() throws Exception { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest.java index 17b2e0ae512..9668a68524e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest.java @@ -24,7 +24,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -41,7 +41,7 @@ public class FeedIssueLongDatesTest { System2 system = mock(System2.class); when(system.now()).thenReturn(1500000000000L); - DatabaseMigration migration = new FeedIssueLongDates(db.database(), system); + MigrationStep migration = new FeedIssueLongDates(db.database(), system); migration.execute(); int count = db.countSql("select count(*) from issues where created_at_ms is not null and updated_at_ms is not null"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/InsertProjectsAuthorizationUpdatedAtMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/InsertProjectsAuthorizationUpdatedAtMigrationTest.java index b7ed42cc268..f10e6e93793 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/InsertProjectsAuthorizationUpdatedAtMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/InsertProjectsAuthorizationUpdatedAtMigrationTest.java @@ -25,7 +25,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -35,13 +35,13 @@ public class InsertProjectsAuthorizationUpdatedAtMigrationTest { @ClassRule public static DbTester db = new DbTester().schema(InsertProjectsAuthorizationUpdatedAtMigrationTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; System2 system = mock(System2.class); @Before public void setUp() throws Exception { db.executeUpdateSql("truncate table projects"); - migration = new InsertProjectsAuthorizationUpdatedAtMigration(db.database(), system); + migration = new InsertProjectsAuthorizationUpdatedAtMigrationStep(db.database(), system); when(system.now()).thenReturn(123456789L); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest.java index 20aec985042..86ee10b0ed5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest.java @@ -30,7 +30,7 @@ import org.sonar.core.persistence.DbTester; import org.sonar.core.persistence.migration.v50.Component; import org.sonar.core.persistence.migration.v50.Migration50Mapper; import org.sonar.server.db.DbClient; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.assertj.core.api.Assertions.assertThat; @@ -45,7 +45,7 @@ public class PopulateProjectsUuidColumnsMigrationTest { Migration50Mapper mapper; - DatabaseMigration migration; + MigrationStep migration; @Before public void setUp() throws Exception { @@ -54,7 +54,7 @@ public class PopulateProjectsUuidColumnsMigrationTest { dbClient = new DbClient(db.database(), db.myBatis()); session = dbClient.openSession(false); mapper = session.getMapper(Migration50Mapper.class); - migration = new PopulateProjectsUuidColumnsMigration(dbClient); + migration = new PopulateProjectsUuidColumnsMigrationStep(dbClient); } @After diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigrationTest.java index f00d33d30a0..8c7cf3fac79 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigrationTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -35,13 +35,13 @@ public class RemoveSortFieldFromIssueFiltersMigrationTest { @ClassRule public static DbTester db = new DbTester().schema(RemoveSortFieldFromIssueFiltersMigrationTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; System2 system = mock(System2.class); @Before public void setUp() throws Exception { db.executeUpdateSql("truncate table issue_filters"); - migration = new RemoveSortFieldFromIssueFiltersMigration(db.database(), system); + migration = new RemoveSortFieldFromIssueFiltersMigrationStep(db.database(), system); when(system.now()).thenReturn(DateUtils.parseDate("2014-10-29").getTime()); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest.java index b5b3ce9abbf..5f48b08215f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -35,7 +35,7 @@ public class ReplaceIssueFiltersProjectKeyByUuidTest { @ClassRule public static DbTester db = new DbTester().schema(ReplaceIssueFiltersProjectKeyByUuidTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; System2 system = mock(System2.class); @Before diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddIssuesColumnsTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddIssuesColumnsTest.java index 6559ca4eb03..e882b4a6fcc 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddIssuesColumnsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddIssuesColumnsTest.java @@ -23,7 +23,7 @@ import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import java.sql.Types; @@ -32,7 +32,7 @@ public class AddIssuesColumnsTest { @ClassRule public static DbTester db = new DbTester().schema(AddIssuesColumnsTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; @Before public void setUp() throws Exception { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest.java index 4bc2d86983c..34fbbef067a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest.java @@ -26,7 +26,7 @@ import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static junit.framework.TestCase.fail; import static org.assertj.core.api.Assertions.assertThat; @@ -38,7 +38,7 @@ public class AddNewCharacteristicsTest { @ClassRule public static DbTester db = new DbTester().schema(AddNewCharacteristicsTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; System2 system = mock(System2.class); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/CopyScmAccountsFromAuthorsToUsersTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/CopyScmAccountsFromAuthorsToUsersTest.java index 603f1cad8ef..9b690506ed1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/CopyScmAccountsFromAuthorsToUsersTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/CopyScmAccountsFromAuthorsToUsersTest.java @@ -26,7 +26,7 @@ import org.junit.Test; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; import org.sonar.core.user.UserDto; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import java.util.Map; @@ -39,7 +39,7 @@ public class CopyScmAccountsFromAuthorsToUsersTest { @ClassRule public static DbTester db = new DbTester().schema(CopyScmAccountsFromAuthorsToUsersTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; System2 system = mock(System2.class); @Before diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest.java index 2086736a9b8..007c7b68ac9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest.java @@ -24,7 +24,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -40,7 +40,7 @@ public class FeedAnalysisReportsLongDatesTest { System2 system = mock(System2.class); when(system.now()).thenReturn(1500000000000L); - DatabaseMigration migration = new FeedAnalysisReportsLongDates(db.database(), system); + MigrationStep migration = new FeedAnalysisReportsLongDates(db.database(), system); migration.execute(); int count = db.countSql("select count(*) from analysis_reports where created_at_ms is not null and updated_at_ms is not null"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest.java index 4076ba2e382..c15cdfe64aa 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest.java @@ -25,7 +25,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -43,7 +43,7 @@ public class FeedEventsLongDatesTest { @Test public void execute() throws Exception { - DatabaseMigration migration = newMigration(System2.INSTANCE); + MigrationStep migration = newMigration(System2.INSTANCE); migration.execute(); @@ -59,7 +59,7 @@ public class FeedEventsLongDatesTest { System2 system = mock(System2.class); when(system.now()).thenReturn(1234L); - DatabaseMigration migration = newMigration(system); + MigrationStep migration = newMigration(system); migration.execute(); @@ -71,7 +71,7 @@ public class FeedEventsLongDatesTest { @Test public void take_date_if_in_the_past() throws Exception { - DatabaseMigration migration = newMigration(System2.INSTANCE); + MigrationStep migration = newMigration(System2.INSTANCE); migration.execute(); @@ -82,7 +82,7 @@ public class FeedEventsLongDatesTest { assertThat(count).isEqualTo(1); } - private DatabaseMigration newMigration(System2 system) { + private MigrationStep newMigration(System2 system) { return new FeedEventsLongDates(db.database(), system); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedFileSourcesBinaryDataTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedFileSourcesBinaryDataTest.java index c9e97998a37..089507fc597 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedFileSourcesBinaryDataTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedFileSourcesBinaryDataTest.java @@ -26,7 +26,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.core.persistence.DbTester; import org.sonar.core.source.db.FileSourceDto; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import org.sonar.server.source.db.FileSourceDb; import java.io.InputStream; @@ -49,7 +49,7 @@ public class FeedFileSourcesBinaryDataTest { public void convert_csv_to_protobuf() throws Exception { db.prepareDbUnit(getClass(), "data.xml"); - DatabaseMigration migration = new FeedFileSourcesBinaryData(db.database()); + MigrationStep migration = new FeedFileSourcesBinaryData(db.database()); migration.execute(); int count = db.countSql("select count(*) from file_sources where binary_data is not null"); @@ -73,7 +73,7 @@ public class FeedFileSourcesBinaryDataTest { public void fail_to_parse_csv() throws Exception { db.prepareDbUnit(getClass(), "bad_data.xml"); - DatabaseMigration migration = new FeedFileSourcesBinaryData(db.database()); + MigrationStep migration = new FeedFileSourcesBinaryData(db.database()); thrown.expect(IllegalStateException.class); thrown.expectMessage("Error during processing of row: [id=1,data="); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest.java index ecc00bb81ba..ea5a6ada331 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest.java @@ -24,7 +24,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -40,7 +40,7 @@ public class FeedIssueChangesLongDatesTest { System2 system = mock(System2.class); when(system.now()).thenReturn(1500000000000L); - DatabaseMigration migration = new FeedIssueChangesLongDates(db.database(), system); + MigrationStep migration = new FeedIssueChangesLongDates(db.database(), system); migration.execute(); int count = db.countSql("select count(*) from issue_changes where created_at_ms is not null and updated_at_ms is not null"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssuesLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssuesLongDatesTest.java index e0d3c6564e5..1044ad73d45 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssuesLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssuesLongDatesTest.java @@ -24,7 +24,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -39,7 +39,7 @@ public class FeedIssuesLongDatesTest { public void execute() throws Exception { db.prepareDbUnit(getClass(), "before.xml"); - DatabaseMigration migration = new FeedIssuesLongDates(db.database(), System2.INSTANCE); + MigrationStep migration = new FeedIssuesLongDates(db.database(), System2.INSTANCE); migration.execute(); int count = db @@ -56,7 +56,7 @@ public class FeedIssuesLongDatesTest { System2 system2 = mock(System2.class); when(system2.now()).thenReturn(0L); - DatabaseMigration migration = new FeedIssuesLongDates(db.database(), mock(System2.class)); + MigrationStep migration = new FeedIssuesLongDates(db.database(), mock(System2.class)); migration.execute(); int count = db @@ -70,7 +70,7 @@ public class FeedIssuesLongDatesTest { db.prepareDbUnit(getClass(), "before.xml"); long snapshotTime = parseDate("2014-09-25").getTime(); - DatabaseMigration migration = new FeedIssuesLongDates(db.database(), System2.INSTANCE); + MigrationStep migration = new FeedIssuesLongDates(db.database(), System2.INSTANCE); migration.execute(); int count = db diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDatesTest.java index d91efe79024..1333710b31c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDatesTest.java @@ -25,7 +25,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -43,7 +43,7 @@ public class FeedManualMeasuresLongDatesTest { @Test public void execute() throws Exception { - DatabaseMigration migration = newMigration(System2.INSTANCE); + MigrationStep migration = newMigration(System2.INSTANCE); migration.execute(); @@ -59,7 +59,7 @@ public class FeedManualMeasuresLongDatesTest { System2 system = mock(System2.class); when(system.now()).thenReturn(1234L); - DatabaseMigration migration = newMigration(system); + MigrationStep migration = newMigration(system); migration.execute(); @@ -71,7 +71,7 @@ public class FeedManualMeasuresLongDatesTest { @Test public void take_manual_measure_date_if_in_the_past() throws Exception { - DatabaseMigration migration = newMigration(System2.INSTANCE); + MigrationStep migration = newMigration(System2.INSTANCE); migration.execute(); @@ -82,7 +82,7 @@ public class FeedManualMeasuresLongDatesTest { assertThat(count).isEqualTo(1); } - private DatabaseMigration newMigration(System2 system) { + private MigrationStep newMigration(System2 system) { return new FeedManualMeasuresLongDates(db.database(), system); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest.java index 21f902627b1..010cca9be66 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest.java @@ -25,7 +25,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -43,7 +43,7 @@ public class FeedSemaphoresLongDatesTest { @Test public void execute() throws Exception { - DatabaseMigration migration = newMigration(System2.INSTANCE); + MigrationStep migration = newMigration(System2.INSTANCE); migration.execute(); @@ -60,7 +60,7 @@ public class FeedSemaphoresLongDatesTest { System2 system = mock(System2.class); when(system.now()).thenReturn(1234L); - DatabaseMigration migration = newMigration(system); + MigrationStep migration = newMigration(system); migration.execute(); @@ -72,7 +72,7 @@ public class FeedSemaphoresLongDatesTest { @Test public void take_snapshot_date_if_in_the_past() throws Exception { - DatabaseMigration migration = newMigration(System2.INSTANCE); + MigrationStep migration = newMigration(System2.INSTANCE); migration.execute(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest.java index 24f2e73500f..16e45e770e5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest.java @@ -24,7 +24,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -39,7 +39,7 @@ public class FeedSnapshotsLongDatesTest { public void execute() throws Exception { db.prepareDbUnit(getClass(), "before.xml"); - DatabaseMigration migration = new FeedSnapshotsLongDates(db.database(), System2.INSTANCE); + MigrationStep migration = new FeedSnapshotsLongDates(db.database(), System2.INSTANCE); migration.execute(); int count = db @@ -59,7 +59,7 @@ public class FeedSnapshotsLongDatesTest { System2 system2 = mock(System2.class); when(system2.now()).thenReturn(0L); - DatabaseMigration migration = new FeedSnapshotsLongDates(db.database(), mock(System2.class)); + MigrationStep migration = new FeedSnapshotsLongDates(db.database(), mock(System2.class)); migration.execute(); int count = db @@ -73,7 +73,7 @@ public class FeedSnapshotsLongDatesTest { db.prepareDbUnit(getClass(), "before.xml"); long snapshotTime = parseDate("2014-09-25").getTime(); - DatabaseMigration migration = new FeedSnapshotsLongDates(db.database(), System2.INSTANCE); + MigrationStep migration = new FeedSnapshotsLongDates(db.database(), System2.INSTANCE); migration.execute(); int count = db diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest.java index 5a9ca798aa8..e31d843500a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest.java @@ -24,7 +24,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -41,7 +41,7 @@ public class FeedUsersLongDatesTest { System2 system = mock(System2.class); when(system.now()).thenReturn(1500000000000L); - DatabaseMigration migration = new FeedUsersLongDates(db.database(), system); + MigrationStep migration = new FeedUsersLongDates(db.database(), system); migration.execute(); int count = db.countSql("select count(*) from users where created_at_ms is not null and updated_at_ms is not null"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RemovePermissionsOnModulesMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RemovePermissionsOnModulesMigrationTest.java index 9d16460e7d3..0dff23a0fb5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RemovePermissionsOnModulesMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RemovePermissionsOnModulesMigrationTest.java @@ -23,18 +23,18 @@ import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; public class RemovePermissionsOnModulesMigrationTest { @ClassRule public static DbTester db = new DbTester().schema(RemovePermissionsOnModulesMigrationTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; @Before public void setUp() throws Exception { - migration = new RemovePermissionsOnModulesMigration(db.database()); + migration = new RemovePermissionsOnModulesMigrationStep(db.database()); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RenameComponentRelatedParamsInIssueFiltersMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RenameComponentRelatedParamsInIssueFiltersMigrationTest.java index bd872931877..86906e6ab5e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RenameComponentRelatedParamsInIssueFiltersMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RenameComponentRelatedParamsInIssueFiltersMigrationTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -35,7 +35,7 @@ public class RenameComponentRelatedParamsInIssueFiltersMigrationTest { @ClassRule public static DbTester db = new DbTester().schema(RenameComponentRelatedParamsInIssueFiltersMigrationTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; System2 system = mock(System2.class); @Before diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/UpdateProjectsModuleUuidPathTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/UpdateProjectsModuleUuidPathTest.java index 895c044a147..e1d680d8464 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/UpdateProjectsModuleUuidPathTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/UpdateProjectsModuleUuidPathTest.java @@ -25,14 +25,14 @@ import org.junit.ClassRule; import org.junit.Test; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; public class UpdateProjectsModuleUuidPathTest { @ClassRule public static DbTester db = new DbTester().schema(UpdateProjectsModuleUuidPathTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; System2 system; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest.java index 2e13dbbce8c..26412c877fc 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest.java @@ -24,14 +24,14 @@ import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; public class FeedEventsComponentUuidTest { @ClassRule public static DbTester db = new DbTester().schema(FeedEventsComponentUuidTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; @Before public void setUp() throws Exception { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest.java index 256660c7ebf..76c888b19b3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest.java @@ -24,14 +24,14 @@ import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; public class FeedProjectLinksComponentUuidTest { @ClassRule public static DbTester db = new DbTester().schema(FeedProjectLinksComponentUuidTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; @Before public void setUp() throws Exception { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest.java index a571bd04123..fdf30cacfe2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest.java @@ -24,14 +24,14 @@ import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MigrationStep; public class MoveProjectProfileAssociationTest { @ClassRule public static DbTester db = new DbTester().schema(MoveProjectProfileAssociationTest.class, "schema.sql"); - DatabaseMigration migration; + MigrationStep migration; @Before public void setUp() throws Exception { diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/401_migrate_violations_to_issues.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/401_migrate_violations_to_issues.rb index cd749866220..065c102f5ef 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/401_migrate_violations_to_issues.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/401_migrate_violations_to_issues.rb @@ -32,7 +32,7 @@ class MigrateViolationsToIssues < ActiveRecord::Migration # Required for MSSQL to unlock the table RULE_FAILURES ActiveRecord::Base.connection.commit_db_transaction - execute_java_migration('org.sonar.server.db.migrations.v36.ViolationMigration') + execute_java_migration('org.sonar.server.db.migrations.v36.ViolationMigrationStep') # Currently not possible in Java because of Oracle (triggers and sequences must be dropped) drop_table('rule_failures') diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/490_migrate_package_keys.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/490_migrate_package_keys.rb index 52a1f86db9c..d17ed8c28c4 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/490_migrate_package_keys.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/490_migrate_package_keys.rb @@ -25,7 +25,7 @@ class MigratePackageKeys < ActiveRecord::Migration def self.up - execute_java_migration('org.sonar.server.db.migrations.v42.PackageKeysMigration') + execute_java_migration('org.sonar.server.db.migrations.v42.PackageKeysMigrationStep') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/497_update_issue_message_by_rule_name_when_no_message.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/497_update_issue_message_by_rule_name_when_no_message.rb index dd16ce162dc..3eb73f963f4 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/497_update_issue_message_by_rule_name_when_no_message.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/497_update_issue_message_by_rule_name_when_no_message.rb @@ -25,6 +25,6 @@ class UpdateIssueMessageByRuleNameWhenNoMessage < ActiveRecord::Migration def self.up - execute_java_migration('org.sonar.server.db.migrations.v42.CompleteIssueMessageMigration') + execute_java_migration('org.sonar.server.db.migrations.v42.CompleteIssueMessageMigrationStep') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/513_convert_issue_debt_to_minutes.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/513_convert_issue_debt_to_minutes.rb index c16795f2467..c02eaf1a2b5 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/513_convert_issue_debt_to_minutes.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/513_convert_issue_debt_to_minutes.rb @@ -25,6 +25,6 @@ class ConvertIssueDebtToMinutes < ActiveRecord::Migration def self.up - execute_java_migration('org.sonar.server.db.migrations.v43.ConvertIssueDebtToMinutesMigration') + execute_java_migration('org.sonar.server.db.migrations.v43.ConvertIssueDebtToMinutesMigrationStep') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/514_update_issue_changelog_debt_to_minutes.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/514_update_issue_changelog_debt_to_minutes.rb index 4e41841f68c..5b755a77e44 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/514_update_issue_changelog_debt_to_minutes.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/514_update_issue_changelog_debt_to_minutes.rb @@ -25,6 +25,6 @@ class UpdateIssueChangelogDebtToMinutes < ActiveRecord::Migration def self.up - execute_java_migration('org.sonar.server.db.migrations.v43.IssueChangelogMigration') + execute_java_migration('org.sonar.server.db.migrations.v43.IssueChangelogMigrationStep') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/515_update_measures_debt_to_minutes.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/515_update_measures_debt_to_minutes.rb index 80e25fc954f..fe5ed6bbec6 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/515_update_measures_debt_to_minutes.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/515_update_measures_debt_to_minutes.rb @@ -25,6 +25,6 @@ class UpdateMeasuresDebtToMinutes < ActiveRecord::Migration def self.up - execute_java_migration('org.sonar.server.db.migrations.v43.TechnicalDebtMeasuresMigration') + execute_java_migration('org.sonar.server.db.migrations.v43.TechnicalDebtMeasuresMigrationStep') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/516_update_development_cost_to_minutes.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/516_update_development_cost_to_minutes.rb index d3babd54cdb..39eca632abb 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/516_update_development_cost_to_minutes.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/516_update_development_cost_to_minutes.rb @@ -25,6 +25,6 @@ class UpdateDevelopmentCostToMinutes < ActiveRecord::Migration def self.up - execute_java_migration('org.sonar.server.db.migrations.v43.DevelopmentCostMeasuresMigration') + execute_java_migration('org.sonar.server.db.migrations.v43.DevelopmentCostMeasuresMigrationStep') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/521_update_requirement_measures.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/521_update_requirement_measures.rb index 9d287e17578..436e864ae63 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/521_update_requirement_measures.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/521_update_requirement_measures.rb @@ -25,6 +25,6 @@ class UpdateRequirementMeasures < ActiveRecord::Migration def self.up - execute_java_migration('org.sonar.server.db.migrations.v43.RequirementMeasuresMigration') + execute_java_migration('org.sonar.server.db.migrations.v43.RequirementMeasuresMigrationStep') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/525_update_not_resolved_issues_on_removed_components.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/525_update_not_resolved_issues_on_removed_components.rb index 410a0bc8d20..778d82658a0 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/525_update_not_resolved_issues_on_removed_components.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/525_update_not_resolved_issues_on_removed_components.rb @@ -25,7 +25,7 @@ class UpdateNotResolvedIssuesOnRemovedComponents < ActiveRecord::Migration def self.up - execute_java_migration('org.sonar.server.db.migrations.v43.NotResolvedIssuesOnRemovedComponentsMigration') + execute_java_migration('org.sonar.server.db.migrations.v43.NotResolvedIssuesOnRemovedComponentsMigrationStep') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/530_merge_measure_data_into_project_measures.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/530_merge_measure_data_into_project_measures.rb index 80bd94722ca..401a74ffb42 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/530_merge_measure_data_into_project_measures.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/530_merge_measure_data_into_project_measures.rb @@ -34,7 +34,7 @@ class MergeMeasureDataIntoProjectMeasures < ActiveRecord::Migration ActiveRecord::Base.connection.commit_db_transaction end ProjectMeasure.reset_column_information - execute_java_migration('org.sonar.server.db.migrations.v44.MeasureDataMigration') + execute_java_migration('org.sonar.server.db.migrations.v44.MeasureDataMigrationStep') drop_table(:measure_data) end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/531_update_issues_action_plan_key_on_removed_action_plan.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/531_update_issues_action_plan_key_on_removed_action_plan.rb index 0add6a21944..479e36534ee 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/531_update_issues_action_plan_key_on_removed_action_plan.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/531_update_issues_action_plan_key_on_removed_action_plan.rb @@ -25,7 +25,7 @@ class UpdateIssuesActionPlanKeyOnRemovedActionPlan < ActiveRecord::Migration def self.up - execute_java_migration('org.sonar.server.db.migrations.v44.IssueActionPlanKeyMigration') + execute_java_migration('org.sonar.server.db.migrations.v44.IssueActionPlanKeyMigrationStep') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/549_feed_qprofile_keys.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/549_feed_qprofile_keys.rb index 7090686004f..d2b579ccbd8 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/549_feed_qprofile_keys.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/549_feed_qprofile_keys.rb @@ -25,7 +25,7 @@ class FeedQprofileKeys < ActiveRecord::Migration def self.up - execute_java_migration('org.sonar.server.db.migrations.v44.FeedQProfileKeysMigration') + execute_java_migration('org.sonar.server.db.migrations.v44.FeedQProfileKeysMigrationStep') # set as non-null and unique change_column :rules_profiles, :kee, :string, :limit => 255, :null => false diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/550_convert_profile_measures.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/550_convert_profile_measures.rb index a6f357c405b..1543cc3fadf 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/550_convert_profile_measures.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/550_convert_profile_measures.rb @@ -28,7 +28,7 @@ class ConvertProfileMeasures < ActiveRecord::Migration end def self.up - execute_java_migration('org.sonar.server.db.migrations.v44.ConvertProfileMeasuresMigration') + execute_java_migration('org.sonar.server.db.migrations.v44.ConvertProfileMeasuresMigrationStep') Metric.reset_column_information metric = Metric.find_by_name('profile') diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/551_update_logs_to_activities.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/551_update_logs_to_activities.rb index 0244e573012..d11201aee8e 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/551_update_logs_to_activities.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/551_update_logs_to_activities.rb @@ -25,7 +25,7 @@ class UpdateLogsToActivities < ActiveRecord::Migration def self.up - execute_java_migration('org.sonar.server.db.migrations.v44.ChangeLogMigration') + execute_java_migration('org.sonar.server.db.migrations.v44.ChangeLogMigrationStep') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/553_feed_qprofile_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/553_feed_qprofile_dates.rb index 2fe4f2390f0..f8cc4868a22 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/553_feed_qprofile_dates.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/553_feed_qprofile_dates.rb @@ -24,7 +24,7 @@ class FeedQprofileDates < ActiveRecord::Migration def self.up - execute_java_migration 'org.sonar.server.db.migrations.v44.FeedQProfileDatesMigration' + execute_java_migration 'org.sonar.server.db.migrations.v44.FeedQProfileDatesMigrationStep' end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/583_add_missing_rule_parameter_default_values.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/583_add_missing_rule_parameter_default_values.rb index 241986a5180..e8c6f8d70dd 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/583_add_missing_rule_parameter_default_values.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/583_add_missing_rule_parameter_default_values.rb @@ -24,7 +24,7 @@ class AddMissingRuleParameterDefaultValues < ActiveRecord::Migration def self.up - execute_java_migration 'org.sonar.server.db.migrations.v45.AddMissingRuleParameterDefaultValuesMigration' + execute_java_migration 'org.sonar.server.db.migrations.v45.AddMissingRuleParameterDefaultValuesMigrationStep' end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/584_delete_measures_on_deleted_profiles.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/584_delete_measures_on_deleted_profiles.rb index f414494f2ba..8a075d5fba9 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/584_delete_measures_on_deleted_profiles.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/584_delete_measures_on_deleted_profiles.rb @@ -24,7 +24,7 @@ class DeleteMeasuresOnDeletedProfiles < ActiveRecord::Migration def self.up - execute_java_migration 'org.sonar.server.db.migrations.v45.DeleteMeasuresOnDeletedProfilesMigration' + execute_java_migration 'org.sonar.server.db.migrations.v45.DeleteMeasuresOnDeletedProfilesMigrationStep' end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/601_add_missing_custom_rule_parameters.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/601_add_missing_custom_rule_parameters.rb index 68fc21af055..eb41a4ff19d 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/601_add_missing_custom_rule_parameters.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/601_add_missing_custom_rule_parameters.rb @@ -25,6 +25,6 @@ class AddMissingCustomRuleParameters < ActiveRecord::Migration def self.up - execute_java_migration 'org.sonar.server.db.migrations.v451.AddMissingCustomRuleParametersMigration' + execute_java_migration 'org.sonar.server.db.migrations.v451.AddMissingCustomRuleParametersMigrationStep' end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/705_populate_projects_uuid_columns.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/705_populate_projects_uuid_columns.rb index a08d370720b..6cc1aba4d0b 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/705_populate_projects_uuid_columns.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/705_populate_projects_uuid_columns.rb @@ -25,7 +25,7 @@ class PopulateProjectsUuidColumns < ActiveRecord::Migration def self.up - execute_java_migration('org.sonar.server.db.migrations.v50.PopulateProjectsUuidColumnsMigration') + execute_java_migration('org.sonar.server.db.migrations.v50.PopulateProjectsUuidColumnsMigrationStep') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/716_insert_projects_authorization_updated_at.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/716_insert_projects_authorization_updated_at.rb index 365ae624d80..aec34e16e5f 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/716_insert_projects_authorization_updated_at.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/716_insert_projects_authorization_updated_at.rb @@ -25,7 +25,7 @@ class InsertProjectsAuthorizationUpdatedAt < ActiveRecord::Migration def self.up - execute_java_migration('org.sonar.server.db.migrations.v50.InsertProjectsAuthorizationUpdatedAtMigration') + execute_java_migration('org.sonar.server.db.migrations.v50.InsertProjectsAuthorizationUpdatedAtMigrationStep') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/721_remove_sort_field_from_issue_filters.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/721_remove_sort_field_from_issue_filters.rb index 262b9fd2c2f..1958f9ef8de 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/721_remove_sort_field_from_issue_filters.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/721_remove_sort_field_from_issue_filters.rb @@ -24,7 +24,7 @@ class RemoveSortFieldFromIssueFilters < ActiveRecord::Migration def self.up - execute_java_migration('org.sonar.server.db.migrations.v50.RemoveSortFieldFromIssueFiltersMigration') + execute_java_migration('org.sonar.server.db.migrations.v50.RemoveSortFieldFromIssueFiltersMigrationStep') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/795_remove_permissions_on_modules.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/795_remove_permissions_on_modules.rb index a38e1beec91..9dec88eeb5c 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/795_remove_permissions_on_modules.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/795_remove_permissions_on_modules.rb @@ -25,7 +25,7 @@ class RemovePermissionsOnModules < ActiveRecord::Migration def self.up - execute_java_migration 'org.sonar.server.db.migrations.v51.RemovePermissionsOnModulesMigration' + execute_java_migration 'org.sonar.server.db.migrations.v51.RemovePermissionsOnModulesMigrationStep' end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/README.txt b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/README.txt index 6545ade2665..796cd8b6f32 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/README.txt +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/README.txt @@ -9,7 +9,7 @@ HOW TO ADD A MIGRATION * If a table is added or removed, then edit sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java * Changes in bulk must be handled using Java migrations based on org.sonar.server.db.migrations.MassUpdate : + Create the class for the Java migration in package package org.sonar.server.db.migrations.vXYZ, where XYZ is the version of SQ without dots - + Add the class to org.sonar.server.db.migrations.DatabaseMigrations.CLASSES + + Add the class to org.sonar.server.db.migrations.MigrationSteps.CLASSES + Create a Ruby migration which calls execute_java_migration('org.sonar.server.db.migrations.vXYZ.MyMigration') + Simple, "one to one" migrations that only need to be split by 1000 can rely on class org.sonar.server.db.migrations.BaseDataChange