]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11631 add SNAPSHOTS.PROJECT_VERSION
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 14 Jan 2019 17:02:45 +0000 (18:02 +0100)
committersonartech <sonartech@sonarsource.com>
Mon, 11 Feb 2019 08:11:47 +0000 (09:11 +0100)
23 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/shouldDeleteSnapshot-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteSnapshot.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingAnalysis-result.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-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldSelectPurgeableAnalysis.xml
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/AddProjectVersionToSnapshot.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/AddProjectVersionToSnapshotTest.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/resources/org/sonar/server/platform/db/migration/version/v77/AddProjectVersionToSnapshotTest/snapshots.sql [new file with mode: 0644]

index 1598855aa2de21b6178586247186dca33153745d..cea2a5ea5e6a9f6480cad75daef76996798e8662 100644 (file)
@@ -142,6 +142,7 @@ CREATE TABLE "SNAPSHOTS" (
   "PURGE_STATUS" INTEGER,
   "ISLAST" BOOLEAN NOT NULL DEFAULT FALSE,
   "VERSION" VARCHAR(500),
+  "PROJECT_VERSION" VARCHAR(100),
   "PERIOD1_MODE" VARCHAR(100),
   "PERIOD1_PARAM" VARCHAR(100),
   "PERIOD1_DATE" BIGINT,
index 2b7cd7f71078e97b8fc5cffd0f5e5fbebecc098d..af7588f557ed3fa245cc6647c78f7937255b549b 100644 (file)
@@ -42,6 +42,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <analysis_properties uuid="u1"
index b40e87b9ebd2a9c4e5a15ff9196ea71525e7037d..92d98ffddc3f5d024059c8019b5fe28bd2266e2f 100644 (file)
@@ -25,6 +25,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <project_measures ID="1"
index 1bfbfa5b4c1bc4fa00274ca055ce48677f0e1ae8..6279b1478cb28a884bd8d281e5f4a9e158c4a8c2 100644 (file)
@@ -25,6 +25,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <project_measures ID="1"
@@ -86,6 +87,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <project_measures ID="2"
index b2b6d9f4667d69892dbd836ca6044989337a467f..81bf959a9f985b67bc768975ecb7c4470a4eff65 100644 (file)
@@ -51,6 +51,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <!-- do not delete standard measure -->
index d683a6acfe64155ff4c2f747180e72e8c14ef9a1..8bee951c35bb049c8db4f70a9eeaf00e99df083d 100644 (file)
@@ -52,6 +52,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <!-- do not delete standard measure -->
index 9b8cfc57b266172ff947de0032e1779ba244a165..e7651e44899bd26337c60066dfc23a41296faed3 100644 (file)
@@ -32,6 +32,7 @@ Note that measures, events and reviews are not deleted.
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
   <analysis_properties uuid="u1"
                        snapshot_uuid="u1"
@@ -104,6 +105,7 @@ Note that measures, events and reviews are not deleted.
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <analysis_properties uuid="u2"
index 5e2e4c4e819eb5997a86964d6f6f71bc858940f6..b6b9c78349fde6867721645525705de8aad84ec0 100644 (file)
@@ -24,6 +24,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <analysis_properties uuid="u1"
@@ -97,6 +98,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <analysis_properties uuid="u2"
index e5c679bf4c5e0a8f00740c71db85505e794dccc5..3d926d2b8eda0e09e4dbdd9ba2c3139b2a3b1d97 100644 (file)
@@ -50,6 +50,7 @@ Snapshot 2 has been deleted
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete -->
@@ -77,6 +78,7 @@ Snapshot 2 has been deleted
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
 </dataset>
index 9acb701f9e9b700ff819aaad00fad401cb3fadbc..99b17569baec1943c1995e8881a5cbd338302f17 100644 (file)
@@ -45,6 +45,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <!-- snapshot with status "unprocessed" -> to be deleted -->
@@ -72,6 +73,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[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]"
   />
 
 </dataset>
index 878595a3c80740039128b238798d9b2df320ca30..bc8a1e2382eb6740910760914f75e1d91f67b629 100644 (file)
@@ -25,6 +25,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <!-- delete only resource 1 -->
@@ -52,6 +53,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
 </dataset>
index d4cdd2565323c4c8975a56aee326cd1680ab187d..7aa4af52e0cf16c9ac02a01a8b89fa9ba5015dfc 100644 (file)
@@ -25,6 +25,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <!-- delete only resource 1 -->
@@ -52,6 +53,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <!-- to be deleted -->
@@ -79,6 +81,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
 </dataset>
index e84a82ff99e2ab403e66f9b64c34417b352f947b..259be92616c6f34a285c8317d81590140370e67b 100644 (file)
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <project_measures id="1"
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <project_measures id="5"
index ff62231bcb5ebee5dda1843d0cbe535a488a1902..67c496411aa77ebe56529b1b825c26a7a1a0ea41 100644 (file)
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <project_measures id="1"
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <project_measures id="5"
index 11c383b63fd7f9386d51e91fac0fd2b7793cb3e8..7cff4413e5e25325d5084818cad02f6ebd5e4102 100644 (file)
@@ -58,6 +58,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <issues id="1"
index 5de7ce994c78cfc56f362a9ceb33c5572c70e0db..d58479413b82538d9b4c4f00961e756f3b24488a 100644 (file)
@@ -66,6 +66,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
 
@@ -94,6 +95,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <!-- snapshot to be purged -->
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
 </dataset>
index 4590dc6260b819d7e856c5a0697debe9dd488049..7362c125b54c26dc9a47c47120c7f005d2bcfb46 100644 (file)
@@ -65,6 +65,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
 
@@ -93,6 +94,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <!-- snapshot to be purged -->
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
 </dataset>
index e1c341d36b00fd4bb606e243db97644f4db3a4f8..48931a146e03919d8654419f79a2bb3368d2922e 100644 (file)
@@ -25,6 +25,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <!-- not processed -> exclude -->
@@ -52,6 +53,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <!-- on other resource -> exclude -->
@@ -79,6 +81,7 @@
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <!-- without event -> select -->
              created_at="1228222680000"
              build_date="1228222680000"
              version="[null]"
+             project_version="[null]"
   />
 
   <!-- with event -> select -->
              created_at="1228222680000"
              build_date="1228222680000"
              version="V5"
+             project_version="[null]"
   />
 
   <events id="2"
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/AddProjectVersionToSnapshot.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/AddProjectVersionToSnapshot.java
new file mode 100644 (file)
index 0000000..8849444
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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.def.VarcharColumnDef;
+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;
+
+public class AddProjectVersionToSnapshot extends DdlChange {
+  private static final String TABLE_NAME = "snapshots";
+  private static final VarcharColumnDef COLUMN_PROJECT_VERSION = newVarcharColumnDefBuilder()
+    .setColumnName("project_version")
+    .setIsNullable(true)
+    .setLimit(100)
+    .build();
+
+  public AddProjectVersionToSnapshot(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddColumnsBuilder(getDialect(), TABLE_NAME)
+      .addColumn(COLUMN_PROJECT_VERSION)
+      .build());
+  }
+}
index cadfd7b2314b474c6de33bfd3b224ccbead3a0aa..d1bb68348cee271905b13591d7dcc2006fbc6a43 100644 (file)
@@ -31,7 +31,8 @@ public class DbVersion77 implements DbVersion {
       .add(2601, "Delete lines with DATA_TYPE='TEST' from table FILES_SOURCE", DeleteTestDataTypeFromFileSources.class)
       .add(2602, "Add column LAST_CONNECTION_DATE to USERS table", AddLastConnectionDateToUsers.class)
       .add(2603, "Add column LAST_USED_DATE to USER_TOKENS table", AddLastConnectionDateToUserTokens.class)
-      .add(2604, "Add manual baseline column to PROJECT_BRANCHES", AddManualBaselineToProjectBranches.class)
+      .add(2604, "Add baseline columns in PROJECT_BRANCHES", AddManualBaselineToProjectBranches.class)
+      .add(2605, "Add SNAPSHOTS.PROJECT_VERSION", AddProjectVersionToSnapshot.class)
 
     ;
   }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/AddProjectVersionToSnapshotTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/AddProjectVersionToSnapshotTest.java
