import org.sonar.core.platform.Module;
import org.sonar.server.platform.db.migration.history.MigrationHistoryImpl;
import org.sonar.server.platform.db.migration.history.MigrationHistoryMeddler;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStepRegistryImpl;
import org.sonar.server.platform.db.migration.step.MigrationStepsProvider;
import org.sonar.server.platform.db.migration.version.v00.DbVersion00;
import org.sonar.server.platform.db.migration.version.v82.DbVersion82;
import org.sonar.server.platform.db.migration.version.v83.DbVersion83;
import org.sonar.server.platform.db.migration.version.v84.DbVersion84;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import org.sonar.server.platform.db.migration.version.v85.DbVersion85;
import org.sonar.server.platform.db.migration.version.v86.DbVersion86;
MigrationHistoryImpl.class,
MigrationHistoryMeddler.class,
- // Only needed for 8.3
- SqlHelper.class,
+ // Utility classes
+ DbPrimaryKeyConstraintFinder.class,
DropPrimaryKeySqlGenerator.class);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.sql;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import static com.google.common.base.Preconditions.checkState;
+import static java.lang.String.format;
+import static org.sonar.server.platform.db.migration.def.Validations.validateTableName;
+import static org.sonar.server.platform.db.migration.sql.CreateTableBuilder.PRIMARY_KEY_PREFIX;
+
+public class AddPrimaryKeyBuilder {
+
+ private final String tableName;
+ private final List<String> primaryKey;
+
+ public AddPrimaryKeyBuilder(String tableName, String column, String... moreColumns) {
+ this.tableName = validateTableName(tableName);
+ this.primaryKey = Lists.asList(column, moreColumns).stream().filter(Objects::nonNull).collect(Collectors.toList());
+ }
+
+ public String build() {
+ checkState(!primaryKey.isEmpty(), "Primary key is missing");
+ return format("ALTER TABLE %s ADD CONSTRAINT %s%s PRIMARY KEY (%s)", tableName, PRIMARY_KEY_PREFIX, tableName,
+ String.join(",", this.primaryKey));
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.sql;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Locale;
+import java.util.Optional;
+import org.sonar.db.Database;
+import org.sonar.db.dialect.Dialect;
+import org.sonar.db.dialect.H2;
+import org.sonar.db.dialect.MsSql;
+import org.sonar.db.dialect.Oracle;
+import org.sonar.db.dialect.PostgreSql;
+
+import static java.lang.String.format;
+
+public class DbPrimaryKeyConstraintFinder {
+
+ private final Database db;
+
+ public DbPrimaryKeyConstraintFinder(Database db) {
+ this.db = db;
+ }
+
+ public String findConstraintName(String tableName) throws SQLException {
+ String constraintQuery = getDbVendorSpecificQuery(tableName);
+ return executeQuery(constraintQuery)
+ .orElseThrow(() -> constraintNotFoundException(tableName));
+ }
+
+ String getDbVendorSpecificQuery(String tableName) {
+ Dialect dialect = db.getDialect();
+ String constraintQuery;
+ switch (dialect.getId()) {
+ case PostgreSql.ID:
+ constraintQuery = getPostgresSqlConstraintQuery(tableName);
+ break;
+ case MsSql.ID:
+ constraintQuery = getMssqlConstraintQuery(tableName);
+ break;
+ case Oracle.ID:
+ constraintQuery = getOracleConstraintQuery(tableName);
+ break;
+ case H2.ID:
+ constraintQuery = getH2ConstraintQuery(tableName);
+ break;
+ default:
+ throw new IllegalStateException(format("Unsupported database '%s'", dialect.getId()));
+ }
+ return constraintQuery;
+ }
+
+ private Optional<String> executeQuery(String query) throws SQLException {
+ try (Connection connection = db.getDataSource().getConnection();
+ PreparedStatement pstmt = connection
+ .prepareStatement(query);
+ ResultSet rs = pstmt.executeQuery()) {
+ if (rs.next()) {
+ return Optional.ofNullable(rs.getString(1));
+ }
+ return Optional.empty();
+ }
+ }
+
+ private static String getPostgresSqlConstraintQuery(String tableName) {
+ return format("SELECT conname " +
+ "FROM pg_constraint " +
+ "WHERE conrelid = " +
+ " (SELECT oid " +
+ " FROM pg_class " +
+ " WHERE relname LIKE '%s')", tableName);
+ }
+
+ private static String getMssqlConstraintQuery(String tableName) {
+ return format("SELECT name " +
+ "FROM sys.key_constraints " +
+ "WHERE type = 'PK' " +
+ "AND OBJECT_NAME(parent_object_id) = '%s'", tableName);
+ }
+
+ private static String getOracleConstraintQuery(String tableName) {
+ return format("SELECT constraint_name " +
+ "FROM user_constraints " +
+ "WHERE table_name = UPPER('%s') " +
+ "AND constraint_type='P'", tableName);
+ }
+
+ private static String getH2ConstraintQuery(String tableName) {
+ return format("SELECT constraint_name "
+ + "FROM information_schema.constraints "
+ + "WHERE table_name = '%s' and constraint_type = 'PRIMARY KEY'", tableName.toUpperCase(Locale.ENGLISH));
+ }
+
+ static IllegalStateException constraintNotFoundException(String tableName) {
+ return new IllegalStateException(format("Cannot find constraint for table '%s'", tableName));
+ }
+
+ // FIXME:: this method should be moved somewhere else
+ String getPostgresSqlSequence(String tableName, String columnName) throws SQLException {
+ try (Connection connection = db.getDataSource().getConnection();
+ PreparedStatement pstmt = connection.prepareStatement(format("SELECT pg_get_serial_sequence('%s', '%s')", tableName, columnName));
+ ResultSet rs = pstmt.executeQuery()) {
+ if (rs.next()) {
+ return rs.getString(1);
+ }
+ throw new IllegalStateException(format("Cannot find sequence for table '%s' on column '%s'", tableName, columnName));
+ }
+ }
+
+}
import static org.sonar.server.platform.db.migration.def.Validations.validateIndexName;
import static org.sonar.server.platform.db.migration.def.Validations.validateTableName;
+/**
+ * This builder have the main goal to drop constraint of a column.
+ * <p>
+ * It shouldn't be used to drop primary keys constraint, use {@link DropPrimaryKeySqlGenerator}
+ */
public class DropConstraintBuilder {
private final Dialect dialect;
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.sql;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import org.sonar.db.Database;
+import org.sonar.db.dialect.Dialect;
+import org.sonar.db.dialect.H2;
+import org.sonar.db.dialect.MsSql;
+import org.sonar.db.dialect.Oracle;
+import org.sonar.db.dialect.PostgreSql;
+
+import static java.lang.String.format;
+import static java.util.Collections.singletonList;
+
+public class DropPrimaryKeySqlGenerator {
+ private static final String GENERIC_DROP_CONSTRAINT_STATEMENT = "ALTER TABLE %s DROP CONSTRAINT %s";
+
+ private final Database db;
+ private final DbPrimaryKeyConstraintFinder dbConstraintFinder;
+
+ public DropPrimaryKeySqlGenerator(Database db, DbPrimaryKeyConstraintFinder dbConstraintFinder) {
+ this.db = db;
+ this.dbConstraintFinder = dbConstraintFinder;
+ }
+
+ public List<String> generate(String tableName, String columnName, boolean isAutoGenerated) throws SQLException {
+ Dialect dialect = db.getDialect();
+ String constraintName = dbConstraintFinder.findConstraintName(tableName);
+ switch (dialect.getId()) {
+ case PostgreSql.ID:
+ return generateForPostgresSql(tableName, columnName, constraintName);
+ case MsSql.ID:
+ return generateForMsSql(tableName, constraintName);
+ case Oracle.ID:
+ return generateForOracle(tableName, constraintName, isAutoGenerated);
+ case H2.ID:
+ return generateForH2(tableName, constraintName);
+ default:
+ throw new IllegalStateException(format("Unsupported database '%s'", dialect.getId()));
+ }
+ }
+
+ private List<String> generateForPostgresSql(String tableName, String column, String constraintName) throws SQLException {
+ List<String> statements = new ArrayList<>();
+ statements.add(format("ALTER TABLE %s ALTER COLUMN %s DROP DEFAULT", tableName, column));
+
+ String sequence = dbConstraintFinder.getPostgresSqlSequence(tableName, column);
+ if (sequence != null) {
+ statements.add(format("DROP SEQUENCE %s", sequence));
+ }
+
+ statements.add(format(GENERIC_DROP_CONSTRAINT_STATEMENT, tableName, constraintName));
+
+ return statements;
+ }
+
+ private static List<String> generateForOracle(String tableName, String constraintName, boolean isAutoGenerated) {
+ List<String> statements = new ArrayList<>();
+ if (isAutoGenerated) {
+ statements.add(format("DROP TRIGGER %s_IDT", tableName));
+ statements.add(format("DROP SEQUENCE %s_SEQ", tableName));
+ }
+
+ // 'drop index' at the end ensures that associated index with primary key will be deleted
+ statements.add(format(GENERIC_DROP_CONSTRAINT_STATEMENT + " DROP INDEX", tableName, constraintName));
+ return statements;
+ }
+
+ private static List<String> generateForMsSql(String tableName, String constraintName) {
+ return singletonList(format(GENERIC_DROP_CONSTRAINT_STATEMENT, tableName, constraintName));
+ }
+
+ private static List<String> generateForH2(String tableName, String constraintName) {
+ return singletonList(format(GENERIC_DROP_CONSTRAINT_STATEMENT, tableName, constraintName));
+ }
+
+}
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropIdFromComponentsTable extends DdlChange {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.activeruleparameters;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "active_rule_parameters";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfActiveRulesTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.activerules;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfActiveRulesTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "active_rules";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfCeActivityTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.ceactivity;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfCeActivityTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "ce_activity";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfCeQueueTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.cequeue;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfCeQueueTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "ce_queue";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public abstract class DropPrimaryKeyOnIdColumn extends DdlChange {
private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator;
- private String tableName;
+ private final String tableName;
protected DropPrimaryKeyOnIdColumn(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator, String tableName) {
super(db);
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.duplicationsindex;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "duplications_index";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfEventsTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.events;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfEventsTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "events";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfFileSourcesTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.filesources;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfFileSourcesTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "file_sources";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfGroupRolesTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.grouproles;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfGroupRolesTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "group_roles";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfGroupsTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.groups;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfGroupsTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "groups";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfIssueChangesTable extends DdlChange {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnKeeColumnOfIssuesTable extends DdlChange {
private static final String TABLE_NAME = "issues";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfManualMeasuresTable extends DdlChange {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfManualMeasuresTable extends DdlChange {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfMetricsTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.metrics;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfMetricsTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "metrics";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPKeyOnUuidOfLiveMeasuresTable extends DdlChange {
private static final String TABLE_NAME = "live_measures";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfNotificationTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.notifications;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfNotificationTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "notifications";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfPermissionTemplatesTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.permissiontemplates;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfPermissionTemplatesTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "permission_templates";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.permtemplatesgroups;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "perm_templates_groups";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.permtemplatesusers;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "perm_templates_users";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.permtplcharacteristics;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "perm_tpl_characteristics";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfProjectMeasuresTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.projectmeasures;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfProjectMeasuresTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "project_measures";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfProjectQProfilesTable extends DdlChange {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfProjectQProfilesTable extends DdlChange {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfPropertiesTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.properties;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfPropertiesTable extends DropPrimaryKeyOnIdColumn {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.qualitygateconditions;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "quality_gate_conditions";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfQGatesTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.qualitygates;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfQGatesTable extends DropPrimaryKeyOnIdColumn {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfRulesTable extends DdlChange {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfRulesTable extends DdlChange {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable extends DdlChange {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfRulesMetadataTable extends DdlChange {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfRulesParametersTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.rulesparameters;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfRulesParametersTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "rules_parameters";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfRulesProfilesTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.rulesprofiles;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfRulesProfilesTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "rules_profiles";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfSnapshotsTable extends DdlChange {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfSnapshotsTable extends DdlChange {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfUserRolesTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.userroles;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfUserRolesTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "user_roles";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfUsersTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.users;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfUsersTable extends DropPrimaryKeyOnIdColumn {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUserUuidAndOrganizationUuidColumnsOfUserRolesTable extends DdlChange {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTable extends DdlChange {
private static final String TABLE_NAME = "organization_members";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidColumnOfUserTokensTable extends DdlChange {
package org.sonar.server.platform.db.migration.version.v84.usertokens;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
public class DropPrimaryKeyOnIdColumnOfUserTokensTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "user_tokens";
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform.db.migration.version.v84.util;
-
-import com.google.common.collect.Lists;
-import java.util.List;
-
-import static com.google.common.base.Preconditions.checkState;
-import static java.lang.String.format;
-import static org.sonar.server.platform.db.migration.def.Validations.validateTableName;
-import static org.sonar.server.platform.db.migration.sql.CreateTableBuilder.PRIMARY_KEY_PREFIX;
-
-public class AddPrimaryKeyBuilder {
-
- private final String tableName;
- private final List<String> primaryKey;
-
- public AddPrimaryKeyBuilder(String tableName, String column, String... moreColumns) {
- this.tableName = validateTableName(tableName);
- this.primaryKey = Lists.asList(column, moreColumns);
- }
-
- public String build() {
- checkState(primaryKey != null, "Primary key is missing");
- return format("ALTER TABLE %s ADD CONSTRAINT %s%s PRIMARY KEY (%s)", tableName, PRIMARY_KEY_PREFIX, tableName,
- String.join(",", this.primaryKey));
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.platform.db.migration.version.v84.util;
-
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import org.sonar.db.Database;
-import org.sonar.db.dialect.Dialect;
-import org.sonar.db.dialect.H2;
-import org.sonar.db.dialect.MsSql;
-import org.sonar.db.dialect.Oracle;
-import org.sonar.db.dialect.PostgreSql;
-
-import static java.lang.String.format;
-import static java.util.Arrays.asList;
-import static java.util.Collections.singletonList;
-
-public class DropPrimaryKeySqlGenerator {
- private static final String GENERIC_DROP_CONSTRAINT_STATEMENT = "ALTER TABLE %s DROP CONSTRAINT %s";
-
- private final Database db;
- private SqlHelper sqlHelper;
-
- public DropPrimaryKeySqlGenerator(Database db, SqlHelper sqlHelper) {
- this.db = db;
- this.sqlHelper = sqlHelper;
- }
-
- public List<String> generate(String tableName, String columnName, boolean isAutoGenerated) throws SQLException {
- Dialect dialect = db.getDialect();
- switch (dialect.getId()) {
- case PostgreSql.ID:
- return generateForPostgresSql(tableName, columnName, sqlHelper.getPostgresSqlConstraint(tableName));
- case MsSql.ID:
- return generateForMsSql(tableName, sqlHelper.getMssqlConstraint(tableName));
- case Oracle.ID:
- return generateForOracle(tableName, sqlHelper.getOracleConstraint(tableName), isAutoGenerated);
- case H2.ID:
- return generateForH2(tableName, columnName, sqlHelper.getH2Constraint(tableName));
- default:
- throw new IllegalStateException(format("Unsupported database '%s'", dialect.getId()));
- }
- }
-
- private List<String> generateForPostgresSql(String tableName, String column, String constraintName) throws SQLException {
- List<String> statements = new ArrayList<>();
- statements.add(format("ALTER TABLE %s ALTER COLUMN %s DROP DEFAULT", tableName, column));
-
- String sequence = sqlHelper.getPostgresSqlSequence(tableName, column);
- if (sequence != null) {
- statements.add(format("DROP SEQUENCE %s", sequence));
- }
-
- statements.add(format(GENERIC_DROP_CONSTRAINT_STATEMENT, tableName, constraintName));
-
- return statements;
- }
-
- private static List<String> generateForOracle(String tableName, String constraintName, boolean isAutoGenerated) {
- List<String> statements = new ArrayList<>();
- if (isAutoGenerated) {
- statements.add(format("DROP TRIGGER %s_IDT", tableName));
- statements.add(format("DROP SEQUENCE %s_SEQ", tableName));
- }
-
- // 'drop index' at the end ensures that associated index with primary key will be deleted
- statements.add(format(GENERIC_DROP_CONSTRAINT_STATEMENT + " DROP INDEX", tableName, constraintName));
- return statements;
- }
-
- private static List<String> generateForMsSql(String tableName, String constraintName) {
- return singletonList(format(GENERIC_DROP_CONSTRAINT_STATEMENT, tableName, constraintName));
- }
-
- private static List<String> generateForH2(String tableName, String column, String constraintName) {
- return asList(
- format(GENERIC_DROP_CONSTRAINT_STATEMENT, tableName, constraintName),
- format("ALTER TABLE %s ALTER COLUMN %s INTEGER NOT NULL", tableName, column));
- }
-
-}
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyOnUuidForIssueChangesTable extends DdlChange {
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPkToApplicationBranchProjs extends DdlChange {
private static final String TABLE = "app_branch_project_branch";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPkToApplicationProjects extends DdlChange {
private static final String TABLE = "app_projects";
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class AddPrimaryKeyToDefaultQProfiles extends DdlChange {
public AddPrimaryKeyToDefaultQProfiles(Database db) {
import java.sql.SQLException;
import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.sql.DropConstraintBuilder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
public class DropDefaultQProfilesPk extends DdlChange {
- public DropDefaultQProfilesPk(Database db) {
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator;
+ private static final String TABLE_NAME = "default_qprofiles";
+ private static final String COLUMN_NAME = "language";
+
+ public DropDefaultQProfilesPk(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
super(db);
+ this.dropPrimaryKeySqlGenerator = dropPrimaryKeySqlGenerator;
}
@Override
public void execute(Context context) throws SQLException {
- context.execute(new DropConstraintBuilder(getDialect()).setName("pk_default_qprofiles").setTable("default_qprofiles").build());
+ context.execute(dropPrimaryKeySqlGenerator.generate(TABLE_NAME, COLUMN_NAME, false));
}
}
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
import org.sonar.server.platform.db.migration.sql.DropConstraintBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
public class DropOrganizationInRulesMetadata extends DdlChange {
private static final String TABLE_NAME = "rules_metadata";
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.sql;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyBuilderTest {
+
+ private static final String TABLE_NAME = "issues";
+
+ @Test
+ public void generate() {
+ String sql = new AddPrimaryKeyBuilder(TABLE_NAME, "id").build();
+
+ assertThat(sql).isEqualTo("ALTER TABLE issues ADD CONSTRAINT pk_issues PRIMARY KEY (id)");
+ }
+
+ @Test
+ public void fail_when_table_name_is_invalid() {
+ assertThatThrownBy(() -> new AddPrimaryKeyBuilder("abcdefghijklmnopqrstuvwxyz", "id"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void fail_when_primary_key_column_is_invalid() {
+ AddPrimaryKeyBuilder builder = new AddPrimaryKeyBuilder("my_table", null);
+ assertThatThrownBy(builder::build)
+ .isInstanceOf(IllegalStateException.class);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.sql;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.db.Database;
+import org.sonar.db.dialect.H2;
+import org.sonar.db.dialect.MsSql;
+import org.sonar.db.dialect.Oracle;
+import org.sonar.db.dialect.PostgreSql;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class DbPrimaryKeyConstraintFinderTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DbPrimaryKeyConstraintFinderTest.class, "schema.sql");
+
+ private final Database dbMock = mock(Database.class);
+ private final DbPrimaryKeyConstraintFinder underTest = new DbPrimaryKeyConstraintFinder(dbMock);
+
+ private static final PostgreSql POSTGRESQL = new PostgreSql();
+ private static final MsSql MS_SQL = new MsSql();
+ private static final Oracle ORACLE = new Oracle();
+ private static final org.sonar.db.dialect.H2 H2 = new H2();
+
+ @Test
+ public void findConstraintName_constraint_exists() throws SQLException {
+ DbPrimaryKeyConstraintFinder underTest = new DbPrimaryKeyConstraintFinder(db.database());
+ String constraintName = underTest.findConstraintName("TEST_PRIMARY_KEY");
+ assertThat(constraintName).isEqualTo("PK_TEST_PRIMARY_KEY");
+ }
+
+ @Test
+ public void findConstraintName_constraint_not_exist() {
+ DbPrimaryKeyConstraintFinder underTest = new DbPrimaryKeyConstraintFinder(db.database());
+ assertThatThrownBy(() -> underTest.findConstraintName("NOT_EXISTING_TABLE"))
+ .hasMessage("Cannot find constraint for table 'NOT_EXISTING_TABLE'")
+ .isInstanceOf(IllegalStateException.class);
+ }
+
+ @Test
+ public void getDbVendorSpecificQuery_mssql() {
+ when(dbMock.getDialect()).thenReturn(MS_SQL);
+
+ assertThat(underTest.getDbVendorSpecificQuery("my_table"))
+ .isEqualTo("SELECT name FROM sys.key_constraints WHERE type = 'PK' AND OBJECT_NAME(parent_object_id) = 'my_table'");
+ }
+
+ @Test
+ public void getDbVendorSpecificQuery_postgresql() {
+ when(dbMock.getDialect()).thenReturn(POSTGRESQL);
+
+ assertThat(underTest.getDbVendorSpecificQuery("my_table"))
+ .isEqualTo("SELECT conname FROM pg_constraint WHERE conrelid = (SELECT oid FROM pg_class WHERE relname LIKE 'my_table')");
+ }
+
+ @Test
+ public void getDbVendorSpecificQuery_oracle() {
+ when(dbMock.getDialect()).thenReturn(ORACLE);
+
+ assertThat(underTest.getDbVendorSpecificQuery("my_table"))
+ .isEqualTo("SELECT constraint_name FROM user_constraints WHERE table_name = UPPER('my_table') AND constraint_type='P'");
+ }
+
+ @Test
+ public void getDbVendorSpecificQuery_h2() {
+ when(dbMock.getDialect()).thenReturn(H2);
+
+ assertThat(underTest.getDbVendorSpecificQuery("my_table"))
+ .isEqualTo("SELECT constraint_name FROM information_schema.constraints WHERE table_name = 'MY_TABLE' and constraint_type = 'PRIMARY KEY'");
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.sql;
+
+import java.sql.SQLException;
+import java.util.List;
+import org.junit.Test;
+import org.sonar.db.Database;
+import org.sonar.db.dialect.Dialect;
+import org.sonar.db.dialect.H2;
+import org.sonar.db.dialect.MsSql;
+import org.sonar.db.dialect.Oracle;
+import org.sonar.db.dialect.PostgreSql;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class DropPrimaryKeySqlGeneratorTest {
+
+ private static final String TABLE_NAME = "issues";
+ private static final String PK_COLUMN = "id";
+ private static final String CONSTRAINT = "pk_id";
+
+ private static final PostgreSql POSTGRESQL = new PostgreSql();
+ private static final MsSql MS_SQL = new MsSql();
+ private static final Oracle ORACLE = new Oracle();
+ private static final org.sonar.db.dialect.H2 H2 = new H2();
+
+ private final Database db = mock(Database.class);
+ private final DbPrimaryKeyConstraintFinder dbConstraintFinder = mock(DbPrimaryKeyConstraintFinder.class);
+
+ private final DropPrimaryKeySqlGenerator underTest = new DropPrimaryKeySqlGenerator(db, dbConstraintFinder);
+
+ @Test
+ public void generate_unknown_dialect() {
+ Dialect mockDialect = mock(Dialect.class);
+ when(mockDialect.getId()).thenReturn("unknown-db-vendor");
+ when(db.getDialect()).thenReturn(mockDialect);
+
+ assertThatThrownBy(() -> underTest.generate(TABLE_NAME, PK_COLUMN, true))
+ .isInstanceOf(IllegalStateException.class);
+ }
+
+ @Test
+ public void generate_for_postgres_sql() throws SQLException {
+ when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT);
+ when(dbConstraintFinder.getPostgresSqlSequence(TABLE_NAME, "id")).thenReturn(TABLE_NAME + "_id_seq");
+ when(db.getDialect()).thenReturn(POSTGRESQL);
+
+ List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
+
+ assertThat(sqls).containsExactly("ALTER TABLE issues ALTER COLUMN id DROP DEFAULT",
+ "DROP SEQUENCE issues_id_seq",
+ "ALTER TABLE issues DROP CONSTRAINT pk_id");
+ }
+
+ @Test
+ public void generate_for_postgres_sql_no_seq() throws SQLException {
+ when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT);
+ when(dbConstraintFinder.getPostgresSqlSequence(TABLE_NAME, "id")).thenReturn(null);
+ when(db.getDialect()).thenReturn(POSTGRESQL);
+
+ List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
+
+ assertThat(sqls).containsExactly("ALTER TABLE issues ALTER COLUMN id DROP DEFAULT",
+ "ALTER TABLE issues DROP CONSTRAINT pk_id");
+ }
+
+ @Test
+ public void generate_for_ms_sql() throws SQLException {
+ when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT);
+ when(db.getDialect()).thenReturn(MS_SQL);
+
+ List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
+
+ assertThat(sqls).containsExactly("ALTER TABLE issues DROP CONSTRAINT pk_id");
+ }
+
+ @Test
+ public void generate_for_oracle_autogenerated_true() throws SQLException {
+ when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT);
+ when(db.getDialect()).thenReturn(ORACLE);
+
+ List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
+
+ assertThat(sqls).containsExactly("DROP TRIGGER issues_IDT",
+ "DROP SEQUENCE issues_SEQ",
+ "ALTER TABLE issues DROP CONSTRAINT pk_id DROP INDEX");
+ }
+
+ @Test
+ public void generate_for_oracle_autogenerated_false() throws SQLException {
+ when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT);
+ when(db.getDialect()).thenReturn(ORACLE);
+
+ List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, false);
+
+ assertThat(sqls).containsExactly("ALTER TABLE issues DROP CONSTRAINT pk_id DROP INDEX");
+ }
+
+ @Test
+ public void generate_for_h2() throws SQLException {
+ when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT);
+ when(db.getDialect()).thenReturn(H2);
+
+ List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
+
+ assertThat(sqls).containsExactly("ALTER TABLE issues DROP CONSTRAINT pk_id");
+ }
+}
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import static java.sql.Types.INTEGER;
import static org.sonar.server.platform.db.migration.version.v83.DropIdFromComponentsTable.COLUMN_NAME;
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(dbTester.database(), new SqlHelper(dbTester.database()));
- private DropIdFromComponentsTable underTest = new DropIdFromComponentsTable(dbTester.database(), dropPrimaryKeySqlGenerator);
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(dbTester.database(), new DbPrimaryKeyConstraintFinder(dbTester.database()));
+ private final DropIdFromComponentsTable underTest = new DropIdFromComponentsTable(dbTester.database(), dropPrimaryKeySqlGenerator);
@Test
public void column_has_been_dropped() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStep;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfActiveRulesTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfActiveRulesTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfActiveRulesTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStep;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfCeActivityTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfCeActivityTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfCeActivityTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStep;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfCeQueueTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfCeQueueTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfCeQueueTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStep;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfEventsTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private DropPrimaryKeyOnIdColumnOfEventsTable underTest = new DropPrimaryKeyOnIdColumnOfEventsTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final DropPrimaryKeyOnIdColumnOfEventsTable underTest = new DropPrimaryKeyOnIdColumnOfEventsTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfFileSourcesTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfFileSourcesTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfFileSourcesTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfGroupRolesTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private DropPrimaryKeyOnIdColumnOfGroupRolesTable underTest = new DropPrimaryKeyOnIdColumnOfGroupRolesTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final DropPrimaryKeyOnIdColumnOfGroupRolesTable underTest = new DropPrimaryKeyOnIdColumnOfGroupRolesTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfGroupsTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfGroupsTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfGroupsTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStep;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfManualMeasuresTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfManualMeasuresTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfManualMeasuresTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfMetricsTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfMetricsTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfMetricsTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStep;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfNotificationTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfNotificationTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfNotificationTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStep;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfPermissionTemplatesTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfPermissionTemplatesTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfPermissionTemplatesTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
public CoreDbTester db = CoreDbTester.createForSchema(
DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
public CoreDbTester db = CoreDbTester.createForSchema(
DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
public CoreDbTester db = CoreDbTester.createForSchema(
DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStep;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfProjectMeasuresTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfProjectMeasuresTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfProjectQProfilesTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfProjectQProfilesTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfProjectQProfilesTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStep;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfPropertiesTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfPropertiesTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfPropertiesTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStep;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfQGatesTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfQGatesTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfQGatesTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStep;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesTableTest.class, "schema.sql");
- private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesTable(db.database(),
- new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database())));
+ private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesTable(db.database(),
+ new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database())));
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStep;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.class, "schema.sql");
- private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesMetadataTable(db.database(),
- new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database())));
+ private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesMetadataTable(db.database(),
+ new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database())));
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStep;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesParametersTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesParametersTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesParametersTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfRulesProfilesTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfRulesProfilesTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.version.v84.snapshots.issues.DropPrimaryKeyOnIdColumnOfSnapshotsTable;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfSnapshotsTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private DropPrimaryKeyOnIdColumnOfSnapshotsTable underTest = new DropPrimaryKeyOnIdColumnOfSnapshotsTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final DropPrimaryKeyOnIdColumnOfSnapshotsTable underTest = new DropPrimaryKeyOnIdColumnOfSnapshotsTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfUsersTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfUsersTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfUsersTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private DdlChange underTest = new DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final DdlChange underTest = new DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStep;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfUserTokensTableTest.class, "schema.sql");
- private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
- private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfUserTokensTable(db.database(), dropPrimaryKeySqlGenerator);
+ private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfUserTokensTable(db.database(), dropPrimaryKeySqlGenerator);
@Test
public void execute() throws SQLException {
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform.db.migration.version.v84.util;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-public class AddPrimaryKeyBuilderTest {
-
- private static final String TABLE_NAME = "issues";
-
- @Test
- public void generate() {
- String sql = new AddPrimaryKeyBuilder(TABLE_NAME, "id").build();
-
- assertThat(sql).isEqualTo("ALTER TABLE issues ADD CONSTRAINT pk_issues PRIMARY KEY (id)");
- }
-
- @Test
- public void fail_when_table_name_is_invalid() {
- assertThatThrownBy(() -> new AddPrimaryKeyBuilder("abcdefghijklmnopqrstuvwxyz", "id").build())
- .isInstanceOf(IllegalArgumentException.class);
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform.db.migration.version.v84.util;
-
-import java.sql.SQLException;
-import java.util.List;
-import org.junit.Test;
-import org.sonar.db.Database;
-import org.sonar.db.dialect.H2;
-import org.sonar.db.dialect.MsSql;
-import org.sonar.db.dialect.Oracle;
-import org.sonar.db.dialect.PostgreSql;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class DropPrimaryKeySqlGeneratorTest {
-
- private static final String TABLE_NAME = "issues";
- private static final String PK_COLUMN = "id";
- private static final String CONSTRAINT = "pk_id";
-
- private static final PostgreSql POSTGRESQL = new PostgreSql();
- private static final MsSql MS_SQL = new MsSql();
- private static final Oracle ORACLE = new Oracle();
- private static final org.sonar.db.dialect.H2 H2 = new H2();
-
- private Database db = mock(Database.class);
- private SqlHelper sqlHelper = mock(SqlHelper.class);
-
- private DropPrimaryKeySqlGenerator underTest = new DropPrimaryKeySqlGenerator(db, sqlHelper);
-
- @Test
- public void generate_for_postgres_sql() throws SQLException {
- when(sqlHelper.getPostgresSqlConstraint(TABLE_NAME)).thenReturn(CONSTRAINT);
- when(sqlHelper.getPostgresSqlSequence(TABLE_NAME, "id")).thenReturn(TABLE_NAME + "_id_seq");
- when(db.getDialect()).thenReturn(POSTGRESQL);
-
- List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
-
- assertThat(sqls).containsExactly("ALTER TABLE issues ALTER COLUMN id DROP DEFAULT",
- "DROP SEQUENCE issues_id_seq",
- "ALTER TABLE issues DROP CONSTRAINT pk_id");
- }
-
- @Test
- public void generate_for_ms_sql() throws SQLException {
- when(sqlHelper.getMssqlConstraint(TABLE_NAME)).thenReturn(CONSTRAINT);
- when(db.getDialect()).thenReturn(MS_SQL);
-
- List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
-
- assertThat(sqls).containsExactly("ALTER TABLE issues DROP CONSTRAINT pk_id");
- }
-
- @Test
- public void generate_for_oracle() throws SQLException {
- when(sqlHelper.getOracleConstraint(TABLE_NAME)).thenReturn(CONSTRAINT);
- when(db.getDialect()).thenReturn(ORACLE);
-
- List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
-
- assertThat(sqls).containsExactly("DROP TRIGGER issues_IDT",
- "DROP SEQUENCE issues_SEQ",
- "ALTER TABLE issues DROP CONSTRAINT pk_id DROP INDEX");
- }
-
- @Test
- public void generate_for_h2() throws SQLException {
- when(sqlHelper.getH2Constraint(TABLE_NAME)).thenReturn(CONSTRAINT);
- when(db.getDialect()).thenReturn(H2);
-
- List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
-
- assertThat(sqls).containsExactly("ALTER TABLE issues DROP CONSTRAINT pk_id",
- "ALTER TABLE issues ALTER COLUMN id INTEGER NOT NULL");
- }
-}
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.MigrationStep;
public class DropDefaultQProfilesPkTest {
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropDefaultQProfilesPkTest.class, "schema.sql");
- private MigrationStep underTest = new DropDefaultQProfilesPk(db.database());
+ private final MigrationStep underTest = new DropDefaultQProfilesPk(db.database(), new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database())));
@Test
public void execute() throws SQLException {
--- /dev/null
+CREATE TABLE "TEST_PRIMARY_KEY"(
+ "UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "TEST_PRIMARY_KEY" ADD CONSTRAINT "PK_TEST_PRIMARY_KEY" PRIMARY KEY("UUID");