]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8025 rewrite create table CE_TASK_INPUT in java
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 13 Sep 2016 09:47:43 +0000 (11:47 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 16 Sep 2016 10:22:12 +0000 (12:22 +0200)
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1302_create_table_ce_task_input.rb
sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
sonar-db/src/main/java/org/sonar/db/version/VarcharColumnDef.java
sonar-db/src/main/java/org/sonar/db/version/v61/CreateTableCeTaskInput.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java
sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableCeTaskInputTest.java [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableCeTaskInputTest/empty.sql [new file with mode: 0644]

index 2beae9f27d81fa6bcb73cdc54b2108c20c079b23..a39d3026b82360545cd5a95f39720eb45f0cdc21 100644 (file)
 class CreateTableCeTaskInput < ActiveRecord::Migration
 
   def self.up
-    create_table 'ce_task_input', :id => false do |t|
-      t.column 'task_uuid', :string, :limit => 40, :null => false
-      t.column 'data', :binary, :null => true
-      t.column 'created_at', :big_integer, :null => false
-      t.column 'updated_at', :big_integer, :null => false
-    end
-    add_primary_key 'ce_task_input', 'task_uuid'
+    execute_java_migration('org.sonar.db.version.v61.CreateTableCeTaskInput')
   end
 end
index 3d97895f8ac8a52b8266934a9ecc2f852e10fe16..85bf57f64c14cefdbf5f3b22623d51c934e2bcb9 100644 (file)
@@ -147,6 +147,7 @@ import org.sonar.db.version.v60.RemoveUsersPasswordWhenNotLocal;
 import org.sonar.db.version.v61.AddBUuidPathToProjects;
 import org.sonar.db.version.v61.AddErrorColumnsToCeActivity;
 import org.sonar.db.version.v61.CopyActivitiesToQprofileChanges;
+import org.sonar.db.version.v61.CreateTableCeTaskInput;
 import org.sonar.db.version.v61.DeleteProjectDashboards;
 import org.sonar.db.version.v61.DeleteReportsFromCeQueue;
 import org.sonar.db.version.v61.DropIsGlobalFromDashboards;
@@ -318,13 +319,13 @@ public class MigrationStepModule extends Module {
       // 6.1
       DeleteProjectDashboards.class,
       DropIsGlobalFromDashboards.class,
+      CreateTableCeTaskInput.class,
       DeleteReportsFromCeQueue.class,
       ShrinkModuleUuidPathOfProjects.class,
       AddBUuidPathToProjects.class,
       AddErrorColumnsToCeActivity.class,
       PopulateTableProperties2.class,
       RemoveViewsDefinitionFromProperties.class,
-      CopyActivitiesToQprofileChanges.class
-      );
+      CopyActivitiesToQprofileChanges.class);
   }
 }
index 0983a4145a0cb3f8186f78b6f7b5fe7a025b6887..d8da72a48478ac103cf2305f9cec0d8a8a93b9f7 100644 (file)
@@ -32,7 +32,12 @@ import static org.sonar.db.version.ColumnDefValidation.validateColumnName;
  */
 public class VarcharColumnDef extends AbstractColumnDef {
   public static final int MAX_SIZE = 4_000;
+  /**
+   * @deprecated use {@link #UUID_SIZE} instead
+   */
+  @Deprecated
   public static final int UUID_VARCHAR_SIZE = 50;
+  public static final int UUID_SIZE = 40;
 
   private final int columnSize;
 
diff --git a/sonar-db/src/main/java/org/sonar/db/version/v61/CreateTableCeTaskInput.java b/sonar-db/src/main/java/org/sonar/db/version/v61/CreateTableCeTaskInput.java
new file mode 100644 (file)
index 0000000..fc4d3ec
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.db.version.v61;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.version.CreateTableBuilder;
+import org.sonar.db.version.DdlChange;
+
+import static org.sonar.db.version.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
+import static org.sonar.db.version.BlobColumnDef.newBlobColumnDefBuilder;
+import static org.sonar.db.version.VarcharColumnDef.UUID_SIZE;
+import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class CreateTableCeTaskInput extends DdlChange {
+  public CreateTableCeTaskInput(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(
+      new CreateTableBuilder(getDialect(), "ce_task_input")
+        .addPkColumn(newVarcharColumnDefBuilder().setColumnName("task_uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
+        .addColumn(newBlobColumnDefBuilder().setColumnName("data").setIsNullable(true).build())
+        .addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
+        .addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").setIsNullable(false).build())
+        .build());
+  }
+}
index d1dfd506a7212a005392dd6ee1cb414b2953e98f..e03d3eafbfe4d487b5ca921210c531dac8ffd837 100644 (file)
@@ -29,6 +29,6 @@ public class MigrationStepModuleTest {
   public void verify_count_of_added_MigrationStep_types() {
     ComponentContainer container = new ComponentContainer();
     new MigrationStepModule().configure(container);
-    assertThat(container.size()).isEqualTo(135);
+    assertThat(container.size()).isEqualTo(136);
   }
 }
diff --git a/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableCeTaskInputTest.java b/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableCeTaskInputTest.java
new file mode 100644 (file)
index 0000000..ff4d366
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.db.version.v61;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class CreateTableCeTaskInputTest {
+  private static final String TABLE_CE_TASK_INPUT = "ce_task_input";
+
+  @Rule
+  public final DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, CreateTableCeTaskInputTest.class, "empty.sql");
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private CreateTableCeTaskInput underTest = new CreateTableCeTaskInput(dbTester.database());
+
+  @Test
+  public void creates_table_on_empty_db() throws SQLException {
+    underTest.execute();
+
+    assertThat(dbTester.countRowsOfTable(TABLE_CE_TASK_INPUT)).isEqualTo(0);
+
+    dbTester.assertColumnDefinition(TABLE_CE_TASK_INPUT, "task_uuid", Types.VARCHAR, 40, false);
+    dbTester.assertColumnDefinition(TABLE_CE_TASK_INPUT, "data", Types.BLOB, null, true);
+    dbTester.assertColumnDefinition(TABLE_CE_TASK_INPUT, "created_at", Types.BIGINT, null, false);
+    dbTester.assertColumnDefinition(TABLE_CE_TASK_INPUT, "updated_at", Types.BIGINT, null, false);
+    dbTester.assertPrimaryKey(TABLE_CE_TASK_INPUT, "pk_" + TABLE_CE_TASK_INPUT, "task_uuid");
+  }
+
+  @Test
+  public void migration_is_not_reentrant() throws SQLException {
+    underTest.execute();
+
+    expectedException.expect(IllegalStateException.class);
+
+    underTest.execute();
+  }
+}
diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableCeTaskInputTest/empty.sql b/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableCeTaskInputTest/empty.sql
new file mode 100644 (file)
index 0000000..e69de29