]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7988 support migrations on old table activities
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 16 Sep 2016 14:15:02 +0000 (16:15 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 16 Sep 2016 14:15:02 +0000 (16:15 +0200)
server/sonar-server/src/main/java/org/sonar/server/platform/db/CheckDatabaseCharsetAtStartup.java
sonar-db/src/main/java/org/sonar/db/charset/ColumnDef.java
sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
sonar-db/src/test/java/org/sonar/db/charset/ColumnDefTest.java

index 9d61afdd0bcb6d0d8400bfa2b579ca032e8e0410..28260499183de98b417fbb9d9a6863be804f4479 100644 (file)
@@ -39,6 +39,7 @@ public class CheckDatabaseCharsetAtStartup implements Startable {
 
   @Override
   public void start() {
+    System.out.println("xxxxxxxxxxx");
     DatabaseCharsetChecker.State state = DatabaseCharsetChecker.State.STARTUP;
     if (upgradeStatus.isUpgraded()) {
       state = DatabaseCharsetChecker.State.UPGRADE;
index 02213499e7f6e2cf77f7bee9cdff088723cb8613..c2c20f176bfbb1a66bd7c7ca7f7130ac38931e51 100644 (file)
@@ -80,7 +80,8 @@ public class ColumnDef {
   }
 
   public boolean isInSonarQubeTable() {
-    return DatabaseVersion.TABLES.contains(table.toLowerCase(Locale.ENGLISH));
+    String tableName = table.toLowerCase(Locale.ENGLISH);
+    return DatabaseVersion.TABLES.contains(tableName) || DatabaseVersion.OLD_DROPPED_TABLES.contains(tableName);
   }
 
   public enum ColumnDefRowConverter implements SqlExecutor.RowConverter<ColumnDef> {
index fa67f02ad38c8b7c49134a8d8a450425dcce70de..9e7d9076e02fa7e09c1ff6b1909c16ae25b99a0c 100644 (file)
@@ -39,6 +39,17 @@ public class DatabaseVersion {
    */
   public static final int MIN_UPGRADE_VERSION = 1152;
 
+  /**
+   * These tables are still involved in DB migrations, so potentially
+   * incorrect collation must be fixed so that joins with other
+   * tables are possible.
+   *
+   * @see org.sonar.db.charset.ColumnDef#isInSonarQubeTable() 
+   */
+  public static final Set<String> OLD_DROPPED_TABLES = ImmutableSet.of(
+    "activities"
+  );
+
   /**
    * List of all the tables.
    * This list is hardcoded because we didn't succeed in using java.sql.DatabaseMetaData#getTables() in the same way
@@ -95,6 +106,7 @@ public class DatabaseVersion {
     "user_tokens",
     "widgets",
     "widget_properties");
+
   private MyBatis mybatis;
 
   public DatabaseVersion(MyBatis mybatis) {
index 8a718e18b6215ddb2f657da840eb4c33d76ac8c3..55b02e0ea1e04da9a8ef6a970200041f17cdcf2e 100644 (file)
@@ -27,19 +27,25 @@ public class ColumnDefTest {
 
   @Test
   public void isInSonarQubeTable_returns_false_if_sqlazure_system_table() {
-    ColumnDef underTest = new ColumnDef("sys.sysusers", "colum", "charset", "collation", "NVARCHAR", 100L, false);
+    ColumnDef underTest = new ColumnDef("sys.sysusers", "login", "charset", "collation", "NVARCHAR", 100L, false);
     assertThat(underTest.isInSonarQubeTable()).isFalse();
 
-    underTest = new ColumnDef("SYS.SYSUSERS", "colum", "charset", "collation", "NVARCHAR", 100L, false);
+    underTest = new ColumnDef("SYS.SYSUSERS", "login", "charset", "collation", "NVARCHAR", 100L, false);
     assertThat(underTest.isInSonarQubeTable()).isFalse();
   }
 
   @Test
   public void isInSonarQubeTable_returns_true_if_table_created_by_sonarqube() {
-    ColumnDef underTest = new ColumnDef("project_measures", "column", "charset", "collation", "NVARCHAR", 100L, false);
+    ColumnDef underTest = new ColumnDef("project_measures", "text_value", "charset", "collation", "NVARCHAR", 100L, false);
     assertThat(underTest.isInSonarQubeTable()).isTrue();
 
-    underTest = new ColumnDef("PROJECT_MEASURES", "column", "charset", "collation", "NVARCHAR", 100L, false);
+    underTest = new ColumnDef("PROJECT_MEASURES", "text_value", "charset", "collation", "NVARCHAR", 100L, false);
+    assertThat(underTest.isInSonarQubeTable()).isTrue();
+  }
+
+  @Test
+  public void isInSonarQubeTable_returns_true_if_table_existed_in_previous_versions_of_sonarqube() {
+    ColumnDef underTest = new ColumnDef("activities", "kee", "charset", "collation", "NVARCHAR", 100L, false);
     assertThat(underTest.isInSonarQubeTable()).isTrue();
   }
 }