]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7123 Improve size of projects name columns 765/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 4 Feb 2016 15:48:35 +0000 (16:48 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 5 Feb 2016 07:29:14 +0000 (08:29 +0100)
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1016_increase_projects_long_name_size.rb [deleted file]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1017_increase_projects_name_columns_size.rb [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
sonar-db/src/main/java/org/sonar/db/version/v54/IncreaseProjectsNameColumnsSize.java [new file with mode: 0644]
sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl
sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java
sonar-db/src/test/java/org/sonar/db/version/v54/IncreaseProjectsNameColumnsSizeTest.java [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/version/v54/IncreaseProjectsNameColumnsSizeTest/schema.sql [new file with mode: 0644]

diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1016_increase_projects_long_name_size.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1016_increase_projects_long_name_size.rb
deleted file mode 100644 (file)
index 0ac8120..0000000
+++ /dev/null
@@ -1,31 +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.
-#
-
-#
-# SonarQube 5.4
-# SONAR-7123
-#
-class IncreaseProjectsLongNameSize < ActiveRecord::Migration
-
-  def self.up
-    change_column('projects', 'long_name', :string, :limit => 2000, :null => true)
-  end
-
-end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1017_increase_projects_name_columns_size.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1017_increase_projects_name_columns_size.rb
new file mode 100644 (file)
index 0000000..6778251
--- /dev/null
@@ -0,0 +1,31 @@
+#
+# 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.4
+# SONAR-7123
+#
+class IncreaseProjectsNameColumnsSize < ActiveRecord::Migration
+
+  def self.up
+    execute_java_migration('org.sonar.db.version.v54.IncreaseProjectsNameColumnsSize')
+  end
+
+end
index dcd66d08151744475c86d0c5b3f09aacf1cac9a5..2f78c4142354097d6dd48506b3377f1c719d5dbb 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.db.MyBatis;
 
 public class DatabaseVersion {
 
-  public static final int LAST_VERSION = 1016;
+  public static final int LAST_VERSION = 1017;
 
   /**
    * The minimum supported version which can be upgraded. Lower
index fc49e280351d348829e89398e136e47f5c62853d..96e0865367ada5d0b72e30af744366172c51b3c5 100644 (file)
@@ -62,6 +62,7 @@ import org.sonar.db.version.v52.RemoveSnapshotLibraries;
 import org.sonar.db.version.v53.FixMsSqlCollation;
 import org.sonar.db.version.v53.UpdateCustomDashboardInLoadedTemplates;
 import org.sonar.db.version.v54.AddUsersIdentityColumns;
+import org.sonar.db.version.v54.IncreaseProjectsNameColumnsSize;
 import org.sonar.db.version.v54.InsertGateAdminPermissionForEachProfileAdmin;
 import org.sonar.db.version.v54.MigrateDisabledUsersToOnlyKeepLoginAndName;
 import org.sonar.db.version.v54.MigrateQualityGatesConditions;
@@ -131,7 +132,8 @@ public class MigrationStepModule extends Module {
       MigrateUsersIdentity.class,
       MigrateQualityGatesConditions.class,
       MigrateDisabledUsersToOnlyKeepLoginAndName.class,
-      RemovePreviewPermission.class
+      RemovePreviewPermission.class,
+      IncreaseProjectsNameColumnsSize.class
     );
   }
 }
diff --git a/sonar-db/src/main/java/org/sonar/db/version/v54/IncreaseProjectsNameColumnsSize.java b/sonar-db/src/main/java/org/sonar/db/version/v54/IncreaseProjectsNameColumnsSize.java
new file mode 100644 (file)
index 0000000..0cc378e
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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.v54;
+
+import java.sql.SQLException;
+import java.util.List;
+import org.sonar.db.Database;
+import org.sonar.db.version.AlterColumnsTypeBuilder;
+import org.sonar.db.version.DdlChange;
+
+import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+/**
+ * Update the following columns to the PROJECTS table :
+ * - name to 2000 characters
+ * - long_name to 2000 characters
+ */
+public class IncreaseProjectsNameColumnsSize extends DdlChange {
+
+  private final Database db;
+
+  public IncreaseProjectsNameColumnsSize(Database db) {
+    super(db);
+    this.db = db;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(generateSql());
+  }
+
+  private List<String> generateSql() {
+    return new AlterColumnsTypeBuilder(db.getDialect(), "projects")
+      .updateColumn(newVarcharColumnDefBuilder().setColumnName("name").setLimit(2000).setIsNullable(true).build())
+      .updateColumn(newVarcharColumnDefBuilder().setColumnName("long_name").setLimit(2000).setIsNullable(true).build())
+      .build();
+  }
+
+}
index 83fd226a751e169bdbcf2bcb3e52290acda85085..1b93040984ae9fdca0845ed115f2989853340582 100644 (file)
@@ -376,7 +376,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1012');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1013');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1014');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1015');
-INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1016');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1017');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index df7f25dd860a4939709bbbb344a7a61d020f8148..d4fb90a114e4f9f458f454ccf98378e61407f30b 100644 (file)
@@ -245,7 +245,7 @@ CREATE TABLE "PROJECTS" (
   "PROJECT_UUID" VARCHAR(50),
   "MODULE_UUID" VARCHAR(50),
   "MODULE_UUID_PATH" VARCHAR(4000),
-  "NAME" VARCHAR(256),
+  "NAME" VARCHAR(2000),
   "DESCRIPTION" VARCHAR(2000),
   "ENABLED" BOOLEAN NOT NULL DEFAULT TRUE,
   "SCOPE" VARCHAR(3),
index 0378848ad8538bcb9157ce2d0ff2938b7be63f6d..c766bebda7dc6a409e99abb383857783482f52c6 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(50);
+    assertThat(container.size()).isEqualTo(51);
   }
 }
