In order to not have 2 default dashboards 'Custom', the entry in LOADED_TEMPLATES is renamed from the old name 'Dashboard' to the new one 'Custom'
--- /dev/null
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+#
+# SonarQube 5.3
+# SONAR-7030
+#
+class UpdateCustomDashboardInLoadedTemplates < ActiveRecord::Migration
+
+ def self.up
+ execute_java_migration('org.sonar.db.version.v53.UpdateCustomDashboardInLoadedTemplates')
+ end
+
+end
+
+
public class DatabaseVersion {
- public static final int LAST_VERSION = 1005;
+ public static final int LAST_VERSION = 1006;
/**
* The minimum supported version which can be upgraded. Lower
import org.sonar.db.version.v52.RemoveRuleMeasuresOnIssues;
import org.sonar.db.version.v52.RemoveSnapshotLibraries;
import org.sonar.db.version.v53.FixMsSqlCollation;
+import org.sonar.db.version.v53.UpdateCustomDashboardInLoadedTemplates;
public class MigrationStepModule extends Module {
@Override
RemoveRuleMeasuresOnIssues.class,
// 5.3
- FixMsSqlCollation.class);
+ FixMsSqlCollation.class,
+ UpdateCustomDashboardInLoadedTemplates.class
+ );
}
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.version.v53;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.version.BaseDataChange;
+import org.sonar.db.version.MassUpdate;
+import org.sonar.db.version.Select;
+import org.sonar.db.version.SqlStatement;
+
+/**
+ * As the default dashboard 'Dashboard' has been renamed to 'Custom', the corresponding entry in LOADED_TEMPLATES is updated,
+ * in order to not have this dashboard twice.
+ */
+public class UpdateCustomDashboardInLoadedTemplates extends BaseDataChange {
+
+ public UpdateCustomDashboardInLoadedTemplates(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ MassUpdate update = context.prepareMassUpdate().rowPluralName("loaded templates");
+ update.select("SELECT l.id FROM loaded_templates l WHERE l.kee='Dashboard' and l.template_type='DASHBOARD'");
+ update.update("UPDATE loaded_templates SET kee=? WHERE id=?");
+ update.execute(MigrationHandler.INSTANCE);
+ }
+
+ private enum MigrationHandler implements MassUpdate.Handler {
+ INSTANCE;
+
+ @Override
+ public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+ update.setString(1, "Custom");
+ update.setLong(2, row.getLong(1));
+ return true;
+ }
+ }
+}
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1003');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1004');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1005');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1006');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null);
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
public void verify_count_of_added_MigrationStep_types() {
ComponentContainer container = new ComponentContainer();
new MigrationStepModule().configure(container);
- assertThat(container.size()).isEqualTo(42);
+ assertThat(container.size()).isEqualTo(43);
}
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.version.v53;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+import org.sonar.db.version.MigrationStep;
+
+public class UpdateCustomDashboardInLoadedTemplatesTest {
+
+ static final String TABLE = "loaded_templates";
+
+ @Rule
+ public DbTester db = DbTester.createForSchema(System2.INSTANCE, UpdateCustomDashboardInLoadedTemplatesTest.class, "schema.sql");
+
+ MigrationStep migration;
+
+ @Before
+ public void setUp() {
+ db.executeUpdateSql("truncate table " + TABLE);
+
+ migration = new UpdateCustomDashboardInLoadedTemplates(db.database());
+ }
+
+ @Test
+ public void migrate_empty_db() throws Exception {
+ migration.execute();
+ }
+
+ @Test
+ public void migrate() throws Exception {
+ db.prepareDbUnit(this.getClass(), "migrate.xml");
+ migration.execute();
+ db.assertDbUnit(this.getClass(), "migrate-result.xml", TABLE);
+ }
+
+ @Test
+ public void not_migrate_already_migrated_data() throws Exception {
+ db.prepareDbUnit(this.getClass(), "not_migrate_already_migrated_data.xml");
+ migration.execute();
+ db.assertDbUnit(this.getClass(), "not_migrate_already_migrated_data.xml", TABLE);
+ }
+
+}
--- /dev/null
+<dataset>
+
+ <loaded_templates id="1" kee="Custom" template_type="DASHBOARD"/>
+
+ <loaded_templates id="2" kee="Dashboard" template_type="QUALITY_PROFILE"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <!-- The kee should be updated to 'Custom' -->
+ <loaded_templates id="1" kee="Dashboard" template_type="DASHBOARD"/>
+
+ <!-- Nothing should be done as it's not a dashboard -->
+ <loaded_templates id="2" kee="Dashboard" template_type="QUALITY_PROFILE"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <loaded_templates id="1" kee="Custom" template_type="DASHBOARD"/>
+
+ <loaded_templates id="2" kee="Dashboard" template_type="QUALITY_PROFILE"/>
+
+</dataset>
--- /dev/null
+CREATE TABLE "LOADED_TEMPLATES" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "KEE" VARCHAR(200),
+ "TEMPLATE_TYPE" VARCHAR(15)
+);