]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10110 Remove LOADED_TEMPLATES table
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 27 Nov 2017 10:53:55 +0000 (11:53 +0100)
committerEric Hartmann <hartmann.eric@gmail.Com>
Mon, 4 Dec 2017 12:44:55 +0000 (13:44 +0100)
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DropLoadedTemplatesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DropLoadedTemplatesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/DropLoadedTemplatesTableTest/loaded_templates.sql [new file with mode: 0644]

index 7d8198577c5d073d0cac06ffbe54812bccaea359..f03ca93038b95a6c237fc9069c2880866eb4c616 100644 (file)
@@ -32,7 +32,7 @@ public class DbVersion70 implements DbVersion {
       .add(1902, "Make QUALITY_GATES.IS_BUILT_IN not null", MakeQualityGatesIsBuiltInNotNullable.class)
       .add(1903, "Remove quality gates loaded templates", RemoveQualityGateLoadedTemplates.class)
       .add(1904, "Rename quality gate \"SonarQube way\" to \"Sonar way\"", RenameOldSonarQubeWayQualityGate.class)
-    ;
+      .add(1905, "Drop LOADED_TEMPLATES table", DropLoadedTemplatesTable.class);
   }
 
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DropLoadedTemplatesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DropLoadedTemplatesTable.java
new file mode 100644 (file)
index 0000000..765d5bb
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.v70;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.DropTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropLoadedTemplatesTable extends DdlChange {
+
+  private static final String LOADED_TEMPLATES = "loaded_templates";
+  private final Database db;
+
+  public DropLoadedTemplatesTable(Database db) {
+    super(db);
+    this.db = db;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    if (tableExists()) {
+      context.execute(new DropTableBuilder(db.getDialect(), LOADED_TEMPLATES).build());
+    }
+  }
+
+  private boolean tableExists() throws SQLException {
+    try (Connection connection = db.getDataSource().getConnection()) {
+      return DatabaseUtils.tableExists(LOADED_TEMPLATES, connection);
+    }
+  }
+}
index 7a3313ef31d40fe1ebeb2364f6b85b14e3e423bc..ece11091b41b69920002c29abee707b30a605c87 100644 (file)
@@ -35,7 +35,7 @@ public class DbVersion70Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 5);
+    verifyMigrationCount(underTest, 6);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DropLoadedTemplatesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DropLoadedTemplatesTableTest.java
new file mode 100644 (file)
index 0000000..a3fa405
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.v70;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class DropLoadedTemplatesTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropLoadedTemplatesTableTest.class, "loaded_templates.sql");
+
+  private DropLoadedTemplatesTable underTest = new DropLoadedTemplatesTable(db.database());
+
+  @Test
+  public void delete_tables() throws SQLException {
+    underTest.execute();
+
+    db.assertTableDoesNotExist("loaded_templates");
+  }
+
+  @Test
+  public void migration_is_re_entrant() throws Exception {
+    underTest.execute();
+    underTest.execute();
+
+    db.assertTableDoesNotExist("loaded_templates");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/DropLoadedTemplatesTableTest/loaded_templates.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/DropLoadedTemplatesTableTest/loaded_templates.sql
new file mode 100644 (file)
index 0000000..d3c72d4
--- /dev/null
@@ -0,0 +1,6 @@
+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(64) NOT NULL
+);
+CREATE INDEX "IX_LOADED_TEMPLATES_TYPE" ON "LOADED_TEMPLATES" ("TEMPLATE_TYPE");