new file mode 100644 (file)
index 0000000..9e7972c
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+import static java.sql.Types.VARCHAR;
+
+public class AddProjectVersionToSnapshotTest {
+
+  private static final String TABLE = "snapshots";
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(AddProjectVersionToSnapshotTest.class, "snapshots.sql");
+
+  private AddProjectVersionToSnapshot underTest = new AddProjectVersionToSnapshot(db.database());
+
+  @Test
+  public void creates_table_on_empty_db() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition(TABLE, "project_version", VARCHAR, 100, true);
+  }
+
+  @Test
+  public void migration_is_not_reentrant() throws SQLException {
+    underTest.execute();
+
+    expectedException.expect(IllegalStateException.class);
+
+    underTest.execute();
+  }
+
+}
index 66e9f032d209b6483d620f535edcf070bff6450b..9768054845e684380fb4468e25c87d8e6ecd99bc 100644 (file)
@@ -36,7 +36,7 @@ public class DbVersion77Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 5);
+    verifyMigrationCount(underTest, 6);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v77/AddProjectVersionToSnapshotTest/snapshots.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v77/AddProjectVersionToSnapshotTest/snapshots.sql
new file mode 100644 (file)
index 0000000..7d8f296
--- /dev/null
@@ -0,0 +1,28 @@
+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),
+  "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");