Browse Source

SONAR-11631 add SNAPSHOTS.PROJECT_VERSION

tags/7.7
Sébastien Lesaint 5 years ago
parent
commit
51a28630d3
23 changed files with 173 additions and 2 deletions
  1. 1
    0
      server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
  2. 1
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml
  3. 1
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml
  4. 2
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteSnapshot.xml
  5. 1
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingAnalysis-result.xml
  6. 1
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingAnalysis.xml
  7. 2
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis-result.xml
  8. 2
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis.xml
  9. 2
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml
  10. 3
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml
  11. 2
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses-result.xml
  12. 3
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses.xml
  13. 2
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml
  14. 2
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml
  15. 1
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml
  16. 3
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldPurgeProject-result.xml
  17. 3
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldPurgeProject.xml
  18. 5
    0
      server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldSelectPurgeableAnalysis.xml
  19. 48
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/AddProjectVersionToSnapshot.java
  20. 2
    1
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77.java
  21. 57
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/AddProjectVersionToSnapshotTest.java
  22. 1
    1
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77Test.java
  23. 28
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v77/AddProjectVersionToSnapshotTest/snapshots.sql

+ 1
- 0
server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl View 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,

+ 1
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml View File

@@ -42,6 +42,7 @@
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
project_version="[null]"
/>

<analysis_properties uuid="u1"

+ 1
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml View File

@@ -25,6 +25,7 @@
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
project_version="[null]"
/>

<project_measures ID="1"

+ 2
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteSnapshot.xml View 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"

+ 1
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingAnalysis-result.xml View File

@@ -51,6 +51,7 @@
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
project_version="[null]"
/>

<!-- do not delete standard measure -->

+ 1
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingAnalysis.xml View File

@@ -52,6 +52,7 @@
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
project_version="[null]"
/>

<!-- do not delete standard measure -->

+ 2
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis-result.xml View 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"

+ 2
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis.xml View 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"

+ 2
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml View 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>

+ 3
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml View 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 -->
@@ -99,6 +101,7 @@
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
project_version="[null]"
/>

</dataset>

+ 2
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses-result.xml View 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>

+ 3
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses.xml View 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>

+ 2
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml View File

@@ -185,6 +185,7 @@
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
project_version="[null]"
/>

<project_measures id="1"
@@ -277,6 +278,7 @@
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
project_version="[null]"
/>

<project_measures id="5"

+ 2
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml View File

@@ -185,6 +185,7 @@
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
project_version="[null]"
/>

<project_measures id="1"
@@ -277,6 +278,7 @@
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
project_version="[null]"
/>

<project_measures id="5"

+ 1
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml View File

@@ -58,6 +58,7 @@
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
project_version="[null]"
/>

<issues id="1"

+ 3
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldPurgeProject-result.xml View 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 -->
@@ -121,6 +123,7 @@
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
project_version="[null]"
/>

</dataset>

+ 3
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldPurgeProject.xml View 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 -->
@@ -120,6 +122,7 @@
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
project_version="[null]"
/>

</dataset>

+ 5
- 0
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldSelectPurgeableAnalysis.xml View 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 -->
@@ -106,6 +109,7 @@
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
project_version="[null]"
/>

<!-- with event -> select -->
@@ -133,6 +137,7 @@
created_at="1228222680000"
build_date="1228222680000"
version="V5"
project_version="[null]"
/>

<events id="2"

+ 48
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/AddProjectVersionToSnapshot.java View File

@@ -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());
}
}

+ 2
- 1
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77.java View 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)

;
}

+ 57
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/AddProjectVersionToSnapshotTest.java View File

@@ -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();
}

}

+ 1
- 1
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77Test.java View File

@@ -36,7 +36,7 @@ public class DbVersion77Test {

@Test
public void verify_migration_count() {
verifyMigrationCount(underTest, 5);
verifyMigrationCount(underTest, 6);
}

}

+ 28
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v77/AddProjectVersionToSnapshotTest/snapshots.sql View File

@@ -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");

Loading…
Cancel
Save