]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11823 Drop snapshots.project_version
authorJanos Gyerik <janos.gyerik@sonarsource.com>
Mon, 18 Mar 2019 13:29:36 +0000 (14:29 +0100)
committerSonarTech <sonartech@sonarsource.com>
Tue, 19 Mar 2019 19:21:27 +0000 (20:21 +0100)
19 files changed:
server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingAnalysis.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldPurgeProject-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldPurgeProject.xml
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/DropProjectVersionFromSnapshots.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/DropProjectVersionFromSnapshotsTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v77/DropProjectVersionFromSnapshotsTest/snapshots.sql [new file with mode: 0644]

index 80c4b377e4db8ecba68773c86512c22fd35c8adb..aa57ac9a70d31dd0c234a50dfcb5a87001599e23 100644 (file)
@@ -142,7 +142,6 @@ CREATE TABLE "SNAPSHOTS" (
   "PURGE_STATUS" INTEGER,
   "ISLAST" BOOLEAN NOT NULL DEFAULT FALSE,
   "VERSION" VARCHAR(500),
-  "PROJECT_VERSION" VARCHAR(100),
   "BUILD_STRING" VARCHAR(100),
   "PERIOD1_MODE" VARCHAR(100),
   "PERIOD1_PARAM" VARCHAR(100),
index af7588f557ed3fa245cc6647c78f7937255b549b..3660be0b472c3962ed5282817872968d1496033e 100644 (file)
@@ -42,7 +42,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
   <analysis_properties uuid="u1"
index 8bee951c35bb049c8db4f70a9eeaf00e99df083d..f4227cf96caa04b3ce31bc8e348333069b384e64 100644 (file)
@@ -52,7 +52,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
   <!-- do not delete standard measure -->
index e9e512f02d24da81928ff6c5cf2bfd3229ad1698..b61837e660b478135bace5c1158c53e618f83a6d 100644 (file)
@@ -32,7 +32,6 @@ Note that measures, events and reviews are not deleted.
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
              build_string="[null]"
   />
   <analysis_properties uuid="u1"
@@ -106,7 +105,7 @@ Note that measures, events and reviews are not deleted.
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
   <analysis_properties uuid="u2"
index b6b9c78349fde6867721645525705de8aad84ec0..44d70d4f14fc1c906d955e1b9372349db838c067 100644 (file)
@@ -24,7 +24,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
   <analysis_properties uuid="u1"
@@ -98,7 +98,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
   <analysis_properties uuid="u2"
index c70adbbf8369f89753463ef0196698b2d3dfcc25..9d3afbaa2257c229b98de9b55b6aab4d874c78ea 100644 (file)
@@ -50,7 +50,6 @@ Snapshot 2 has been deleted
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
              build_string="[null]"
   />
 
@@ -79,7 +78,7 @@ Snapshot 2 has been deleted
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
 </dataset>
index 99b17569baec1943c1995e8881a5cbd338302f17..bd9d1ecdbd87a3e35e0bce17570f5084ec20edbd 100644 (file)
@@ -45,7 +45,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
   <!-- snapshot with status "unprocessed" -> to be deleted -->
@@ -73,7 +73,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
   <!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete -->
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
 </dataset>
index 16a0bab013ec265e35b4ce09c819b02349f5accb..aa7d13e08f5f51c1ad7f9db0ebcc2437cf75c125 100644 (file)
@@ -25,7 +25,6 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
              build_string="[null]"
   />
 
@@ -54,7 +53,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
 </dataset>
index 7aa4af52e0cf16c9ac02a01a8b89fa9ba5015dfc..51673c1b529f106e2f6ea520b9b519ce1010ba3a 100644 (file)
@@ -25,7 +25,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
   <!-- delete only resource 1 -->
@@ -53,7 +53,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
   <!-- to be deleted -->
@@ -81,7 +81,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
 </dataset>
index 39fe34d21c789c4d89e04b9b6601a48ed700df4e..cbfd274de16b0f8c76560fd1d00e4ac81c5e9c31 100644 (file)
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
              build_string="[null]"
   />
 
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
   <project_measures id="5"
index 67c496411aa77ebe56529b1b825c26a7a1a0ea41..8f08b4a5f5d8b56dd3a5d60230557007463d6240 100644 (file)
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
   <project_measures id="1"
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
   <project_measures id="5"
index 7cff4413e5e25325d5084818cad02f6ebd5e4102..78f130d8df31b35f6ace979398f71926df3927bb 100644 (file)
@@ -58,7 +58,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
   <issues id="1"
index 7f10558d0a9ef055bec153b52a0c2970d842494d..3d7fd311f93823daca224d182de4b79714d30149 100644 (file)
@@ -66,7 +66,6 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
              build_string="[null]"
   />
 
@@ -96,7 +95,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
   <!-- snapshot to be purged -->
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
 </dataset>
index 7362c125b54c26dc9a47c47120c7f005d2bcfb46..f63f25501cf06cca184562eb70d298d4d1c00892 100644 (file)
@@ -65,7 +65,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
 
@@ -94,7 +94,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
   <!-- snapshot to be purged -->
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
-             project_version="[null]"
+             build_string="[null]"
   />
 
 </dataset>
index c12afef8e3b3f73ef3445e6252ba52b2c7c43f4c..4c31fe89a78cd3bb6219546cc78de4059097b405 100644 (file)
@@ -39,6 +39,8 @@ public class DbVersion77 implements DbVersion {
       .add(2609, "Delete exceeding favorites when there are more than 100 for a user", DeleteFavoritesExceedingOneHundred.class)
       .add(2610, "Truncate ES_QUEUE table content", TruncateEsQueue.class)
       .add(2611, "Add SNAPSHOTS.BUILD_STRING", AddBuildStringToSnapshot.class)
+      // FIXME after deployment on SonarCloud, drop this and "Add SNAPSHOTS.PROJECT_VERSION" above as they cancel out each other
+      .add(2612, "Drop SNAPSHOTS.PROJECT_VERSION", DropProjectVersionFromSnapshots.class)
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DropProjectVersionFromSnapshots.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DropProjectVersionFromSnapshots.java
new file mode 100644 (file)
index 0000000..ff55ba4
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.sql.DropColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropProjectVersionFromSnapshots extends DdlChange {
+
+  private static final String TABLE_NAME = "snapshots";
+
+  public DropProjectVersionFromSnapshots(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, "project_version")
+      .build());
+  }
+}
index 802d22d59a398a9dac56b9f91d75b543786e421d..c3245e62a98e6f1e98a34181fd7d5fa34cb8436b 100644 (file)
@@ -36,7 +36,7 @@ public class DbVersion77Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 12);
+    verifyMigrationCount(underTest, 13);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DropProjectVersionFromSnapshotsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DropProjectVersionFromSnapshotsTest.java
new file mode 100644 (file)
index 0000000..e4787ad
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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 DropProjectVersionFromSnapshotsTest {
+
+  private static final String TABLE = "snapshots";
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(DropProjectVersionFromSnapshotsTest.class, "snapshots.sql");
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private DropProjectVersionFromSnapshots underTest = new DropProjectVersionFromSnapshots(db.database());
+
+  @Test
+  public void drop_column_and_recreate_index() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDoesNotExist(TABLE, "project_version");
+  }
+
+  @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/DropProjectVersionFromSnapshotsTest/snapshots.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v77/DropProjectVersionFromSnapshotsTest/snapshots.sql
new file mode 100644 (file)
index 0000000..8d668ab
--- /dev/null
@@ -0,0 +1,30 @@
+CREATE TABLE "SNAPSHOTS" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "UUID" VARCHAR(50) NOT NULL,
+  "CREATED_AT" BIGINT,
+  "BUILD_DATE" BIGINT,
+  "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+  "STATUS" VARCHAR(4) NOT NULL DEFAULT 'U',
+  "PURGE_STATUS" INTEGER,
+  "ISLAST" BOOLEAN NOT NULL DEFAULT FALSE,
+  "VERSION" VARCHAR(500),
+  "PROJECT_VERSION" VARCHAR(100),
+  "BUILD_STRING" VARCHAR(100),
+  "PERIOD1_MODE" VARCHAR(100),
+  "PERIOD1_PARAM" VARCHAR(100),
+  "PERIOD1_DATE" BIGINT,
+  "PERIOD2_MODE" VARCHAR(100),
+  "PERIOD2_PARAM" VARCHAR(100),
+  "PERIOD2_DATE" BIGINT,
+  "PERIOD3_MODE" VARCHAR(100),
+  "PERIOD3_PARAM" VARCHAR(100),
+  "PERIOD3_DATE" BIGINT,
+  "PERIOD4_MODE" VARCHAR(100),
+  "PERIOD4_PARAM" VARCHAR(100),
+  "PERIOD4_DATE" BIGINT,
+  "PERIOD5_MODE" VARCHAR(100),
+  "PERIOD5_PARAM" VARCHAR(100),
+  "PERIOD5_DATE" BIGINT
+);
+CREATE INDEX "SNAPSHOT_COMPONENT" ON "SNAPSHOTS" ("COMPONENT_UUID");
+CREATE UNIQUE INDEX "ANALYSES_UUID" ON "SNAPSHOTS" ("UUID");