From: Julien Lancelot Date: Thu, 26 Feb 2015 11:07:30 +0000 (+0100) Subject: Rename a migration because the name is too long on windows X-Git-Tag: 5.1-RC1~55 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=dcb0457a1a79f9baa412849bd1524c14032f5c0f;p=sonarqube.git Rename a migration because the name is too long on windows --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java index f454013b2a1..6afedd0a1f6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java @@ -92,7 +92,7 @@ public interface DatabaseMigrations { FeedProjectMeasuresLongDates.class, FeedManualMeasuresLongDates.class, FeedEventsLongDates.class, - AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.class, + AddNewCharacteristics.class, RemovePermissionsOnModulesMigration.class ); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.java deleted file mode 100644 index 7c5714413cb..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.java +++ /dev/null @@ -1,324 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.db.migrations.v51; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.utils.MessageException; -import org.sonar.api.utils.System2; -import org.sonar.core.persistence.Database; -import org.sonar.server.db.migrations.BaseDataChange; -import org.sonar.server.db.migrations.Select; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.sql.SQLException; -import java.util.Date; -import java.util.List; - -/** - * See http://jira.codehaus.org/browse/SONAR-6187 - * - * Add a new Characteristic 'Usability' with 2 sub-characteristics 'Accessibility' and 'Ease of Use' - * and add a new sub-characteristic 'Compliance' for all characteristics. - * - * Nothing will be done if there's no characteristics in db, as they're all gonna be created by {@link org.sonar.server.startup.RegisterDebtModel} - * - * Before 4.3 the characteristics table contains requirements, then when selecting characteristics we should not forget to exclude them (with a filter on rule_id IS NULL) - * - */ -public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration extends BaseDataChange { - - private static final Logger LOGGER = LoggerFactory.getLogger(AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.class); - - private static final String COMPLIANCE_NAME = "Compliance"; - private static final String COMPLIANCE_KEY_SUFFIX = "_COMPLIANCE"; - - private static final String SECURITY_KEY = "SECURITY"; - private static final String USABILITY_KEY = "USABILITY"; - - private static final String ERROR_SUFFIX = "Please restore your DB backup, start the previous version of SonarQube " + - "and update your SQALE model to fix this issue before trying again to run the migration."; - - private final System2 system; - - public AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration(Database db, System2 system) { - super(db); - this.system = system; - } - - @Override - public void execute(Context context) throws SQLException { - CharacteristicsContext characteristicsContext = new CharacteristicsContext(context, system); - - // On an empty DB, there are no characteristics, they're all gonna be created after in RegisterDebtModel - if (!characteristicsContext.characteristics().isEmpty()) { - int usabilityOder = moveCharacteristicsDownToBeAbleToInsertUsability(characteristicsContext); - createOrUpdateUsabilityCharacteristicAndItsSubCharacteristic(characteristicsContext, usabilityOder); - - createSubCharacteristic(characteristicsContext, "REUSABILITY" + COMPLIANCE_KEY_SUFFIX, "Reusability " + COMPLIANCE_NAME, "REUSABILITY"); - createSubCharacteristic(characteristicsContext, "PORTABILITY" + COMPLIANCE_KEY_SUFFIX, "Portability " + COMPLIANCE_NAME, "PORTABILITY"); - createSubCharacteristic(characteristicsContext, "MAINTAINABILITY" + COMPLIANCE_KEY_SUFFIX, "Maintainability " + COMPLIANCE_NAME, "MAINTAINABILITY"); - createSubCharacteristic(characteristicsContext, SECURITY_KEY + COMPLIANCE_KEY_SUFFIX, "Security " + COMPLIANCE_NAME, SECURITY_KEY); - createSubCharacteristic(characteristicsContext, "EFFICIENCY" + COMPLIANCE_KEY_SUFFIX, "Efficiency " + COMPLIANCE_NAME, "EFFICIENCY"); - createSubCharacteristic(characteristicsContext, "CHANGEABILITY" + COMPLIANCE_KEY_SUFFIX, "Changeability " + COMPLIANCE_NAME, "CHANGEABILITY"); - createSubCharacteristic(characteristicsContext, "RELIABILITY" + COMPLIANCE_KEY_SUFFIX, "Reliability " + COMPLIANCE_NAME, "RELIABILITY"); - createSubCharacteristic(characteristicsContext, "TESTABILITY" + COMPLIANCE_KEY_SUFFIX, "Testability " + COMPLIANCE_NAME, "TESTABILITY"); - } - } - - /** - * If the characteristic 'Security' exists, the new characteristic 'Usability' should be inserted just below it, - * so every existing characteristics below Security should move down. - * - * If the characteristic 'Security' does not exists, the new characteristic 'Usability' should be the first one, - * so every existing characteristics should move down. - * - * If the characteristic 'Usability' is already at the right place, nothing will be done. - */ - private int moveCharacteristicsDownToBeAbleToInsertUsability(CharacteristicsContext characteristicsContext) throws SQLException { - Characteristic security = characteristicsContext.findCharacteristicByKey(SECURITY_KEY); - Characteristic usability = characteristicsContext.findCharacteristicByKey(USABILITY_KEY); - - int usabilityOder = 1; - int indexToStart = 0; - if (security != null) { - indexToStart = characteristicsContext.characteristics().indexOf(security) + 1; - usabilityOder = security.getOrder() + 1; - } - - if (usability == null || usability.getOrder() != usabilityOder) { - // Move root characteristics one step lower - for (int i = indexToStart; i < characteristicsContext.characteristics().size(); i++) { - Characteristic characteristic = characteristicsContext.characteristics().get(i); - if (characteristic.getParentId() == null) { - characteristicsContext.updateCharacteristicOrder(characteristic.getKey(), characteristic.getOrder() + 1); - } - } - } - return usabilityOder; - } - - private void createOrUpdateUsabilityCharacteristicAndItsSubCharacteristic(CharacteristicsContext characteristicsContext, int newUsabilityOrder) - throws SQLException { - String usabilityKey = USABILITY_KEY; - Characteristic usability = characteristicsContext.findCharacteristicByKey(usabilityKey); - if (usability != null) { - if (usability.getOrder() != newUsabilityOrder) { - usability.setOrder(newUsabilityOrder); - characteristicsContext.updateCharacteristicOrder(usability.getKey(), usability.getOrder()); - } - } else { - usability = new Characteristic().setKey(usabilityKey).setName("Usability").setOrder(newUsabilityOrder); - characteristicsContext.insertCharacteristic(usability); - } - - createSubCharacteristic(characteristicsContext, "USABILITY_ACCESSIBILITY", "Accessibility", usabilityKey); - createSubCharacteristic(characteristicsContext, "USABILITY_EASE_OF_USE", "Ease of Use", usabilityKey); - createSubCharacteristic(characteristicsContext, USABILITY_KEY + COMPLIANCE_KEY_SUFFIX, "Usability " + COMPLIANCE_NAME, usabilityKey); - } - - private void createSubCharacteristic(CharacteristicsContext characteristicsContext, - String subCharacteristicKey, String subCharacteristicName, String parentKey) throws SQLException { - Characteristic parent = characteristicsContext.findCharacteristicByKey(parentKey); - if (parent != null) { - Characteristic subCharacteristic = characteristicsContext.findSubCharacteristicByKey(subCharacteristicKey, parent); - if (subCharacteristic == null) { - characteristicsContext.insertCharacteristic(new Characteristic().setKey(subCharacteristicKey).setName(subCharacteristicName).setParentId(parent.getId())); - } - } - // If the characteristic parent does not exits, the sub-characteristic is not added - } - - private static class Characteristic { - private Integer id; - private String key; - private String name; - private Integer order; - private Integer parentId; - - public Integer getId() { - return id; - } - - public Characteristic setId(Integer id) { - this.id = id; - return this; - } - - public String getKey() { - return key; - } - - public Characteristic setKey(String key) { - this.key = key; - return this; - } - - public String getName() { - return name; - } - - public Characteristic setName(String name) { - this.name = name; - return this; - } - - /** - * On a characteristic, the order can never be null - */ - public Integer getOrder() { - return parentId == null && order != null ? order : null; - } - - public Characteristic setOrder(@Nullable Integer order) { - this.order = order; - return this; - } - - @CheckForNull - public Integer getParentId() { - return parentId; - } - - public Characteristic setParentId(@Nullable Integer parentId) { - this.parentId = parentId; - return this; - } - } - - private static class CharacteristicsContext { - private final System2 system; - Context context; - Date now; - List characteristics; - - public CharacteristicsContext(Context context, System2 system) throws SQLException { - this.context = context; - this.system = system; - init(); - } - - private void init() throws SQLException { - now = new Date(system.now()); - characteristics = selectEnabledCharacteristics(); - } - - public List characteristics() { - return characteristics; - } - - @CheckForNull - public Characteristic findCharacteristicByKey(final String key) { - Characteristic characteristic = Iterables.find(characteristics, new Predicate() { - @Override - public boolean apply(@Nullable Characteristic input) { - return input != null && input.key.equals(key); - } - }, null); - if (characteristic != null && characteristic.getParentId() != null) { - throw MessageException.of(String.format("'%s' must be a characteristic. " + ERROR_SUFFIX, characteristic.getName())); - } - return characteristic; - } - - @CheckForNull - public Characteristic findSubCharacteristicByKey(final String key, Characteristic parent) { - Characteristic characteristic = Iterables.find(characteristics, new Predicate() { - @Override - public boolean apply(@Nullable Characteristic input) { - return input != null && input.key.equals(key); - } - }, null); - if (characteristic != null) { - Integer parentId = characteristic.getParentId(); - if (parentId == null) { - throw MessageException.of(String.format("'%s' must be a sub-characteristic. " + ERROR_SUFFIX, characteristic.getName())); - } else if (!parentId.equals(parent.getId())) { - throw MessageException.of(String.format("'%s' must be defined under '%s'. " + ERROR_SUFFIX, characteristic.getName(), parent.getName())); - } - } - return characteristic; - } - - private List selectEnabledCharacteristics() throws SQLException { - return context.prepareSelect( - // Exclude requirements (to not fail when coming from a version older than 4.3) - "SELECT c.id, c.kee, c.name, c.characteristic_order, c.parent_id FROM characteristics c WHERE c.enabled=? AND c.rule_id IS NULL ORDER BY c.characteristic_order") - .setBoolean(1, true) - .list(new CharacteristicReader()); - } - - private int selectCharacteristicId(String key) throws SQLException { - return context.prepareSelect( - "SELECT c.id FROM characteristics c WHERE c.kee = ? AND c.enabled=?") - .setString(1, key) - .setBoolean(2, true) - .get(Select.LONG_READER).intValue(); - } - - public void insertCharacteristic(Characteristic characteristic) throws SQLException { - if (characteristic.getParentId() == null) { - LOGGER.info("Insert new characteristic '{}'", characteristic.getKey()); - } else { - LOGGER.info("Insert new sub characteristic '{}'", characteristic.getKey()); - } - - context.prepareUpsert("INSERT INTO characteristics (kee, name, parent_id, characteristic_order, enabled, created_at) VALUES (?, ?, ?, ?, ?, ?)") - .setString(1, characteristic.getKey()) - .setString(2, characteristic.getName()) - .setInt(3, characteristic.getParentId()) - .setInt(4, characteristic.getOrder()) - .setBoolean(5, true) - .setDate(6, now) - .execute() - .commit(); - characteristic.setId(selectCharacteristicId(characteristic.getKey())); - - characteristics.add(characteristic); - } - - public void updateCharacteristicOrder(String key, Integer order) throws SQLException { - LOGGER.info("Update characteristic '{}' order to {}", key, order); - - context.prepareUpsert("UPDATE characteristics SET characteristic_order=?, updated_at=? WHERE kee=?") - .setInt(1, order) - .setDate(2, now) - .setString(3, key) - .execute() - .commit(); - } - - private static class CharacteristicReader implements Select.RowReader { - @Override - public Characteristic read(Select.Row row) throws SQLException { - return new Characteristic() - .setId(row.getInt(1)) - .setKey(row.getString(2)) - .setName(row.getString(3)) - .setOrder(row.getNullableInt(4)) - .setParentId(row.getNullableInt(5)); - } - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/AddNewCharacteristics.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/AddNewCharacteristics.java new file mode 100644 index 00000000000..9b66e70a07e --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/AddNewCharacteristics.java @@ -0,0 +1,323 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.db.migrations.v51; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sonar.api.utils.MessageException; +import org.sonar.api.utils.System2; +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.Select; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import java.sql.SQLException; +import java.util.Date; +import java.util.List; + +/** + * See http://jira.codehaus.org/browse/SONAR-6187 + * + * Add a new Characteristic 'Usability' with 2 sub-characteristics 'Accessibility' and 'Ease of Use' + * and add a new sub-characteristic 'Compliance' for all characteristics. + * + * Nothing will be done if there's no characteristics in db, as they're all gonna be created by {@link org.sonar.server.startup.RegisterDebtModel} + * + * Before 4.3 the characteristics table contains requirements, then when selecting characteristics we should not forget to exclude them (with a filter on rule_id IS NULL) + * + */ +public class AddNewCharacteristics extends BaseDataChange { + + private static final Logger LOGGER = LoggerFactory.getLogger(AddNewCharacteristics.class); + + private static final String COMPLIANCE_NAME = "Compliance"; + private static final String COMPLIANCE_KEY_SUFFIX = "_COMPLIANCE"; + + private static final String SECURITY_KEY = "SECURITY"; + private static final String USABILITY_KEY = "USABILITY"; + + private static final String ERROR_SUFFIX = "Please restore your DB backup, start the previous version of SonarQube " + + "and update your SQALE model to fix this issue before trying again to run the migration."; + + private final System2 system; + + public AddNewCharacteristics(Database db, System2 system) { + super(db); + this.system = system; + } + + @Override + public void execute(Context context) throws SQLException { + CharacteristicsContext characteristicsContext = new CharacteristicsContext(context, system); + + // On an empty DB, there are no characteristics, they're all gonna be created after in RegisterDebtModel + if (!characteristicsContext.characteristics().isEmpty()) { + int usabilityOder = moveCharacteristicsDownToBeAbleToInsertUsability(characteristicsContext); + createOrUpdateUsabilityCharacteristicAndItsSubCharacteristic(characteristicsContext, usabilityOder); + + createSubCharacteristic(characteristicsContext, "REUSABILITY" + COMPLIANCE_KEY_SUFFIX, "Reusability " + COMPLIANCE_NAME, "REUSABILITY"); + createSubCharacteristic(characteristicsContext, "PORTABILITY" + COMPLIANCE_KEY_SUFFIX, "Portability " + COMPLIANCE_NAME, "PORTABILITY"); + createSubCharacteristic(characteristicsContext, "MAINTAINABILITY" + COMPLIANCE_KEY_SUFFIX, "Maintainability " + COMPLIANCE_NAME, "MAINTAINABILITY"); + createSubCharacteristic(characteristicsContext, SECURITY_KEY + COMPLIANCE_KEY_SUFFIX, "Security " + COMPLIANCE_NAME, SECURITY_KEY); + createSubCharacteristic(characteristicsContext, "EFFICIENCY" + COMPLIANCE_KEY_SUFFIX, "Efficiency " + COMPLIANCE_NAME, "EFFICIENCY"); + createSubCharacteristic(characteristicsContext, "CHANGEABILITY" + COMPLIANCE_KEY_SUFFIX, "Changeability " + COMPLIANCE_NAME, "CHANGEABILITY"); + createSubCharacteristic(characteristicsContext, "RELIABILITY" + COMPLIANCE_KEY_SUFFIX, "Reliability " + COMPLIANCE_NAME, "RELIABILITY"); + createSubCharacteristic(characteristicsContext, "TESTABILITY" + COMPLIANCE_KEY_SUFFIX, "Testability " + COMPLIANCE_NAME, "TESTABILITY"); + } + } + + /** + * If the characteristic 'Security' exists, the new characteristic 'Usability' should be inserted just below it, + * so every existing characteristics below Security should move down. + * + * If the characteristic 'Security' does not exists, the new characteristic 'Usability' should be the first one, + * so every existing characteristics should move down. + * + * If the characteristic 'Usability' is already at the right place, nothing will be done. + */ + private int moveCharacteristicsDownToBeAbleToInsertUsability(CharacteristicsContext characteristicsContext) throws SQLException { + Characteristic security = characteristicsContext.findCharacteristicByKey(SECURITY_KEY); + Characteristic usability = characteristicsContext.findCharacteristicByKey(USABILITY_KEY); + + int usabilityOder = 1; + int indexToStart = 0; + if (security != null) { + indexToStart = characteristicsContext.characteristics().indexOf(security) + 1; + usabilityOder = security.getOrder() + 1; + } + + if (usability == null || usability.getOrder() != usabilityOder) { + // Move root characteristics one step lower + for (int i = indexToStart; i < characteristicsContext.characteristics().size(); i++) { + Characteristic characteristic = characteristicsContext.characteristics().get(i); + if (characteristic.getParentId() == null) { + characteristicsContext.updateCharacteristicOrder(characteristic.getKey(), characteristic.getOrder() + 1); + } + } + } + return usabilityOder; + } + + private void createOrUpdateUsabilityCharacteristicAndItsSubCharacteristic(CharacteristicsContext characteristicsContext, int newUsabilityOrder) + throws SQLException { + String usabilityKey = USABILITY_KEY; + Characteristic usability = characteristicsContext.findCharacteristicByKey(usabilityKey); + if (usability != null) { + if (usability.getOrder() != newUsabilityOrder) { + usability.setOrder(newUsabilityOrder); + characteristicsContext.updateCharacteristicOrder(usability.getKey(), usability.getOrder()); + } + } else { + usability = new Characteristic().setKey(usabilityKey).setName("Usability").setOrder(newUsabilityOrder); + characteristicsContext.insertCharacteristic(usability); + } + + createSubCharacteristic(characteristicsContext, "USABILITY_ACCESSIBILITY", "Accessibility", usabilityKey); + createSubCharacteristic(characteristicsContext, "USABILITY_EASE_OF_USE", "Ease of Use", usabilityKey); + createSubCharacteristic(characteristicsContext, USABILITY_KEY + COMPLIANCE_KEY_SUFFIX, "Usability " + COMPLIANCE_NAME, usabilityKey); + } + + private void createSubCharacteristic(CharacteristicsContext characteristicsContext, + String subCharacteristicKey, String subCharacteristicName, String parentKey) throws SQLException { + Characteristic parent = characteristicsContext.findCharacteristicByKey(parentKey); + if (parent != null) { + Characteristic subCharacteristic = characteristicsContext.findSubCharacteristicByKey(subCharacteristicKey, parent); + if (subCharacteristic == null) { + characteristicsContext.insertCharacteristic(new Characteristic().setKey(subCharacteristicKey).setName(subCharacteristicName).setParentId(parent.getId())); + } + } + // If the characteristic parent does not exits, the sub-characteristic is not added + } + + private static class Characteristic { + private Integer id; + private String key; + private String name; + private Integer order; + private Integer parentId; + + public Integer getId() { + return id; + } + + public Characteristic setId(Integer id) { + this.id = id; + return this; + } + + public String getKey() { + return key; + } + + public Characteristic setKey(String key) { + this.key = key; + return this; + } + + public String getName() { + return name; + } + + public Characteristic setName(String name) { + this.name = name; + return this; + } + + /** + * On a characteristic, the order can never be null + */ + public Integer getOrder() { + return parentId == null && order != null ? order : null; + } + + public Characteristic setOrder(@Nullable Integer order) { + this.order = order; + return this; + } + + @CheckForNull + public Integer getParentId() { + return parentId; + } + + public Characteristic setParentId(@Nullable Integer parentId) { + this.parentId = parentId; + return this; + } + } + + private static class CharacteristicsContext { + private final System2 system; + Context context; + Date now; + List characteristics; + + public CharacteristicsContext(Context context, System2 system) throws SQLException { + this.context = context; + this.system = system; + init(); + } + + private void init() throws SQLException { + now = new Date(system.now()); + characteristics = selectEnabledCharacteristics(); + } + + public List characteristics() { + return characteristics; + } + + @CheckForNull + public Characteristic findCharacteristicByKey(final String key) { + Characteristic characteristic = Iterables.find(characteristics, new Predicate() { + @Override + public boolean apply(@Nullable Characteristic input) { + return input != null && input.key.equals(key); + } + }, null); + if (characteristic != null && characteristic.getParentId() != null) { + throw MessageException.of(String.format("'%s' must be a characteristic. " + ERROR_SUFFIX, characteristic.getName())); + } + return characteristic; + } + + @CheckForNull + public Characteristic findSubCharacteristicByKey(final String key, Characteristic parent) { + Characteristic characteristic = Iterables.find(characteristics, new Predicate() { + @Override + public boolean apply(@Nullable Characteristic input) { + return input != null && input.key.equals(key); + } + }, null); + if (characteristic != null) { + Integer parentId = characteristic.getParentId(); + if (parentId == null) { + throw MessageException.of(String.format("'%s' must be a sub-characteristic. " + ERROR_SUFFIX, characteristic.getName())); + } else if (!parentId.equals(parent.getId())) { + throw MessageException.of(String.format("'%s' must be defined under '%s'. " + ERROR_SUFFIX, characteristic.getName(), parent.getName())); + } + } + return characteristic; + } + + private List selectEnabledCharacteristics() throws SQLException { + return context.prepareSelect( + // Exclude requirements (to not fail when coming from a version older than 4.3) + "SELECT c.id, c.kee, c.name, c.characteristic_order, c.parent_id FROM characteristics c WHERE c.enabled=? AND c.rule_id IS NULL ORDER BY c.characteristic_order") + .setBoolean(1, true) + .list(new CharacteristicReader()); + } + + private int selectCharacteristicId(String key) throws SQLException { + return context.prepareSelect( + "SELECT c.id FROM characteristics c WHERE c.kee = ? AND c.enabled=?") + .setString(1, key) + .setBoolean(2, true) + .get(Select.LONG_READER).intValue(); + } + + public void insertCharacteristic(Characteristic characteristic) throws SQLException { + if (characteristic.getParentId() == null) { + LOGGER.info("Insert new characteristic '{}'", characteristic.getKey()); + } else { + LOGGER.info("Insert new sub characteristic '{}'", characteristic.getKey()); + } + + context.prepareUpsert("INSERT INTO characteristics (kee, name, parent_id, characteristic_order, enabled, created_at) VALUES (?, ?, ?, ?, ?, ?)") + .setString(1, characteristic.getKey()) + .setString(2, characteristic.getName()) + .setInt(3, characteristic.getParentId()) + .setInt(4, characteristic.getOrder()) + .setBoolean(5, true) + .setDate(6, now) + .execute() + .commit(); + characteristic.setId(selectCharacteristicId(characteristic.getKey())); + + characteristics.add(characteristic); + } + + public void updateCharacteristicOrder(String key, Integer order) throws SQLException { + LOGGER.info("Update characteristic '{}' order to {}", key, order); + + context.prepareUpsert("UPDATE characteristics SET characteristic_order=?, updated_at=? WHERE kee=?") + .setInt(1, order) + .setDate(2, now) + .setString(3, key) + .execute() + .commit(); + } + + private static class CharacteristicReader implements Select.RowReader { + @Override + public Characteristic read(Select.Row row) throws SQLException { + return new Characteristic() + .setId(row.getInt(1)) + .setKey(row.getString(2)) + .setName(row.getString(3)) + .setOrder(row.getNullableInt(4)) + .setParentId(row.getNullableInt(5)); + } + } + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.java deleted file mode 100644 index 012cf06fa4e..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.db.migrations.v51; - -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.sonar.api.utils.DateUtils; -import org.sonar.api.utils.MessageException; -import org.sonar.api.utils.System2; -import org.sonar.core.persistence.DbTester; -import org.sonar.server.db.migrations.DatabaseMigration; - -import static junit.framework.TestCase.fail; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest { - - @ClassRule - public static DbTester db = new DbTester().schema(AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.class, "schema.sql"); - - DatabaseMigration migration; - - System2 system = mock(System2.class); - - @Before - public void setUp() throws Exception { - db.executeUpdateSql("truncate table characteristics"); - - when(system.now()).thenReturn(DateUtils.parseDate("2015-02-15").getTime()); - - migration = new AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration(db.database(), system); - } - - @Test - public void migrate() throws Exception { - db.prepareDbUnit(getClass(), "migrate.xml"); - migration.execute(); - db.assertDbUnit(getClass(), "migrate-result.xml", "characteristics"); - } - - @Test - public void do_nothing_when_already_migrated() throws Exception { - db.prepareDbUnit(getClass(), "do_nothing_when_already_migrated.xml"); - migration.execute(); - db.assertDbUnit(getClass(), "do_nothing_when_already_migrated.xml", "characteristics"); - } - - @Test - public void do_nothing_when_no_characteristics() throws Exception { - db.prepareDbUnit(getClass(), "empty.xml"); - migration.execute(); - assertThat(db.countRowsOfTable("characteristics")).isEqualTo(0); - } - - @Test - public void insert_usability_at_the_top_if_security_does_exists() throws Exception { - db.prepareDbUnit(getClass(), "insert_usability_at_the_top_if_security_does_exists.xml"); - migration.execute(); - db.assertDbUnit(getClass(), "insert_usability_at_the_top_if_security_does_exists-result.xml", "characteristics"); - } - - @Test - public void update_usability_order_if_already_exists() throws Exception { - db.prepareDbUnit(getClass(), "update_usability_if_already_exists.xml"); - migration.execute(); - db.assertDbUnit(getClass(), "update_usability_if_already_exists-result.xml", "characteristics"); - } - - @Test - public void fail_if_usability_exists_as_sub_characteristic() throws Exception { - db.prepareDbUnit(getClass(), "fail_if_usability_exists_as_sub_characteristic.xml"); - - try { - migration.execute(); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(MessageException.class).hasMessage( - "'Usability' must be a characteristic. Please restore your DB backup, start the previous version of SonarQube " + - "and update your SQALE model to fix this issue before trying again to run the migration."); - } - } - - @Test - public void fail_if_compliance_already_exists_as_characteristic() throws Exception { - db.prepareDbUnit(getClass(), "fail_if_compliance_already_exists_as_characteristic.xml"); - - try { - migration.execute(); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(MessageException.class).hasMessage( - "'Compliance' must be a sub-characteristic. Please restore your DB backup, start the previous version of SonarQube " + - "and update your SQALE model to fix this issue before trying again to run the migration."); - } - } - - @Test - public void fail_if_compliance_already_exists_under_wrong_characteristic() throws Exception { - db.prepareDbUnit(getClass(), "fail_if_compliance_already_exists_under_wrong_characteristic.xml"); - - try { - migration.execute(); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(MessageException.class).hasMessage( - "'Reusability Compliance' must be defined under 'Reusability'. Please restore your DB backup, start the previous version of SonarQube " + - "and update your SQALE model to fix this issue before trying again to run the migration."); - } - } - - @Test - public void not_fail_if_some_deprecated_requirements_still_exists_in_db() throws Exception { - db.prepareDbUnit(getClass(), "not_fail_if_some_deprecated_requirements_still_exists_in_db.xml"); - migration.execute(); - db.assertDbUnit(getClass(), "not_fail_if_some_deprecated_requirements_still_exists_in_db.xml", "characteristics"); - } - -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest.java new file mode 100644 index 00000000000..4bc2d86983c --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest.java @@ -0,0 +1,138 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.db.migrations.v51; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.sonar.api.utils.DateUtils; +import org.sonar.api.utils.MessageException; +import org.sonar.api.utils.System2; +import org.sonar.core.persistence.DbTester; +import org.sonar.server.db.migrations.DatabaseMigration; + +import static junit.framework.TestCase.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class AddNewCharacteristicsTest { + + @ClassRule + public static DbTester db = new DbTester().schema(AddNewCharacteristicsTest.class, "schema.sql"); + + DatabaseMigration migration; + + System2 system = mock(System2.class); + + @Before + public void setUp() throws Exception { + db.executeUpdateSql("truncate table characteristics"); + + when(system.now()).thenReturn(DateUtils.parseDate("2015-02-15").getTime()); + + migration = new AddNewCharacteristics(db.database(), system); + } + + @Test + public void migrate() throws Exception { + db.prepareDbUnit(getClass(), "migrate.xml"); + migration.execute(); + db.assertDbUnit(getClass(), "migrate-result.xml", "characteristics"); + } + + @Test + public void do_nothing_when_already_migrated() throws Exception { + db.prepareDbUnit(getClass(), "do_nothing_when_already_migrated.xml"); + migration.execute(); + db.assertDbUnit(getClass(), "do_nothing_when_already_migrated.xml", "characteristics"); + } + + @Test + public void do_nothing_when_no_characteristics() throws Exception { + db.prepareDbUnit(getClass(), "empty.xml"); + migration.execute(); + assertThat(db.countRowsOfTable("characteristics")).isEqualTo(0); + } + + @Test + public void insert_usability_at_the_top_if_security_does_exists() throws Exception { + db.prepareDbUnit(getClass(), "insert_usability_at_the_top_if_security_does_exists.xml"); + migration.execute(); + db.assertDbUnit(getClass(), "insert_usability_at_the_top_if_security_does_exists-result.xml", "characteristics"); + } + + @Test + public void update_usability_order_if_already_exists() throws Exception { + db.prepareDbUnit(getClass(), "update_usability_if_already_exists.xml"); + migration.execute(); + db.assertDbUnit(getClass(), "update_usability_if_already_exists-result.xml", "characteristics"); + } + + @Test + public void fail_if_usability_exists_as_sub_characteristic() throws Exception { + db.prepareDbUnit(getClass(), "fail_if_usability_exists_as_sub_characteristic.xml"); + + try { + migration.execute(); + fail(); + } catch (Exception e) { + assertThat(e).isInstanceOf(MessageException.class).hasMessage( + "'Usability' must be a characteristic. Please restore your DB backup, start the previous version of SonarQube " + + "and update your SQALE model to fix this issue before trying again to run the migration."); + } + } + + @Test + public void fail_if_compliance_already_exists_as_characteristic() throws Exception { + db.prepareDbUnit(getClass(), "fail_if_compliance_already_exists_as_characteristic.xml"); + + try { + migration.execute(); + fail(); + } catch (Exception e) { + assertThat(e).isInstanceOf(MessageException.class).hasMessage( + "'Compliance' must be a sub-characteristic. Please restore your DB backup, start the previous version of SonarQube " + + "and update your SQALE model to fix this issue before trying again to run the migration."); + } + } + + @Test + public void fail_if_compliance_already_exists_under_wrong_characteristic() throws Exception { + db.prepareDbUnit(getClass(), "fail_if_compliance_already_exists_under_wrong_characteristic.xml"); + + try { + migration.execute(); + fail(); + } catch (Exception e) { + assertThat(e).isInstanceOf(MessageException.class).hasMessage( + "'Reusability Compliance' must be defined under 'Reusability'. Please restore your DB backup, start the previous version of SonarQube " + + "and update your SQALE model to fix this issue before trying again to run the migration."); + } + } + + @Test + public void not_fail_if_some_deprecated_requirements_still_exists_in_db() throws Exception { + db.prepareDbUnit(getClass(), "not_fail_if_some_deprecated_requirements_still_exists_in_db.xml"); + migration.execute(); + db.assertDbUnit(getClass(), "not_fail_if_some_deprecated_requirements_still_exists_in_db.xml", "characteristics"); + } + +} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/do_nothing_when_already_migrated.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/do_nothing_when_already_migrated.xml deleted file mode 100644 index b8ff37c389e..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/do_nothing_when_already_migrated.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/empty.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/empty.xml deleted file mode 100644 index 871dedcb5e9..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/empty.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_as_characteristic.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_as_characteristic.xml deleted file mode 100644 index 1f2f39bdbef..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_as_characteristic.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_under_wrong_characteristic.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_under_wrong_characteristic.xml deleted file mode 100644 index 3dbfebd4153..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_under_wrong_characteristic.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_usability_exists_as_sub_characteristic.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_usability_exists_as_sub_characteristic.xml deleted file mode 100644 index 70016cc2d9d..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_usability_exists_as_sub_characteristic.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists-result.xml deleted file mode 100644 index 4f596203e6d..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists-result.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists.xml deleted file mode 100644 index 7ab9a9726ac..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate-result.xml deleted file mode 100644 index 91f1c6ab778..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate-result.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate.xml deleted file mode 100644 index 2d92c7cc413..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/not_fail_if_some_deprecated_requirements_still_exists_in_db.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/not_fail_if_some_deprecated_requirements_still_exists_in_db.xml deleted file mode 100644 index 6953f5230bb..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/not_fail_if_some_deprecated_requirements_still_exists_in_db.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/schema.sql deleted file mode 100644 index 98c025def6b..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/schema.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE "CHARACTERISTICS" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "KEE" VARCHAR(100), - "NAME" VARCHAR(100), - "PARENT_ID" INTEGER, - "RULE_ID" INTEGER, - "CHARACTERISTIC_ORDER" INTEGER, - "ENABLED" BOOLEAN, - "CREATED_AT" TIMESTAMP, - "UPDATED_AT" TIMESTAMP -); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists-result.xml deleted file mode 100644 index 1b12df0872e..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists-result.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists.xml deleted file mode 100644 index 33d901de062..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/do_nothing_when_already_migrated.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/do_nothing_when_already_migrated.xml new file mode 100644 index 00000000000..b8ff37c389e --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/do_nothing_when_already_migrated.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/empty.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/empty.xml new file mode 100644 index 00000000000..871dedcb5e9 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/empty.xml @@ -0,0 +1,3 @@ + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/fail_if_compliance_already_exists_as_characteristic.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/fail_if_compliance_already_exists_as_characteristic.xml new file mode 100644 index 00000000000..1f2f39bdbef --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/fail_if_compliance_already_exists_as_characteristic.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/fail_if_compliance_already_exists_under_wrong_characteristic.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/fail_if_compliance_already_exists_under_wrong_characteristic.xml new file mode 100644 index 00000000000..3dbfebd4153 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/fail_if_compliance_already_exists_under_wrong_characteristic.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/fail_if_usability_exists_as_sub_characteristic.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/fail_if_usability_exists_as_sub_characteristic.xml new file mode 100644 index 00000000000..70016cc2d9d --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/fail_if_usability_exists_as_sub_characteristic.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/insert_usability_at_the_top_if_security_does_exists-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/insert_usability_at_the_top_if_security_does_exists-result.xml new file mode 100644 index 00000000000..4f596203e6d --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/insert_usability_at_the_top_if_security_does_exists-result.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/insert_usability_at_the_top_if_security_does_exists.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/insert_usability_at_the_top_if_security_does_exists.xml new file mode 100644 index 00000000000..7ab9a9726ac --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/insert_usability_at_the_top_if_security_does_exists.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/migrate-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/migrate-result.xml new file mode 100644 index 00000000000..91f1c6ab778 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/migrate-result.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/migrate.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/migrate.xml new file mode 100644 index 00000000000..2d92c7cc413 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/migrate.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/not_fail_if_some_deprecated_requirements_still_exists_in_db.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/not_fail_if_some_deprecated_requirements_still_exists_in_db.xml new file mode 100644 index 00000000000..6953f5230bb --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/not_fail_if_some_deprecated_requirements_still_exists_in_db.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/schema.sql new file mode 100644 index 00000000000..98c025def6b --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/schema.sql @@ -0,0 +1,11 @@ +CREATE TABLE "CHARACTERISTICS" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "KEE" VARCHAR(100), + "NAME" VARCHAR(100), + "PARENT_ID" INTEGER, + "RULE_ID" INTEGER, + "CHARACTERISTIC_ORDER" INTEGER, + "ENABLED" BOOLEAN, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/update_usability_if_already_exists-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/update_usability_if_already_exists-result.xml new file mode 100644 index 00000000000..1b12df0872e --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/update_usability_if_already_exists-result.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/update_usability_if_already_exists.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/update_usability_if_already_exists.xml new file mode 100644 index 00000000000..33d901de062 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest/update_usability_if_already_exists.xml @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/794_add_characteristic_usability_and_sub_characteristics_compliance.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/794_add_characteristic_usability_and_sub_characteristics_compliance.rb index 4c65c3c3864..3637819ad25 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/794_add_characteristic_usability_and_sub_characteristics_compliance.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/794_add_characteristic_usability_and_sub_characteristics_compliance.rb @@ -25,7 +25,7 @@ class AddCharacteristicUsabilityAndSubCharacteristicsCompliance < ActiveRecord::Migration def self.up - execute_java_migration 'org.sonar.server.db.migrations.v51.AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration' + execute_java_migration 'org.sonar.server.db.migrations.v51.AddNewCharacteristics' end end