diff --git a/sonar-db/src/test/java/org/sonar/db/version/v54/IncreaseProjectsNameColumnsSizeTest.java b/sonar-db/src/test/java/org/sonar/db/version/v54/IncreaseProjectsNameColumnsSizeTest.java
new file mode 100644 (file)
index 0000000..0f3d428
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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.v54;
+
+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;
+
+import static java.sql.Types.VARCHAR;
+
+public class IncreaseProjectsNameColumnsSizeTest {
+
+  @Rule
+  public DbTester db = DbTester.createForSchema(System2.INSTANCE, IncreaseProjectsNameColumnsSizeTest.class, "schema.sql");
+
+  MigrationStep migration;
+
+  @Before
+  public void setUp() {
+    migration = new IncreaseProjectsNameColumnsSize(db.database());
+  }
+
+  @Test
+  public void update_columns() throws Exception {
+    migration.execute();
+
+    db.assertColumnDefinition("projects", "long_name", VARCHAR, 2000);
+    db.assertColumnDefinition("projects", "name", VARCHAR, 2000);
+  }
+
+}
diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v54/IncreaseProjectsNameColumnsSizeTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/version/v54/IncreaseProjectsNameColumnsSizeTest/schema.sql
new file mode 100644 (file)
index 0000000..b7307a0
--- /dev/null
@@ -0,0 +1,22 @@
+CREATE TABLE "PROJECTS" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "KEE" VARCHAR(400),
+  "ROOT_ID" INTEGER,
+  "UUID" VARCHAR(50),
+  "PROJECT_UUID" VARCHAR(50),
+  "MODULE_UUID" VARCHAR(50),
+  "MODULE_UUID_PATH" VARCHAR(4000),
+  "NAME" VARCHAR(256),
+  "DESCRIPTION" VARCHAR(2000),
+  "ENABLED" BOOLEAN NOT NULL DEFAULT TRUE,
+  "SCOPE" VARCHAR(3),
+  "QUALIFIER" VARCHAR(10),
+  "DEPRECATED_KEE" VARCHAR(400),
+  "PATH" VARCHAR(2000),
+  "LANGUAGE" VARCHAR(20),
+  "COPY_RESOURCE_ID" INTEGER,
+  "LONG_NAME" VARCHAR(256),
+  "PERSON_ID" INTEGER,
+  "CREATED_AT" TIMESTAMP,
+  "AUTHORIZATION_UPDATED_AT" BIGINT
+);