]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11650 Drop DATA_TYPE column from FILE_SOURCES table
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 13 Feb 2019 09:23:45 +0000 (10:23 +0100)
committerSonarTech <sonartech@sonarsource.com>
Wed, 13 Feb 2019 19:20:54 +0000 (20:20 +0100)
server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSources.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSourcesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSourcesTest/file_sources.sql [new file with mode: 0644]

index cea2a5ea5e6a9f6480cad75daef76996798e8662..785fc278f5c1a18fd225b39136ed5a841c2bcb75 100644 (file)
@@ -675,7 +675,6 @@ CREATE TABLE "FILE_SOURCES" (
   "LINE_HASHES_VERSION" INTEGER,
   "LINE_COUNT" INTEGER NOT NULL,
   "BINARY_DATA" BLOB,
-  "DATA_TYPE" VARCHAR(20),
   "DATA_HASH" VARCHAR(50),
   "SRC_HASH" VARCHAR(50),
   "REVISION" VARCHAR(100),
@@ -683,7 +682,7 @@ CREATE TABLE "FILE_SOURCES" (
   "UPDATED_AT" BIGINT NOT NULL
 );
 CREATE INDEX "FILE_SOURCES_PROJECT_UUID" ON "FILE_SOURCES" ("PROJECT_UUID");
-CREATE UNIQUE INDEX "FILE_SOURCES_UUID_TYPE" ON "FILE_SOURCES" ("FILE_UUID", "DATA_TYPE");
+CREATE UNIQUE INDEX "FILE_SOURCES_FILE_UUID" ON "FILE_SOURCES" ("FILE_UUID");
 CREATE INDEX "FILE_SOURCES_UPDATED_AT" ON "FILE_SOURCES" ("UPDATED_AT");
 
 
index d1bb68348cee271905b13591d7dcc2006fbc6a43..aa7c48e35d6ec6dc72d60e85a5d22931fd70aff7 100644 (file)
@@ -33,7 +33,6 @@ public class DbVersion77 implements DbVersion {
       .add(2603, "Add column LAST_USED_DATE to USER_TOKENS table", AddLastConnectionDateToUserTokens.class)
       .add(2604, "Add baseline columns in PROJECT_BRANCHES", AddManualBaselineToProjectBranches.class)
       .add(2605, "Add SNAPSHOTS.PROJECT_VERSION", AddProjectVersionToSnapshot.class)
-
-    ;
+      .add(2606, "Drop DATA_TYPE column from FILE_SOURCES table", DropDataTypeFromFileSources.class);
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSources.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSources.java
new file mode 100644 (file)
index 0000000..8e87f66
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.v77;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.SupportsBlueGreen;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+@SupportsBlueGreen
+public class DropDataTypeFromFileSources extends DdlChange {
+
+  private static final String TABLE_NAME = "file_sources";
+
+  public DropDataTypeFromFileSources(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new DropIndexBuilder(getDialect())
+      .setTable(TABLE_NAME)
+      .setName("file_sources_uuid_type")
+      .build());
+
+    context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, "data_type")
+      .build());
+
+    context.execute(new CreateIndexBuilder(getDialect())
+      .setTable(TABLE_NAME)
+      .setName("file_sources_file_uuid")
+      .setUnique(true)
+      .addColumn(newVarcharColumnDefBuilder()
+        .setColumnName("file_uuid")
+        .setIsNullable(false)
+        .setLimit(50)
+        .build())
+      .build());
+  }
+
+}
index 9768054845e684380fb4468e25c87d8e6ecd99bc..559d2bc0ae8d3b8bb3b47c5ed95b2dd23cf52793 100644 (file)
@@ -36,7 +36,7 @@ public class DbVersion77Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 6);
+    verifyMigrationCount(underTest, 7);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSourcesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSourcesTest.java
new file mode 100644 (file)
index 0000000..f69e374
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.v77;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+public class DropDataTypeFromFileSourcesTest {
+
+  private static final String TABLE = "file_sources";
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(DropDataTypeFromFileSourcesTest.class, "file_sources.sql");
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private DropDataTypeFromFileSources underTest = new DropDataTypeFromFileSources(db.database());
+
+  @Test
+  public void drop_column_and_recreate_index() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDoesNotExist(TABLE, "data_type");
+    db.assertUniqueIndex(TABLE, "file_sources_file_uuid", "file_uuid");
+  }
+
+  @Test
+  public void migration_is_not_re_entrant() throws SQLException {
+    underTest.execute();
+
+    expectedException.expect(IllegalStateException.class);
+
+    underTest.execute();
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSourcesTest/file_sources.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSourcesTest/file_sources.sql
new file mode 100644 (file)
index 0000000..9a93cbc
--- /dev/null
@@ -0,0 +1,18 @@
+CREATE TABLE "FILE_SOURCES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "PROJECT_UUID" VARCHAR(50) NOT NULL,
+  "FILE_UUID" VARCHAR(50) NOT NULL,
+  "LINE_HASHES" CLOB,
+  "LINE_HASHES_VERSION" INTEGER,
+  "LINE_COUNT" INTEGER NOT NULL,
+  "BINARY_DATA" BLOB,
+  "DATA_TYPE" VARCHAR(20),
+  "DATA_HASH" VARCHAR(50),
+  "SRC_HASH" VARCHAR(50),
+  "REVISION" VARCHAR(100),
+  "CREATED_AT" BIGINT NOT NULL,
+  "UPDATED_AT" BIGINT NOT NULL
+);
+CREATE INDEX "FILE_SOURCES_PROJECT_UUID" ON "FILE_SOURCES" ("PROJECT_UUID");
+CREATE UNIQUE INDEX "FILE_SOURCES_UUID_TYPE" ON "FILE_SOURCES" ("FILE_UUID", "DATA_TYPE");
+CREATE INDEX "FILE_SOURCES_UPDATED_AT" ON "FILE_SOURCES" ("UPDATED_AT");
\ No newline at end of file