]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11950 create DB column snapshots.revision
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 6 May 2019 14:38:40 +0000 (16:38 +0200)
committerSonarTech <sonartech@sonarsource.com>
Wed, 22 May 2019 18:21:16 +0000 (20:21 +0200)
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/shouldPurgeAnalysis-result.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/shouldDeleteAnalyses-result.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/shouldPurgeProject-result.xml
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v78/AddSnapshotRevision.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v78/DbVersion78.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v78/AddSnapshotRevisionTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v78/DbVersion78Test.java
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v78/AddSnapshotRevisionTest/snapshots.sql [new file with mode: 0644]

index b23a664d69bcf9bd47fa2289eac4203fc46ba8c9..26147e6f9072b3501360f8efbf74330a22b87de7 100644 (file)
@@ -158,7 +158,8 @@ CREATE TABLE "SNAPSHOTS" (
   "PERIOD4_DATE" BIGINT,
   "PERIOD5_MODE" VARCHAR(100),
   "PERIOD5_PARAM" VARCHAR(100),
-  "PERIOD5_DATE" BIGINT
+  "PERIOD5_DATE" BIGINT,
+  "REVISION" VARCHAR(100)
 );
 CREATE INDEX "SNAPSHOT_COMPONENT" ON "SNAPSHOTS" ("COMPONENT_UUID");
 CREATE UNIQUE INDEX "ANALYSES_UUID" ON "SNAPSHOTS" ("UUID");
index b61837e660b478135bace5c1158c53e618f83a6d..e41b1f1d7ab87af796f1b55d88cfc37e8f6dad18 100644 (file)
@@ -33,6 +33,7 @@ Note that measures, events and reviews are not deleted.
              build_date="1228222680000"
              version="[null]"
              build_string="[null]"
+             revision="[null]"
   />
   <analysis_properties uuid="u1"
                        snapshot_uuid="u1"
@@ -106,6 +107,7 @@ Note that measures, events and reviews are not deleted.
              build_date="1228222680000"
              version="[null]"
              build_string="[null]"
+             revision="[null]"
   />
 
   <analysis_properties uuid="u2"
index 9d3afbaa2257c229b98de9b55b6aab4d874c78ea..b0aa9eb8837b6cb60508386f86214d30ab49adee 100644 (file)
@@ -51,6 +51,7 @@ Snapshot 2 has been deleted
              build_date="1228222680000"
              version="[null]"
              build_string="[null]"
+             revision="[null]"
   />
 
   <!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete -->
@@ -79,6 +80,7 @@ Snapshot 2 has been deleted
              build_date="1228222680000"
              version="[null]"
              build_string="[null]"
+             revision="[null]"
   />
 
 </dataset>
index aa7d13e08f5f51c1ad7f9db0ebcc2437cf75c125..2dda466f3a2c9071cdb1451bfd5915cab2458b10 100644 (file)
@@ -26,6 +26,7 @@
              build_date="1228222680000"
              version="[null]"
              build_string="[null]"
+             revision="[null]"
   />
 
   <!-- delete only resource 1 -->
@@ -54,6 +55,7 @@
              build_date="1228222680000"
              version="[null]"
              build_string="[null]"
+             revision="[null]"
   />
 
 </dataset>
index cbfd274de16b0f8c76560fd1d00e4ac81c5e9c31..aa85a695d08d3625215d8dfd763fb7fb8ffb0b1a 100644 (file)
              build_date="1228222680000"
              version="[null]"
              build_string="[null]"
+             revision="[null]"
   />
 
   <project_measures id="1"
              build_date="1228222680000"
              version="[null]"
              build_string="[null]"
+             revision="[null]"
   />
 
   <project_measures id="5"
index 3d7fd311f93823daca224d182de4b79714d30149..a3259f6ddd5fda618d722040f3149e07af0d8589 100644 (file)
@@ -67,6 +67,7 @@
              build_date="1228222680000"
              version="[null]"
              build_string="[null]"
+             revision="[null]"
   />
 
 
@@ -96,6 +97,7 @@
              build_date="1228222680000"
              version="[null]"
              build_string="[null]"
+             revision="[null]"
   />
 
   <!-- snapshot to be purged -->
              build_date="1228222680000"
              version="[null]"
              build_string="[null]"
+             revision="[null]"
   />
 
 </dataset>
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v78/AddSnapshotRevision.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v78/AddSnapshotRevision.java
new file mode 100644 (file)
index 0000000..bf04798
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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.v78;
+
+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.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+@SupportsBlueGreen
+public class AddSnapshotRevision extends DdlChange {
+
+  public AddSnapshotRevision(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddColumnsBuilder(getDialect(), "snapshots")
+      .addColumn(newVarcharColumnDefBuilder()
+        .setColumnName("revision")
+        .setIsNullable(true)
+        .setLimit(100)
+        .build())
+      .build());
+  }
+}
index dde78a84ef76f90034b4781c1565676c9fd9c6e9..635a74ab53b046606795113238c83c71dad3efb7 100644 (file)
@@ -32,6 +32,7 @@ public class DbVersion78 implements DbVersion {
       .add(2702, "Add column webhooks.secret", AddWebhooksSecret.class)
       .add(2703, "Add security fields to Elasticsearch indices", AddSecurityFieldsToElasticsearchIndices.class)
       .add(2704, "Add InternalComponentProperties table", CreateInternalComponentPropertiesTable.class)
+      .add(2705, "Add column snapshots.revision", AddSnapshotRevision.class)
       .add(2707, "Update statuses of Security Hotspots", UpdateSecurityHotspotsStatuses.class);
   }
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v78/AddSnapshotRevisionTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v78/AddSnapshotRevisionTest.java
new file mode 100644 (file)
index 0000000..f44bebb
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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.v78;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static java.sql.Types.VARCHAR;
+
+public class AddSnapshotRevisionTest {
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(AddSnapshotRevisionTest.class, "snapshots.sql");
+
+  private DdlChange underTest = new AddSnapshotRevision(db.database());
+
+  @Test
+  public void creates_table_on_empty_db() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("snapshots", "revision", VARCHAR, 100, true);
+  }
+
+  @Test
+  public void migration_is_not_reentrant() throws SQLException {
+    underTest.execute();
+
+    expectedException.expect(IllegalStateException.class);
+
+    underTest.execute();
+  }
+}
index e126254bd4d4e5ed66e082a4f8fdda8e70526b82..b97a927666c939f65f42046c205d622e97ba66ff 100644 (file)
@@ -35,7 +35,7 @@ public class DbVersion78Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 6);
+    verifyMigrationCount(underTest, 7);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v78/AddSnapshotRevisionTest/snapshots.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v78/AddSnapshotRevisionTest/snapshots.sql
new file mode 100644 (file)
index 0000000..89b83ad
--- /dev/null
@@ -0,0 +1,29 @@
+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),
+  "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");