*/
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 {
*/
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;
*/
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<CHILD extends SqlStatement> implements SqlStatement<CHILD> {
protected PreparedStatement pstmt;
*/
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 {
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-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;
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-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<Class<? extends DatabaseMigration>> 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
- );
-}
*/
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.
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;
}
public void executeMigration(String className) {
- DatabaseMigration migration = getMigration(className);
+ MigrationStep migration = getMigration(className);
try {
migration.execute();
}
}
- 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;
}
*/
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;
*/
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 {
*/
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 {
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+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;
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+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<Class<? extends MigrationStep>> 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
+ );
+}
*/
package org.sonar.server.db.migrations;
-import javax.annotation.CheckForNull;
-
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
+import javax.annotation.CheckForNull;
+
public interface Select extends SqlStatement<Select> {
static class Row {
*/
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.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.dbutils.DbUtils;
+import org.sonar.core.persistence.Database;
+
class SelectImpl extends BaseSqlStatement<Select> implements Select {
private SelectImpl(PreparedStatement pstmt) {
*/
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 extends SqlStatement> {
CHILD setBoolean(int columnIndex, @Nullable Boolean value) throws SQLException;
*/
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() {
*/
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<Upsert> implements Upsert {
private long batchCount = 0L;
*/
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.
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));
}
*/
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;
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.
*/
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;
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<Object> {
*/
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;
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;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-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);
- }
- }
-
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+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);
+ }
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-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;
- }
- });
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+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;
+ }
+ });
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-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;
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+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;
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-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;
- }
- });
- }
-
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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;
+ }
+ });
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-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));
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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));
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-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();
- }
-
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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();
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-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;
- }
- });
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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;
+ }
+ });
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-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;
- }
- });
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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;
+ }
+ });
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-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<Long> 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;
- }
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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<Long> 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;
+ }
+ }
+}
}
}
- private void checkHoursInDay(){
+ private void checkHoursInDay() {
if (hoursInDay == null) {
throw new IllegalStateException("init() has not been called");
}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-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
- * <p/>
- * 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<ChangeLog> changes) {
-
- Iterator<ChangeLog> 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())));
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+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
+ * <p/>
+ * 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<ChangeLog> changes) {
+
+ Iterator<ChangeLog> 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())));
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-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();
- }
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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();
+ }
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-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();
- }
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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();
+ }
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-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;
- }
- });
-
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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;
+ }
+ });
+
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-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.
- * <p/>
- * 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;
- }
- });
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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.
+ * <p/>
+ * 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;
+ }
+ });
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-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;
- }
- });
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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;
+ }
+ });
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-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<RuleParam> ruleParameters = context.prepareSelect("select id,rule_id,name,default_value from rules_parameters where default_value is not null")
- .list(new Select.RowReader<RuleParam>() {
- @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<ActiveRule> 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<ActiveRule>() {
- @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;
- }
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+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<RuleParam> ruleParameters = context.prepareSelect("select id,rule_id,name,default_value from rules_parameters where default_value is not null")
+ .list(new Select.RowReader<RuleParam>() {
+ @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<ActiveRule> 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<ActiveRule>() {
+ @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;
+ }
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-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();
- }
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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();
+ }
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-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<RuleParameter> templateRuleParams = mapper.selectAllTemplateRuleParameters();
- Multimap<Integer, RuleParameter> templateRuleParamsByRuleId = ArrayListMultimap.create();
- for (RuleParameter templateRuleParam : templateRuleParams) {
- templateRuleParamsByRuleId.put(templateRuleParam.getRuleId(), templateRuleParam);
- }
-
- List<Rule> customRules = mapper.selectAllCustomRules();
- Multimap<Integer, Integer> customRuleIdsByTemplateRuleId = HashMultimap.create();
- for (Rule customRule : customRules) {
- customRuleIdsByTemplateRuleId.put(customRule.getTemplateId(), customRule.getId());
- }
-
- List<RuleParameter> customRuleParams = mapper.selectAllCustomRuleParameters();
- Multimap<Integer, RuleParameter> 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<Integer, Integer> customRuleIdsByTemplateRuleId,
- Multimap<Integer, RuleParameter> 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<RuleParameter> customRuleParams) {
- return Iterables.any(customRuleParams, new Predicate<RuleParameter>() {
- @Override
- public boolean apply(@Nullable RuleParameter input) {
- return input != null && input.getName().equals(parameter);
- }
- });
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+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<RuleParameter> templateRuleParams = mapper.selectAllTemplateRuleParameters();
+ Multimap<Integer, RuleParameter> templateRuleParamsByRuleId = ArrayListMultimap.create();
+ for (RuleParameter templateRuleParam : templateRuleParams) {
+ templateRuleParamsByRuleId.put(templateRuleParam.getRuleId(), templateRuleParam);
+ }
+
+ List<Rule> customRules = mapper.selectAllCustomRules();
+ Multimap<Integer, Integer> customRuleIdsByTemplateRuleId = HashMultimap.create();
+ for (Rule customRule : customRules) {
+ customRuleIdsByTemplateRuleId.put(customRule.getTemplateId(), customRule.getId());
+ }
+
+ List<RuleParameter> customRuleParams = mapper.selectAllCustomRuleParameters();
+ Multimap<Integer, RuleParameter> 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<Integer, Integer> customRuleIdsByTemplateRuleId,
+ Multimap<Integer, RuleParameter> 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<RuleParameter> customRuleParams) {
+ return Iterables.any(customRuleParams, new Predicate<RuleParameter>() {
+ @Override
+ public boolean apply(@Nullable RuleParameter input) {
+ return input != null && input.getName().equals(parameter);
+ }
+ });
+ }
+}
*/
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;
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
*
*/
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;
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
*
*/
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;
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;
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
*
*/
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;
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 {
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-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;
- }
- });
- }
-
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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;
+ }
+ });
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-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<Long, String> 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<Long, String> uuidByComponentId) {
- Map<Long, Component> componentsBySnapshotId = newHashMap();
-
- List<Component> components = readSession.getMapper(Migration50Mapper.class).selectComponentChildrenForProjects(project.getId());
- components.add(project);
- List<Component> 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<Long, String> 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<Long, Component> componentsBySnapshotId, Map<Long, String> 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<Long, String> 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;
- }
-
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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<Long, String> 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<Long, String> uuidByComponentId) {
+ Map<Long, Component> componentsBySnapshotId = newHashMap();
+
+ List<Component> components = readSession.getMapper(Migration50Mapper.class).selectComponentChildrenForProjects(project.getId());
+ components.add(project);
+ List<Component> 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<Long, String> 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<Long, Component> componentsBySnapshotId, Map<Long, String> 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<Long, String> 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;
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-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<String> 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;
- }
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+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<String> 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;
+ }
+ }
+}
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
*
private String convertData(PreparedStatement pstmt, String data) throws SQLException {
StringBuilder newFields = new StringBuilder();
String[] fields = data.split("\\|");
- for (int i=0; i<fields.length; i++) {
+ for (int i = 0; i < fields.length; i++) {
String field = fields[i];
if (field.contains("componentRoots")) {
String[] componentRootValues = field.split("=");
package org.sonar.server.db.migrations.v51;
+import java.sql.SQLException;
+
import org.sonar.core.persistence.Database;
import org.sonar.server.db.migrations.AddColumnsBuilder;
import org.sonar.server.db.migrations.DdlChange;
-import java.sql.SQLException;
-
/**
* Add the following columns to the issues table :
* - issue_creation_date_ms
*/
package org.sonar.server.db.migrations.v51;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
+import java.sql.SQLException;
+import java.util.Date;
+import java.util.List;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.utils.MessageException;
import org.sonar.server.db.migrations.BaseDataChange;
import org.sonar.server.db.migrations.Select;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.sql.SQLException;
-import java.util.Date;
-import java.util.List;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
/**
* See http://jira.codehaus.org/browse/SONAR-6187
package org.sonar.server.db.migrations.v51;
-import com.google.common.base.Joiner;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Multimap;
+import static com.google.common.collect.Lists.newArrayList;
+
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.annotation.CheckForNull;
+
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.UpsertImpl;
import org.sonar.server.util.ProgressLogger;
-import javax.annotation.CheckForNull;
-
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicLong;
-
-import static com.google.common.collect.Lists.newArrayList;
+import com.google.common.base.Joiner;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
public class CopyScmAccountsFromAuthorsToUsers extends BaseDataChange {
package org.sonar.server.db.migrations.v51;
-import com.google.common.annotations.VisibleForTesting;
+import java.sql.SQLException;
+
import org.sonar.core.persistence.Database;
import org.sonar.server.db.migrations.DdlChange;
import org.sonar.server.db.migrations.DropColumnsBuilder;
-import java.sql.SQLException;
+import com.google.common.annotations.VisibleForTesting;
/**
* Drop the following columns from the issues table :
package org.sonar.server.db.migrations.v51;
+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.Select;
import org.sonar.server.db.migrations.SqlStatement;
-import java.sql.SQLException;
-import java.util.Date;
-
public class FeedAnalysisReportsLongDates extends BaseDataChange {
private final System2 system;
package org.sonar.server.db.migrations.v51;
+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.Select;
import org.sonar.server.db.migrations.SqlStatement;
-import java.sql.SQLException;
-import java.util.Date;
-
public class FeedEventsLongDates extends BaseDataChange {
private final System2 system2;
*/
package org.sonar.server.db.migrations.v51;
-import com.google.common.base.Function;
-import com.google.common.base.Splitter;
-import com.google.common.collect.Iterables;
+import java.sql.SQLException;
+import java.util.Iterator;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.sonar.server.db.migrations.SqlStatement;
import org.sonar.server.source.db.FileSourceDb;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import java.sql.SQLException;
-import java.util.Iterator;
+import com.google.common.base.Function;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Iterables;
public class FeedFileSourcesBinaryData extends BaseDataChange {
package org.sonar.server.db.migrations.v51;
+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.Select;
import org.sonar.server.db.migrations.SqlStatement;
-import java.sql.SQLException;
-import java.util.Date;
-
public class FeedIssueChangesLongDates extends BaseDataChange {
private final System2 system;
package org.sonar.server.db.migrations.v51;
+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.Row;
import org.sonar.server.db.migrations.SqlStatement;
-import java.sql.SQLException;
-
public class FeedIssueComponentUuids extends BaseDataChange {
public FeedIssueComponentUuids(Database db) {
*/
package org.sonar.server.db.migrations.v51;
-import com.google.common.base.Joiner;
-import com.google.common.collect.Maps;
+import java.sql.SQLException;
+import java.util.Map;
+
import org.apache.commons.lang.StringUtils;
import org.sonar.api.utils.System2;
import org.sonar.core.persistence.Database;
import org.sonar.server.db.migrations.Select.RowHandler;
import org.sonar.server.db.migrations.SqlStatement;
-import java.sql.SQLException;
-import java.util.Map;
-
+import com.google.common.base.Joiner;
+import com.google.common.collect.Maps;
/**
* SONAR-5897
package org.sonar.server.db.migrations.v51;
+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.Select;
import org.sonar.server.db.migrations.SqlStatement;
-import java.sql.SQLException;
-import java.util.Date;
-
public class FeedIssuesLongDates extends BaseDataChange {
private final System2 system2;
package org.sonar.server.db.migrations.v51;
+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.Select;
import org.sonar.server.db.migrations.SqlStatement;
-import java.sql.SQLException;
-import java.util.Date;
-
public class FeedManualMeasuresLongDates extends BaseDataChange {
private final System2 system2;
package org.sonar.server.db.migrations.v51;
+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.Select;
import org.sonar.server.db.migrations.SqlStatement;
-import java.sql.SQLException;
-import java.util.Date;
-
public class FeedSemaphoresLongDates extends BaseDataChange {
private final System2 system2;
package org.sonar.server.db.migrations.v51;
+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.Select;
import org.sonar.server.db.migrations.SqlStatement;
-import java.sql.SQLException;
-import java.util.Date;
-
public class FeedSnapshotsLongDates extends BaseDataChange {
private final System2 system2;
*/
package org.sonar.server.db.migrations.v51;
+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.Select;
import org.sonar.server.db.migrations.SqlStatement;
-import java.sql.SQLException;
-import java.util.Date;
-
public class FeedUsersLongDates extends BaseDataChange {
private final System2 system;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.db.migrations.v51;
-
-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;
-
-/**
- * See http://jira.codehaus.org/browse/SONAR-5596
- *
- * It's no possible to set permission on a module or a sub-view, but the batch was setting default permission on it on their creation.
- * As now it's no more the case, we need to purge this useless data.
- *
- * @since 5.1
- */
-public class RemovePermissionsOnModulesMigration extends BaseDataChange {
-
- public RemovePermissionsOnModulesMigration(Database db) {
- super(db);
- }
-
- @Override
- public void execute(Context context) throws SQLException {
- removeUserRolePermissions(context, "user_roles", "user roles");
- removeUserRolePermissions(context, "group_roles", "group roles");
- }
-
- private void removeUserRolePermissions(Context context, String tableName, String pluralName) throws SQLException {
- MassUpdate massUpdate = context.prepareMassUpdate();
- massUpdate.select("SELECT r.id " +
- "FROM " + tableName + " r " +
- " INNER JOIN projects ON projects.id = r.resource_id " +
- "WHERE projects.module_uuid IS NOT NULL");
- massUpdate.update("DELETE FROM " + tableName + " WHERE id=?");
- massUpdate.rowPluralName(pluralName);
- massUpdate.execute(new MassUpdate.Handler() {
- @Override
- public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
- update.setLong(1, row.getLong(1));
- return true;
- }
- });
- }
-
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.db.migrations.v51;
+
+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;
+
+/**
+ * See http://jira.codehaus.org/browse/SONAR-5596
+ *
+ * It's no possible to set permission on a module or a sub-view, but the batch was setting default permission on it on their creation.
+ * As now it's no more the case, we need to purge this useless data.
+ *
+ * @since 5.1
+ */
+public class RemovePermissionsOnModulesMigrationStep extends BaseDataChange {
+
+ public RemovePermissionsOnModulesMigrationStep(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ removeUserRolePermissions(context, "user_roles", "user roles");
+ removeUserRolePermissions(context, "group_roles", "group roles");
+ }
+
+ private void removeUserRolePermissions(Context context, String tableName, String pluralName) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+ massUpdate.select("SELECT r.id " +
+ "FROM " + tableName + " r " +
+ " INNER JOIN projects ON projects.id = r.resource_id " +
+ "WHERE projects.module_uuid IS NOT NULL");
+ massUpdate.update("DELETE FROM " + tableName + " WHERE id=?");
+ massUpdate.rowPluralName(pluralName);
+ massUpdate.execute(new MassUpdate.Handler() {
+ @Override
+ public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+ update.setLong(1, row.getLong(1));
+ return true;
+ }
+ });
+ }
+
+}
*/
package org.sonar.server.db.migrations.v51;
-import com.google.common.collect.Lists;
+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.Select;
import org.sonar.server.db.migrations.SqlStatement;
-import java.sql.SQLException;
-import java.util.Date;
-import java.util.List;
+import com.google.common.collect.Lists;
public class RenameComponentRelatedParamsInIssueFilters extends BaseDataChange {
package org.sonar.server.db.migrations.v51;
+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;
import org.sonar.server.db.migrations.Select.Row;
import org.sonar.server.db.migrations.SqlStatement;
-import javax.annotation.Nullable;
-
-import java.sql.SQLException;
-
/**
* SONAR-6054
* SONAR-6119
package org.sonar.server.db.migrations.v52;
+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;
-
public class FeedEventsComponentUuid extends BaseDataChange {
public FeedEventsComponentUuid(Database db) {
package org.sonar.server.db.migrations.v52;
+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.Row;
import org.sonar.server.db.migrations.SqlStatement;
-import java.sql.SQLException;
-
public class FeedProjectLinksComponentUuid extends BaseDataChange {
public FeedProjectLinksComponentUuid(Database db) {
*/
package org.sonar.server.db.migrations.v52;
-import com.google.common.collect.HashBasedTable;
-import com.google.common.collect.Table;
+import java.sql.SQLException;
+
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.*;
+import org.sonar.server.db.migrations.BaseDataChange;
+import org.sonar.server.db.migrations.MassUpdate;
import org.sonar.server.db.migrations.MassUpdate.Handler;
+import org.sonar.server.db.migrations.Select;
import org.sonar.server.db.migrations.Select.Row;
import org.sonar.server.db.migrations.Select.RowReader;
+import org.sonar.server.db.migrations.SqlStatement;
+import org.sonar.server.db.migrations.Upsert;
-import java.sql.SQLException;
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Table;
/**
* SonarQube 5.2
String profileName = row.getString(3);
Long projectId = row.getNullableLong(4);
String projectUuid = row.getString(5);
-
+
if (profileKeysByLanguageThenName.contains(profileLanguage, profileName)) {
String profileKey = profileKeysByLanguageThenName.get(profileLanguage, profileName);
import org.sonar.server.db.DatabaseChecker;
import org.sonar.server.db.DbClient;
import org.sonar.server.db.EmbeddedDatabaseFactory;
-import org.sonar.server.db.migrations.DatabaseMigrations;
+import org.sonar.server.db.migrations.MigrationSteps;
import org.sonar.server.db.migrations.DatabaseMigrator;
import org.sonar.server.debt.*;
import org.sonar.server.design.FileDesignWidget;
FileSourceDao.class
));
components.addAll(CorePropertyDefinitions.all());
- components.addAll(DatabaseMigrations.CLASSES);
+ components.addAll(MigrationSteps.CLASSES);
components.addAll(DaoUtils.getDaoClasses());
return components;
}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.db.migrations;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DatabaseMigrationsTest {
-
- @Test
- public void check_number_of_migrations() throws Exception {
- assertThat(DatabaseMigrations.CLASSES).isNotEmpty();
- }
-}
public ExpectedException thrown = ExpectedException.none();
DbClient dbClient = mock(DbClient.class, Mockito.RETURNS_DEEP_STUBS);
- DatabaseMigration[] migrations = new DatabaseMigration[]{new FakeMigration()};
+ MigrationStep[] migrations = new MigrationStep[]{new FakeMigrationStep()};
ServerUpgradeStatus serverUpgradeStatus = mock(ServerUpgradeStatus.class);
DatabaseMigrator migrator;
@Test
public void execute_migration() throws Exception {
- assertThat(FakeMigration.executed).isFalse();
- migrator.executeMigration(FakeMigration.class.getName());
- assertThat(FakeMigration.executed).isTrue();
+ assertThat(FakeMigrationStep.executed).isFalse();
+ migrator.executeMigration(FakeMigrationStep.class.getName());
+ assertThat(FakeMigrationStep.executed).isTrue();
}
@Test
assertThat(databaseMigrator.createDatabase()).isTrue();
}
- public static class FakeMigration implements DatabaseMigration {
+ public static class FakeMigrationStep implements MigrationStep {
static boolean executed = false;
@Override
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.db.migrations;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MigrationStepsTest {
+
+ @Test
+ public void check_number_of_migrations() throws Exception {
+ assertThat(MigrationSteps.CLASSES).isNotEmpty();
+ }
+}
public void migrate_violations() throws Exception {
db.prepareDbUnit(getClass(), "migrate_violations.xml");
- new ViolationMigration(db.database(), new Settings()).execute();
+ new ViolationMigrationStep(db.database(), new Settings()).execute();
db.assertDbUnit(getClass(), "migrate_violations_result.xml", "issues", "issue_changes");
assertMigrationEnded();
public void no_violations_to_migrate() throws Exception {
db.prepareDbUnit(getClass(), "no_violations_to_migrate.xml");
- new ViolationMigration(db.database(), new Settings()).execute();
+ new ViolationMigrationStep(db.database(), new Settings()).execute();
db.assertDbUnit(getClass(), "no_violations_to_migrate_result.xml", "issues", "issue_changes");
assertMigrationEnded();
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 CompleteIssueMessageMigrationTest {
@ClassRule
public static DbTester db = new DbTester().schema(CompleteIssueMessageMigrationTest.class, "schema.sql");
- DatabaseMigration migration = new CompleteIssueMessageMigration(db.database());
+ MigrationStep migration = new CompleteIssueMessageMigrationStep(db.database());
@Test
public void execute() throws Exception {
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 PackageKeysMigrationTest {
@ClassRule
public static DbTester db = new DbTester().schema(PackageKeysMigrationTest.class, "schema.sql");
- DatabaseMigration migration = new PackageKeysMigration(db.database());
+ MigrationStep migration = new PackageKeysMigrationStep(db.database());
@Test
public void execute() throws Exception {
@Mock
PropertiesDao propertiesDao;
- ConvertIssueDebtToMinutesMigration migration;
+ ConvertIssueDebtToMinutesMigrationStep migration;
@Before
public void setUp() throws Exception {
when(system2.now()).thenReturn(DateUtils.parseDateTime("2014-02-19T19:10:03+0100").getTime());
when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue("8"));
- migration = new ConvertIssueDebtToMinutesMigration(db.database(), propertiesDao, system2);
+ migration = new ConvertIssueDebtToMinutesMigrationStep(db.database(), propertiesDao, system2);
}
@Test
@Mock
PropertiesDao propertiesDao;
- DevelopmentCostMeasuresMigration migration;
+ DevelopmentCostMeasuresMigrationStep migration;
@Before
public void setUp() throws Exception {
when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue("8"));
- migration = new DevelopmentCostMeasuresMigration(db.database(), propertiesDao);
+ migration = new DevelopmentCostMeasuresMigrationStep(db.database(), propertiesDao);
}
@Test
@Mock
PropertiesDao propertiesDao;
- IssueChangelogMigration migration;
+ IssueChangelogMigrationStep migration;
@Before
public void setUp() throws Exception {
WorkDurationConvertor convertor = new WorkDurationConvertor(propertiesDao);
convertor.init();
- migration = new IssueChangelogMigration(db.database(), system2, convertor);
+ migration = new IssueChangelogMigrationStep(db.database(), system2, convertor);
}
@Test
@Mock
System2 system2;
- NotResolvedIssuesOnRemovedComponentsMigration migration;
+ NotResolvedIssuesOnRemovedComponentsMigrationStep migration;
@Before
public void setUp() throws Exception {
when(system2.now()).thenReturn(DateUtils.parseDate("2014-04-09").getTime());
- migration = new NotResolvedIssuesOnRemovedComponentsMigration(db.database(), system2);
+ migration = new NotResolvedIssuesOnRemovedComponentsMigrationStep(db.database(), system2);
}
@Test
@ClassRule
public static DbTester db = new DbTester().schema(RequirementMeasuresMigrationTest.class, "schema.sql");
- RequirementMeasuresMigration migration;
+ RequirementMeasuresMigrationStep migration;
@Before
public void setUp() throws Exception {
- migration = new RequirementMeasuresMigration(db.database());
+ migration = new RequirementMeasuresMigrationStep(db.database());
}
@Test
@Mock
PropertiesDao propertiesDao;
- TechnicalDebtMeasuresMigration migration;
+ TechnicalDebtMeasuresMigrationStep migration;
@Before
public void setUp() throws Exception {
when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue("8"));
- migration = new TechnicalDebtMeasuresMigration(db.database(), propertiesDao);
+ migration = new TechnicalDebtMeasuresMigrationStep(db.database(), propertiesDao);
}
@Test
System2 system2 = mock(System2.class);
DbClient dbClient;
ActivityDao dao;
- ChangeLogMigration migration;
+ ChangeLogMigrationStep migration;
DbSession session;
@Before
when(system2.now()).thenReturn(DateUtils.parseDate("2014-03-13").getTime());
dao = new ActivityDao(db.myBatis(), system2);
dbClient = new DbClient(db.database(), db.myBatis(), dao);
- migration = new ChangeLogMigration(dao, dbClient);
+ migration = new ChangeLogMigrationStep(dao, dbClient);
session = dbClient.openSession(false);
}
@ClassRule
public static DbTester db = new DbTester().schema(ConvertProfileMeasuresMigrationTest.class, "schema.sql");
- ConvertProfileMeasuresMigration migration;
+ ConvertProfileMeasuresMigrationStep migration;
@Before
public void setUp() throws Exception {
DbClient dbClient = new DbClient(db.database(), db.myBatis());
- migration = new ConvertProfileMeasuresMigration(dbClient);
+ migration = new ConvertProfileMeasuresMigrationStep(dbClient);
}
@Test
@ClassRule
public static DbTester db = new DbTester().schema(FeedQProfileDatesMigrationTest.class, "schema.sql");
- FeedQProfileDatesMigration migration;
+ FeedQProfileDatesMigrationStep migration;
@Before
public void setUp() throws Exception {
DbClient dbClient = new DbClient(db.database(), db.myBatis());
System2 system = mock(System2.class);
when(system.now()).thenReturn(UtcDateUtils.parseDateTime("2014-07-03T12:00:00+0000").getTime());
- migration = new FeedQProfileDatesMigration(dbClient, system);
+ migration = new FeedQProfileDatesMigrationStep(dbClient, system);
}
@Test
public void feed_keys() throws Exception {
db.prepareDbUnit(getClass(), "feed_keys.xml");
- new FeedQProfileKeysMigration(db.database()).execute();
+ new FeedQProfileKeysMigrationStep(db.database()).execute();
List<Map<String, Object>> profiles = db.select("SELECT kee, name, language, parent_kee FROM rules_profiles ORDER BY id ASC");
@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
@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
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;
@ClassRule
public static DbTester db = new DbTester().schema(AddMissingRuleParameterDefaultValuesMigrationTest.class, "schema.sql");
- DatabaseMigration migration;
+ MigrationStep migration;
System2 system = mock(System2.class);
@Before
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());
}
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;
@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
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;
@ClassRule
public static DbTester db = new DbTester().schema(AddMissingCustomRuleParametersMigrationTest.class, "schema.sql");
- DatabaseMigration migration;
+ MigrationStep migration;
System2 system = mock(System2.class);
@Before
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());
}
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;
@ClassRule
public static DbTester db = new DbTester().schema(DeleteUnescapedActivitiesTest.class, "schema.sql");
- DatabaseMigration migration;
+ MigrationStep migration;
@Test
public void execute() throws Exception {
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;
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");
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;
@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);
}
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;
Migration50Mapper mapper;
- DatabaseMigration migration;
+ MigrationStep migration;
@Before
public void setUp() throws Exception {
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
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;
@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());
}
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;
@ClassRule
public static DbTester db = new DbTester().schema(ReplaceIssueFiltersProjectKeyByUuidTest.class, "schema.sql");
- DatabaseMigration migration;
+ MigrationStep migration;
System2 system = mock(System2.class);
@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;
@ClassRule
public static DbTester db = new DbTester().schema(AddIssuesColumnsTest.class, "schema.sql");
- DatabaseMigration migration;
+ MigrationStep migration;
@Before
public void setUp() throws Exception {
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;
@ClassRule
public static DbTester db = new DbTester().schema(AddNewCharacteristicsTest.class, "schema.sql");
- DatabaseMigration migration;
+ MigrationStep migration;
System2 system = mock(System2.class);
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;
@ClassRule
public static DbTester db = new DbTester().schema(CopyScmAccountsFromAuthorsToUsersTest.class, "schema.sql");
- DatabaseMigration migration;
+ MigrationStep migration;
System2 system = mock(System2.class);
@Before
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;
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");
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;
@Test
public void execute() throws Exception {
- DatabaseMigration migration = newMigration(System2.INSTANCE);
+ MigrationStep migration = newMigration(System2.INSTANCE);
migration.execute();
System2 system = mock(System2.class);
when(system.now()).thenReturn(1234L);
- DatabaseMigration migration = newMigration(system);
+ MigrationStep migration = newMigration(system);
migration.execute();
@Test
public void take_date_if_in_the_past() throws Exception {
- DatabaseMigration migration = newMigration(System2.INSTANCE);
+ MigrationStep migration = newMigration(System2.INSTANCE);
migration.execute();
assertThat(count).isEqualTo(1);
}
- private DatabaseMigration newMigration(System2 system) {
+ private MigrationStep newMigration(System2 system) {
return new FeedEventsLongDates(db.database(), system);
}
}
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;
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");
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=");
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;
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");
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;
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
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
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
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;
@Test
public void execute() throws Exception {
- DatabaseMigration migration = newMigration(System2.INSTANCE);
+ MigrationStep migration = newMigration(System2.INSTANCE);
migration.execute();
System2 system = mock(System2.class);
when(system.now()).thenReturn(1234L);
- DatabaseMigration migration = newMigration(system);
+ MigrationStep migration = newMigration(system);
migration.execute();
@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();
assertThat(count).isEqualTo(1);
}
- private DatabaseMigration newMigration(System2 system) {
+ private MigrationStep newMigration(System2 system) {
return new FeedManualMeasuresLongDates(db.database(), system);
}
}
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;
@Test
public void execute() throws Exception {
- DatabaseMigration migration = newMigration(System2.INSTANCE);
+ MigrationStep migration = newMigration(System2.INSTANCE);
migration.execute();
System2 system = mock(System2.class);
when(system.now()).thenReturn(1234L);
- DatabaseMigration migration = newMigration(system);
+ MigrationStep migration = newMigration(system);
migration.execute();
@Test
public void take_snapshot_date_if_in_the_past() throws Exception {
- DatabaseMigration migration = newMigration(System2.INSTANCE);
+ MigrationStep migration = newMigration(System2.INSTANCE);
migration.execute();
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;
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
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
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
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;
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");
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
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;
@ClassRule
public static DbTester db = new DbTester().schema(RenameComponentRelatedParamsInIssueFiltersMigrationTest.class, "schema.sql");
- DatabaseMigration migration;
+ MigrationStep migration;
System2 system = mock(System2.class);
@Before
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;
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 {
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 {
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 {
# 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')
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
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
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
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
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
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
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
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
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
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
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
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')
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
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
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
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
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
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
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
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
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
* 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