Parcourir la source

SONAR-12218 remove DB migrations before 8.0

tags/8.0
Sébastien Lesaint il y a 5 ans
Parent
révision
753dbacdec
100 fichiers modifiés avec 3 ajouts et 6088 suppressions
  1. 1
    1
      server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
  2. 0
    38
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
  3. 1
    1
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProvider.java
  4. 1
    1
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProviderImpl.java
  5. 0
    924
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v56/CreateInitialSchema.java
  6. 0
    32
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v56/DbVersion56.java
  7. 0
    126
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v56/PopulateInitialSchema.java
  8. 0
    24
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v56/package-info.java
  9. 0
    30
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v561/DbVersion561.java
  10. 0
    69
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v561/UpdateUsersExternalIdentityWhenEmpty.java
  11. 0
    24
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v561/package-info.java
  12. 0
    45
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddAnalysisUuidColumnToCeActivity.java
  13. 0
    45
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddAnalysisUuidColumnToEvents.java
  14. 0
    45
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddAnalysisUuidColumnToMeasures.java
  15. 0
    55
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddBColumnsToProjects.java
  16. 0
    46
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddComponentUuidAndAnalysisUuidColumnToDuplicationsIndex.java
  17. 0
    45
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddComponentUuidColumnToMeasures.java
  18. 0
    46
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddComponentUuidColumnsToSnapshots.java
  19. 0
    46
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddIndexOnAnalysisUuidOfMeasures.java
  20. 0
    44
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddIndexOnComponentUuidOfMeasures.java
  21. 0
    44
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddLastUsedColumnToRulesProfiles.java
  22. 0
    44
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddProfileKeyToActivities.java
  23. 0
    44
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddUniqueIndexOnUuidOfSnapshots.java
  24. 0
    44
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddUserUpdatedAtToRulesProfiles.java
  25. 0
    45
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddUuidColumnToSnapshots.java
  26. 0
    47
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddUuidColumnsToProjects.java
  27. 0
    44
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddUuidPathColumnToProjects.java
  28. 0
    45
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CleanEventsWithoutAnalysisUuid.java
  29. 0
    45
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CleanEventsWithoutSnapshotId.java
  30. 0
    45
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CleanMeasuresWithNullAnalysisUuid.java
  31. 0
    48
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CleanOrphanRowsInProjects.java
  32. 0
    62
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CleanOrphanRowsInSnapshots.java
  33. 0
    156
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CleanUsurperRootComponents.java
  34. 0
    66
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CreatePermTemplatesCharacteristics.java
  35. 0
    51
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CreateTemporaryIndicesFor1211.java
  36. 0
    110
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DbVersion60.java
  37. 0
    61
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DeleteOrphanDuplicationsIndexRowsWithoutComponentOrAnalysis.java
  38. 0
    45
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DeleteOrphanMeasuresWithoutComponent.java
  39. 0
    44
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIdColumnsFromProjects.java
  40. 0
    44
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIdColumnsFromSnapshots.java
  41. 0
    39
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIndexDuplicationsIndexSidFromDuplicationsIndex.java
  42. 0
    39
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIndexEventsSnapshotIdFromEvents.java
  43. 0
    39
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIndexOnSnapshotIdOfMeasures.java
  44. 0
    39
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIndexProjectsRootIdFromProjects.java
  45. 0
    39
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIndexProjectsUuidFromProjects.java
  46. 0
    46
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIndicesOnTreeColumnsOfSnapshots.java
  47. 0
    41
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropProjectIdColumnFromMeasures.java
  48. 0
    40
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropRememberMeColumnsFromUsers.java
  49. 0
    41
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropResourceIndexRidFromResourceIndex.java
  50. 0
    44
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropSnapshotIdColumnFromCeActivity.java
  51. 0
    40
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropSnapshotIdColumnFromEvents.java
  52. 0
    40
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropSnapshotIdColumnFromMeasures.java
  53. 0
    41
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropSnapshotIdColumnsFromDuplicationsIndex.java
  54. 0
    46
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropSnapshotProjectIdFromSnapshots.java
  55. 0
    46
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropTemporaryIndicesOf1210.java
  56. 0
    41
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropTreeColumnsFromSnapshots.java
  57. 0
    50
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropTreesOfSnapshots.java
  58. 0
    58
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropUnusedMeasuresColumns.java
  59. 0
    53
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/FixProjectUuidOfDeveloperProjects.java
  60. 0
    59
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeAnalysisUuidNotNullOnEvents.java
  61. 0
    45
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeAnalysisUuidNotNullOnMeasures.java
  62. 0
    66
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex.java
  63. 0
    70
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeComponentUuidColumnsNotNullOnSnapshots.java
  64. 0
    45
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeComponentUuidNotNullOnMeasures.java
  65. 0
    44
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeProfileKeyNotNullOnActivities.java
  66. 0
    45
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeUuidColumnNotNullOnSnapshots.java
  67. 0
    55
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeUuidColumnsNotNullOnProjects.java
  68. 0
    44
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeUuidPathColumnNotNullOnProjects.java
  69. 0
    43
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/Migration1223.java
  70. 0
    54
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidColumnOnCeActivity.java
  71. 0
    55
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnEvents.java
  72. 0
    74
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnMeasures.java
  73. 0
    81
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateComponentUuidAndAnalysisUuidOfDuplicationsIndex.java
  74. 0
    85
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateComponentUuidColumnsOfSnapshots.java
  75. 0
    54
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateComponentUuidOfMeasures.java
  76. 0
    90
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateLastUsedColumnOfRulesProfiles.java
  77. 0
    66
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateProfileKeyOfActivities.java
  78. 0
    91
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateUserUpdatedAtOfRulesProfiles.java
  79. 0
    55
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateUuidColumnOnSnapshots.java
  80. 0
    167
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateUuidColumnsOfProjects.java
  81. 0
    169
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateUuidPathColumnOnProjects.java
  82. 0
    43
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/RecreateIndexProjectsUuidFromProjects.java
  83. 0
    50
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/RemoveUsersPasswordWhenNotLocal.java
  84. 0
    44
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/TemporarilyDropIndexOfAnalysisUuidOnMeasures.java
  85. 0
    23
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/package-info.java
  86. 0
    44
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/AddBUuidPathToProjects.java
  87. 0
    46
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/AddErrorColumnsToCeActivity.java
  88. 0
    68
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/CopyActivitiesToQprofileChanges.java
  89. 0
    47
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/CreateTableCeTaskInput.java
  90. 0
    49
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/CreateTableInternalProperties.java
  91. 0
    69
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/CreateTableProperties2.java
  92. 0
    49
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/CreateTableQprofileChanges.java
  93. 0
    46
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/CreateTableRuleRepositories.java
  94. 0
    47
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/CreateTableScannerContext.java
  95. 0
    56
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/DbVersion61.java
  96. 0
    74
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/DeleteProjectDashboards.java
  97. 0
    47
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/DeleteReportsFromCeQueue.java
  98. 0
    40
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/DropIsGlobalFromDashboards.java
  99. 0
    46
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/DropTableActivities.java
  100. 0
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/DropTableProperties.java

+ 1
- 1
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java Voir le fichier

@@ -122,7 +122,7 @@ public class ComputeEngineContainerImplTest {
);
assertThat(picoContainer.getParent().getParent().getComponentAdapters()).hasSize(
CONTAINER_ITSELF
+ 25 // MigrationConfigurationModule
+ 6 // MigrationConfigurationModule
+ 16 // level 2
);
assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize(

+ 0
- 38
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java Voir le fichier

@@ -24,25 +24,6 @@ import org.sonar.server.platform.db.migration.history.MigrationHistoryImpl;
import org.sonar.server.platform.db.migration.history.MigrationHistoryMeddler;
import org.sonar.server.platform.db.migration.step.MigrationStepRegistryImpl;
import org.sonar.server.platform.db.migration.step.MigrationStepsProvider;
import org.sonar.server.platform.db.migration.version.v56.DbVersion56;
import org.sonar.server.platform.db.migration.version.v561.DbVersion561;
import org.sonar.server.platform.db.migration.version.v60.DbVersion60;
import org.sonar.server.platform.db.migration.version.v61.DbVersion61;
import org.sonar.server.platform.db.migration.version.v62.DbVersion62;
import org.sonar.server.platform.db.migration.version.v63.DbVersion63;
import org.sonar.server.platform.db.migration.version.v64.DbVersion64;
import org.sonar.server.platform.db.migration.version.v65.DbVersion65;
import org.sonar.server.platform.db.migration.version.v66.DbVersion66;
import org.sonar.server.platform.db.migration.version.v67.DbVersion67;
import org.sonar.server.platform.db.migration.version.v70.DbVersion70;
import org.sonar.server.platform.db.migration.version.v71.DbVersion71;
import org.sonar.server.platform.db.migration.version.v72.DbVersion72;
import org.sonar.server.platform.db.migration.version.v73.DbVersion73;
import org.sonar.server.platform.db.migration.version.v74.DbVersion74;
import org.sonar.server.platform.db.migration.version.v75.DbVersion75;
import org.sonar.server.platform.db.migration.version.v76.DbVersion76;
import org.sonar.server.platform.db.migration.version.v77.DbVersion77;
import org.sonar.server.platform.db.migration.version.v78.DbVersion78;
import org.sonar.server.platform.db.migration.version.v79.DbVersion79;
import org.sonar.server.platform.db.migration.version.v80.DbVersion80;

@@ -51,25 +32,6 @@ public class MigrationConfigurationModule extends Module {
protected void configureModule() {
add(
// DbVersion implementations
DbVersion56.class,
DbVersion561.class,
DbVersion60.class,
DbVersion61.class,
DbVersion62.class,
DbVersion63.class,
DbVersion64.class,
DbVersion65.class,
DbVersion66.class,
DbVersion67.class,
DbVersion70.class,
DbVersion71.class,
DbVersion72.class,
DbVersion73.class,
DbVersion74.class,
DbVersion75.class,
DbVersion76.class,
DbVersion77.class,
DbVersion78.class,
DbVersion79.class,
DbVersion80.class,


server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DefaultOrganizationUuidProvider.java → server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProvider.java Voir le fichier

@@ -17,7 +17,7 @@
* 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.v63;
package org.sonar.server.platform.db.migration.version;

import java.sql.SQLException;
import org.sonar.server.platform.db.migration.step.DataChange;

server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DefaultOrganizationUuidProviderImpl.java → server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProviderImpl.java Voir le fichier

@@ -17,7 +17,7 @@
* 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.v63;
package org.sonar.server.platform.db.migration.version;

import java.sql.SQLException;
import org.sonar.server.platform.db.migration.step.DataChange;

+ 0
- 924
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v56/CreateInitialSchema.java Voir le fichier

@@ -1,924 +0,0 @@
/*
* 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.v56;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.def.BigIntegerColumnDef;
import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
import org.sonar.server.platform.db.migration.def.ColumnDef;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
import org.sonar.server.platform.db.migration.def.IntegerColumnDef;
import org.sonar.server.platform.db.migration.def.TinyIntColumnDef;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.BlobColumnDef.newBlobColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.ClobColumnDef.newClobColumnDefBuilder;
import static org.sonar.server.platform.db.migration.sql.CreateTableBuilder.ColumnFlag.AUTO_INCREMENT;
import static org.sonar.server.platform.db.migration.def.DecimalColumnDef.newDecimalColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.IntegerColumnDef.newIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.TimestampColumnDef.newTimestampColumnDefBuilder;

public class CreateInitialSchema extends DdlChange {

public CreateInitialSchema(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
createActiveDashboards(context);
createActiveRuleParameters(context);
createActiveRules(context);
createActivities(context);
createAuthors(context);
createCeActivity(context);
createCeQueue(context);
createDashboards(context);
createDuplicationsIndex(context);
createEvents(context);
createFileSources(context);
createGroupRoles(context);
createGroups(context);
createGroupsUsers(context);
createIssueChanges(context);
createIssueFilterFavourites(context);
createIssueFilters(context);
createIssues(context);
createLoadedTemplates(context);
createManualMeasures(context);
createMeasureFilterFavourites(context);
createMeasureFilters(context);
createMetrics(context);
createNotifications(context);
createPermissionTemplates(context);
createPermTemplatesGroups(context);
createPermTemplatesUsers(context);
createProjectLinks(context);
createProjectMeasures(context);
createProjectQprofiles(context);
createProjects(context);
createProperties(context);
createQualityGateConditions(context);
createQualityGates(context);
createResourceIndex(context);
createRules(context);
createRulesParameters(context);
createRulesProfiles(context);
createSnapshots(context);
createUserRoles(context);
createUserTokens(context);
createUsers(context);
createWidgetProperties(context);
createWidgets(context);
}

private void createUserTokens(Context context) throws SQLException {
VarcharColumnDef loginCol = newLenientVarcharBuilder("login").setLimit(255).setIsNullable(false).build();
VarcharColumnDef nameCol = newLenientVarcharBuilder("name").setLimit(100).setIsNullable(false).build();
VarcharColumnDef tokenHashCol = newLenientVarcharBuilder("token_hash").setLimit(255).setIsNullable(false).build();
context.execute(
newTableBuilder("user_tokens")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(loginCol)
.addColumn(nameCol)
.addColumn(tokenHashCol)
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
.build());
addIndex(context, "user_tokens", "user_tokens_login_name", true, loginCol, nameCol);
addIndex(context, "user_tokens", "user_tokens_token_hash", true, tokenHashCol);
}

private void createCeActivity(Context context) throws SQLException {
VarcharColumnDef uuidCol = newLenientVarcharBuilder("uuid").setLimit(40).setIsNullable(false).build();
VarcharColumnDef isLastKeyCol = newLenientVarcharBuilder("is_last_key").setLimit(55).setIsNullable(false).build();
BooleanColumnDef isLastCol = newBooleanColumnDefBuilder().setColumnName("is_last").setIsNullable(false).build();
VarcharColumnDef statusCol = newLenientVarcharBuilder("status").setLimit(15).setIsNullable(false).build();
VarcharColumnDef componentUuidCol = newLenientVarcharBuilder("component_uuid").setLimit(40).build();
context.execute(
newTableBuilder("ce_activity")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(uuidCol)
.addColumn(newLenientVarcharBuilder("task_type").setLimit(15).setIsNullable(false).build())
.addColumn(componentUuidCol)
.addColumn(statusCol)
.addColumn(isLastCol)
.addColumn(isLastKeyCol)
.addColumn(newLenientVarcharBuilder("submitter_login").setLimit(255).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("submitted_at").setIsNullable(false).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("started_at").build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("executed_at").build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").setIsNullable(false).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("execution_time_ms").build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("snapshot_id").build())
.build());
addIndex(context, "ce_activity", "ce_activity_component_uuid", false, componentUuidCol);
addIndex(context, "ce_activity", "ce_activity_islast_status", false, isLastCol, statusCol);
addIndex(context, "ce_activity", "ce_activity_islastkey", false, isLastKeyCol);
addIndex(context, "ce_activity", "ce_activity_uuid", true, uuidCol);
}

private void createCeQueue(Context context) throws SQLException {
VarcharColumnDef uuidCol = newLenientVarcharBuilder("uuid").setLimit(40).setIsNullable(false).build();
VarcharColumnDef componentUuidCol = newLenientVarcharBuilder("component_uuid").setLimit(40).build();
context.execute(
newTableBuilder("ce_queue")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(uuidCol)
.addColumn(newLenientVarcharBuilder("task_type").setLimit(15).setIsNullable(false).build())
.addColumn(componentUuidCol)
.addColumn(newLenientVarcharBuilder("status").setLimit(15).build())
.addColumn(newLenientVarcharBuilder("submitter_login").setLimit(255).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("started_at").build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").setIsNullable(false).build())
.build());
addIndex(context, "ce_queue", "ce_queue_component_uuid", false, componentUuidCol);
addIndex(context, "ce_queue", "ce_queue_uuid", true, uuidCol);
}

private void createFileSources(Context context) throws SQLException {
VarcharColumnDef projectUuidCol = newLenientVarcharBuilder("project_uuid").setLimit(50).setIsNullable(false).build();
BigIntegerColumnDef updatedAtCol = newBigIntegerColumnDefBuilder().setColumnName("updated_at").setIsNullable(false).build();
VarcharColumnDef dataTypeCol = newLenientVarcharBuilder("data_type").setLimit(20).build();
VarcharColumnDef fileUuidCol = newLenientVarcharBuilder("file_uuid").setLimit(50).setIsNullable(false).build();
context.execute(
newTableBuilder("file_sources")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(projectUuidCol)
.addColumn(fileUuidCol)
.addColumn(newClobColumnDefBuilder().setColumnName("line_hashes").build())
.addColumn(newLenientVarcharBuilder("data_hash").setLimit(50).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
.addColumn(updatedAtCol)
.addColumn(newLenientVarcharBuilder("src_hash").setLimit(50).build())
.addColumn(newBlobColumnDefBuilder().setColumnName("binary_data").build())
.addColumn(dataTypeCol)
.addColumn(newLenientVarcharBuilder("revision").setLimit(100).build())
.build());
addIndex(context, "file_sources", "file_sources_project_uuid", false, projectUuidCol);
addIndex(context, "file_sources", "file_sources_updated_at", false, updatedAtCol);
addIndex(context, "file_sources", "file_sources_uuid_type", true, fileUuidCol, dataTypeCol);
}

private void createActivities(Context context) throws SQLException {
VarcharColumnDef keeCol = newLenientVarcharBuilder("log_key").setLimit(255).build();
context.execute(
newTableBuilder("activities")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").build())
.addColumn(newLenientVarcharBuilder("user_login").setLimit(255).build())
.addColumn(newClobColumnDefBuilder().setColumnName("data_field").build())
.addColumn(newLenientVarcharBuilder("log_type").setLimit(50).build())
.addColumn(newLenientVarcharBuilder("log_action").setLimit(50).build())
.addColumn(newLenientVarcharBuilder("log_message").setLimit(4000).build())
.addColumn(keeCol)
.build());

addIndex(context, "activities", "activities_log_key", true, keeCol);
}

private void createPermTemplatesGroups(Context context) throws SQLException {
context.execute(
newTableBuilder("perm_templates_groups")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newIntegerColumnDefBuilder().setColumnName("group_id").build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("template_id").setIsNullable(false).build())
.addColumn(newLenientVarcharBuilder("permission_reference").setLimit(64).setIsNullable(false).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("updated_at").build())
.build());
}

private void createPermTemplatesUsers(Context context) throws SQLException {
context.execute(
newTableBuilder("perm_templates_users")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newIntegerColumnDefBuilder().setColumnName("user_id").setIsNullable(false).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("template_id").setIsNullable(false).build())
.addColumn(newLenientVarcharBuilder("permission_reference").setLimit(64).setIsNullable(false).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("updated_at").build())
.build());
}

private void createPermissionTemplates(Context context) throws SQLException {
context.execute(
newTableBuilder("permission_templates")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newLenientVarcharBuilder("name").setLimit(100).setIsNullable(false).build())
.addColumn(newLenientVarcharBuilder("kee").setLimit(100).setIsNullable(false).build())
.addColumn(newLenientVarcharBuilder("description").setLimit(4000).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("updated_at").build())
.addColumn(newLenientVarcharBuilder("key_pattern").setLimit(500).build())
.build());
}

private void createIssueFilterFavourites(Context context) throws SQLException {
VarcharColumnDef loginCol = newLenientVarcharBuilder("user_login").setLimit(255).setIsNullable(false).build();
context.execute(
newTableBuilder("issue_filter_favourites")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(loginCol)
.addColumn(newIntegerColumnDefBuilder().setColumnName("issue_filter_id").setIsNullable(false).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").build())
.build());
addIndex(context, "issue_filter_favourites", "issue_filter_favs_user", false, loginCol);
}

private void createIssueFilters(Context context) throws SQLException {
VarcharColumnDef nameCol = newLenientVarcharBuilder("name").setLimit(100).setIsNullable(false).build();
context.execute(
newTableBuilder("issue_filters")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(nameCol)
.addColumn(newLenientVarcharBuilder("user_login").setLimit(255).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("shared").setIsNullable(false).setDefaultValue(false).build())
.addColumn(newLenientVarcharBuilder("description").setLimit(4000).build())
.addColumn(newClobColumnDefBuilder().setColumnName("data").build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("updated_at").build())
.build());
addIndex(context, "issue_filters", "issue_filters_name", false, nameCol);
}

private void createIssueChanges(Context context) throws SQLException {
VarcharColumnDef issueKeyCol = newLenientVarcharBuilder("issue_key").setLimit(50).setIsNullable(false).build();
VarcharColumnDef keeCol = newLenientVarcharBuilder("kee").setLimit(50).build();
context.execute(
newTableBuilder("issue_changes")
.addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(keeCol)
.addColumn(issueKeyCol)
.addColumn(newLenientVarcharBuilder("user_login").setLimit(255).build())
.addColumn(newLenientVarcharBuilder("change_type").setLimit(20).build())
.addColumn(newClobColumnDefBuilder().setColumnName("change_data").build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("issue_change_creation_date").build())
.build());
addIndex(context, "issue_changes", "issue_changes_issue_key", false, issueKeyCol);
addIndex(context, "issue_changes", "issue_changes_kee", false, keeCol);
}

private void createIssues(Context context) throws SQLException {
VarcharColumnDef assigneeCol = newLenientVarcharBuilder("assignee").setLimit(255).build();
VarcharColumnDef componentUuidCol = newLenientVarcharBuilder("component_uuid").setLimit(50).build();
BigIntegerColumnDef issueCreationDateCol = newBigIntegerColumnDefBuilder().setColumnName("issue_creation_date").build();
VarcharColumnDef keeCol = newLenientVarcharBuilder("kee").setLimit(50).setIsNullable(false).build();
VarcharColumnDef projectUuidCol = newLenientVarcharBuilder("project_uuid").setLimit(50).build();
VarcharColumnDef resolutionCol = newLenientVarcharBuilder("resolution").setLimit(20).build();
IntegerColumnDef ruleIdCol = newIntegerColumnDefBuilder().setColumnName("rule_id").build();
BigIntegerColumnDef updatedAtCol = newBigIntegerColumnDefBuilder().setColumnName("updated_at").build();
context.execute(
newTableBuilder("issues")
.addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(keeCol)
.addColumn(ruleIdCol)
.addColumn(newLenientVarcharBuilder("severity").setLimit(10).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("manual_severity").setIsNullable(false).build())
// unit has been fixed in SonarQube 5.6 (see migration 1151, SONAR-7493)
.addColumn(newLenientVarcharBuilder("message").setIgnoreOracleUnit(false).setLimit(4000).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("line").build())
.addColumn(newDecimalColumnDefBuilder().setColumnName("gap").setPrecision(30).setScale(20).build())
.addColumn(newLenientVarcharBuilder("status").setLimit(20).build())
.addColumn(resolutionCol)
.addColumn(newLenientVarcharBuilder("checksum").setLimit(1000).build())
.addColumn(newLenientVarcharBuilder("reporter").setLimit(255).build())
.addColumn(assigneeCol)
.addColumn(newLenientVarcharBuilder("author_login").setLimit(255).build())
.addColumn(newLenientVarcharBuilder("action_plan_key").setLimit(50).build())
.addColumn(newLenientVarcharBuilder("issue_attributes").setLimit(4000).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("effort").build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").build())
.addColumn(updatedAtCol)
.addColumn(issueCreationDateCol)
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("issue_update_date").build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("issue_close_date").build())
.addColumn(newLenientVarcharBuilder("tags").setLimit(4000).build())
.addColumn(componentUuidCol)
.addColumn(projectUuidCol)
.addColumn(newBlobColumnDefBuilder().setColumnName("locations").build())
.addColumn(new TinyIntColumnDef.Builder().setColumnName("issue_type").build())
.build());
addIndex(context, "issues", "issues_assignee", false, assigneeCol);
addIndex(context, "issues", "issues_component_uuid", false, componentUuidCol);
addIndex(context, "issues", "issues_creation_date", false, issueCreationDateCol);
addIndex(context, "issues", "issues_kee", true, keeCol);
addIndex(context, "issues", "issues_project_uuid", false, projectUuidCol);
addIndex(context, "issues", "issues_resolution", false, resolutionCol);
addIndex(context, "issues", "issues_rule_id", false, ruleIdCol);
addIndex(context, "issues", "issues_updated_at", false, updatedAtCol);
}

private void createMeasureFilterFavourites(Context context) throws SQLException {
IntegerColumnDef userIdCol = newIntegerColumnDefBuilder().setColumnName("user_id").setIsNullable(false).build();
context.execute(
newTableBuilder("measure_filter_favourites")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(userIdCol)
.addColumn(newIntegerColumnDefBuilder().setColumnName("measure_filter_id").setIsNullable(false).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").build())
.build());
addIndex(context, "measure_filter_favourites", "measure_filter_favs_userid", false, userIdCol);
}

private void createMeasureFilters(Context context) throws SQLException {
VarcharColumnDef nameCol = newLenientVarcharBuilder("name").setLimit(100).setIsNullable(false).build();
context.execute(
newTableBuilder("measure_filters")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(nameCol)
.addColumn(newIntegerColumnDefBuilder().setColumnName("user_id").build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("shared").setDefaultValue(false).setIsNullable(false).build())
.addColumn(newLenientVarcharBuilder("description").setLimit(4000).build())
.addColumn(newClobColumnDefBuilder().setColumnName("data").build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("updated_at").build())
.build());
addIndex(context, "measure_filters", "measure_filters_name", false, nameCol);
}

private void createAuthors(Context context) throws SQLException {
VarcharColumnDef loginCol = newLenientVarcharBuilder("login").setLimit(255).build();
context.execute(
newTableBuilder("authors")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newIntegerColumnDefBuilder().setColumnName("person_id").setIsNullable(false).build())
.addColumn(loginCol)
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("updated_at").build())
.build());
addIndex(context, "authors", "uniq_author_logins", true, loginCol);
}

private void createResourceIndex(Context context) throws SQLException {
VarcharColumnDef keeCol = newLenientVarcharBuilder("kee").setLimit(400).setIsNullable(false).build();
IntegerColumnDef resourceIdCol = newIntegerColumnDefBuilder().setColumnName("resource_id").setIsNullable(false).build();
context.execute(
newTableBuilder("resource_index")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(keeCol)
.addColumn(newIntegerColumnDefBuilder().setColumnName("position").setIsNullable(false).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("name_size").setIsNullable(false).build())
.addColumn(resourceIdCol)
.addColumn(newIntegerColumnDefBuilder().setColumnName("root_project_id").setIsNullable(false).build())
.addColumn(newLenientVarcharBuilder("qualifier").setLimit(10).setIsNullable(false).build())
.build());
addIndex(context, "resource_index", "resource_index_key", false, keeCol);
addIndex(context, "resource_index", "resource_index_rid", false, resourceIdCol);
}

private void createLoadedTemplates(Context context) throws SQLException {
context.execute(
newTableBuilder("loaded_templates")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newLenientVarcharBuilder("kee").setLimit(200).build())
.addColumn(newLenientVarcharBuilder("template_type").setLimit(15).build())
.build());
}

private void createMetrics(Context context) throws SQLException {
VarcharColumnDef nameCol = newLenientVarcharBuilder("name").setLimit(64).setIsNullable(false).build();
context.execute(
newTableBuilder("metrics")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(nameCol)
.addColumn(newLenientVarcharBuilder("description").setLimit(255).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("direction").setIsNullable(false).setDefaultValue(0).build())
.addColumn(newLenientVarcharBuilder("domain").setLimit(64).build())
.addColumn(newLenientVarcharBuilder("short_name").setLimit(64).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("qualitative").setDefaultValue(false).setIsNullable(false).build())
.addColumn(newLenientVarcharBuilder("val_type").setLimit(8).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("user_managed").setDefaultValue(false).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("enabled").setDefaultValue(true).build())
.addColumn(newDecimalColumnDefBuilder().setColumnName("worst_value").setPrecision(38).setScale(20).build())
.addColumn(newDecimalColumnDefBuilder().setColumnName("best_value").setPrecision(38).setScale(20).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("optimized_best_value").build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("hidden").build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("delete_historical_data").build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("decimal_scale").build())
.build());
addIndex(context, "metrics", "metrics_unique_name", true, nameCol);
}

private void createDashboards(Context context) throws SQLException {
context.execute(
newTableBuilder("dashboards")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newIntegerColumnDefBuilder().setColumnName("user_id").build())
.addColumn(newLenientVarcharBuilder("name").setLimit(256).build())
.addColumn(newLenientVarcharBuilder("description").setLimit(1000).build())
.addColumn(newLenientVarcharBuilder("column_layout").setLimit(20).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("shared").build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("updated_at").build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("is_global").build())
.build());
}

private void createUsers(Context context) throws SQLException {
VarcharColumnDef loginCol = newLenientVarcharBuilder("login").setLimit(255).build();
BigIntegerColumnDef updatedAtCol = newBigIntegerColumnDefBuilder().setColumnName("updated_at").build();
context.execute(
newTableBuilder("users")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(loginCol)
.addColumn(newLenientVarcharBuilder("name").setLimit(200).build())
.addColumn(newLenientVarcharBuilder("email").setLimit(100).build())
.addColumn(newLenientVarcharBuilder("crypted_password").setLimit(40).build())
.addColumn(newLenientVarcharBuilder("salt").setLimit(40).build())
.addColumn(newLenientVarcharBuilder("remember_token").setLimit(500).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("remember_token_expires_at").build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("active").setDefaultValue(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").build())
.addColumn(updatedAtCol)
.addColumn(newLenientVarcharBuilder("scm_accounts").setLimit(4000).build())
.addColumn(newLenientVarcharBuilder("external_identity").setLimit(255).build())
.addColumn(newLenientVarcharBuilder("external_identity_provider").setLimit(100).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("user_local").build())
.build());
addIndex(context, "users", "users_login", true, loginCol);
addIndex(context, "users", "users_updated_at", false, updatedAtCol);
}

private void createActiveRuleParameters(Context context) throws SQLException {
context.execute(
newTableBuilder("active_rule_parameters")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newIntegerColumnDefBuilder().setColumnName("active_rule_id").setIsNullable(false).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("rules_parameter_id").setIsNullable(false).build())
.addColumn(newLenientVarcharBuilder("value").setLimit(4000).build())
.addColumn(newLenientVarcharBuilder("rules_parameter_key").setLimit(128).build())
.build());
}

private void createActiveRules(Context context) throws SQLException {
IntegerColumnDef profileIdCol = newIntegerColumnDefBuilder().setColumnName("profile_id").setIsNullable(false).build();
IntegerColumnDef ruleIdCol = newIntegerColumnDefBuilder().setColumnName("rule_id").setIsNullable(false).build();
context.execute(
newTableBuilder("active_rules")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(profileIdCol)
.addColumn(ruleIdCol)
.addColumn(newIntegerColumnDefBuilder().setColumnName("failure_level").setIsNullable(false).build())
.addColumn(newLenientVarcharBuilder("inheritance").setLimit(10).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").build())
.build());
addIndex(context, "active_rules", "uniq_profile_rule_ids", true, profileIdCol, ruleIdCol);
}

private void createUserRoles(Context context) throws SQLException {
IntegerColumnDef userIdCol = newIntegerColumnDefBuilder().setColumnName("user_id").build();
IntegerColumnDef resourceIdCol = newIntegerColumnDefBuilder().setColumnName("resource_id").build();
context.execute(
newTableBuilder("user_roles")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(userIdCol)
.addColumn(resourceIdCol)
.addColumn(newLenientVarcharBuilder("role").setLimit(64).setIsNullable(false).build())
.build());
addIndex(context, "user_roles", "user_roles_resource", false, resourceIdCol);
addIndex(context, "user_roles", "user_roles_user", false, userIdCol);
}

private void createActiveDashboards(Context context) throws SQLException {
IntegerColumnDef dashboardIdCol = newIntegerColumnDefBuilder().setColumnName("dashboard_id").setIsNullable(false).build();
IntegerColumnDef userIdCol = newIntegerColumnDefBuilder().setColumnName("user_id").build();
context.execute(
newTableBuilder("active_dashboards")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(dashboardIdCol)
.addColumn(userIdCol)
.addColumn(newIntegerColumnDefBuilder().setColumnName("order_index").build())
.build());
addIndex(context, "active_dashboards", "active_dashboards_dashboardid", false, dashboardIdCol);
addIndex(context, "active_dashboards", "active_dashboards_userid", false, userIdCol);
}

private void createNotifications(Context context) throws SQLException {
context.execute(
newTableBuilder("notifications")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newBlobColumnDefBuilder().setColumnName("data").build())
.build());
}

private void createSnapshots(Context context) throws SQLException {
IntegerColumnDef projectIdCol = newIntegerColumnDefBuilder().setColumnName("project_id").setIsNullable(false).build();
IntegerColumnDef rootProjectIdCol = newIntegerColumnDefBuilder().setColumnName("root_project_id").setIsNullable(true).build();
IntegerColumnDef parentSnapshotIdCol = newIntegerColumnDefBuilder().setColumnName("parent_snapshot_id").setIsNullable(true).build();
VarcharColumnDef qualifierCol = newLenientVarcharBuilder("qualifier").setLimit(10).setIsNullable(true).build();
IntegerColumnDef rootSnapshotIdCol = newIntegerColumnDefBuilder().setColumnName("root_snapshot_id").setIsNullable(true).build();
context.execute(
newTableBuilder("snapshots")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(projectIdCol)
.addColumn(parentSnapshotIdCol)
.addColumn(newLenientVarcharBuilder("status").setLimit(4).setIsNullable(false).setDefaultValue("U").build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("islast").setIsNullable(false).setDefaultValue(false).build())
.addColumn(newLenientVarcharBuilder("scope").setLimit(3).setIsNullable(true).build())
.addColumn(qualifierCol)
.addColumn(rootSnapshotIdCol)
.addColumn(newLenientVarcharBuilder("version").setLimit(500).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("path").setLimit(500).setIsNullable(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("depth").setIsNullable(true).build())
.addColumn(rootProjectIdCol)
.addColumn(newIntegerColumnDefBuilder().setColumnName("purge_status").setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("period1_mode").setLimit(100).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("period1_param").setLimit(100).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("period2_mode").setLimit(100).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("period2_param").setLimit(100).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("period3_mode").setLimit(100).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("period3_param").setLimit(100).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("period4_mode").setLimit(100).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("period4_param").setLimit(100).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("period5_mode").setLimit(100).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("period5_param").setLimit(100).setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("build_date").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("period1_date").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("period2_date").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("period3_date").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("period4_date").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("period5_date").setIsNullable(true).build())
.build());
addIndex(context, "snapshots", "snapshot_project_id", false, projectIdCol);
addIndex(context, "snapshots", "snapshots_parent", false, parentSnapshotIdCol);
addIndex(context, "snapshots", "snapshots_qualifier", false, qualifierCol);
addIndex(context, "snapshots", "snapshots_root", false, rootSnapshotIdCol);
addIndex(context, "snapshots", "snapshots_root_project_id", false, rootProjectIdCol);
}

private void createGroups(Context context) throws SQLException {
context.execute(
newTableBuilder("groups")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newLenientVarcharBuilder("name").setLimit(500).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("description").setLimit(200).setIsNullable(true).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").setIsNullable(true).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("updated_at").setIsNullable(true).build())
.build());
}

private void createWidgets(Context context) throws SQLException {
IntegerColumnDef dashboardId = newIntegerColumnDefBuilder().setColumnName("dashboard_id").setIsNullable(false).build();
VarcharColumnDef widgetKey = newLenientVarcharBuilder("widget_key").setLimit(256).setIsNullable(false).build();
context.execute(
newTableBuilder("widgets")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(dashboardId)
.addColumn(widgetKey)
.addColumn(newLenientVarcharBuilder("name").setLimit(256).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("description").setLimit(1000).setIsNullable(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("column_index").setIsNullable(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("row_index").setIsNullable(true).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("configured").setIsNullable(true).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").setIsNullable(true).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("updated_at").setIsNullable(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("resource_id").setIsNullable(true).build())
.build());
addIndex(context, "widgets", "widgets_dashboards", false, dashboardId);
addIndex(context, "widgets", "widgets_widgetkey", false, widgetKey);
}

private void createProjectQprofiles(Context context) throws SQLException {
VarcharColumnDef projectUuid = newLenientVarcharBuilder("project_uuid").setLimit(50).setIsNullable(false).build();
VarcharColumnDef profileKey = newLenientVarcharBuilder("profile_key").setLimit(50).setIsNullable(false).build();
context.execute(
newTableBuilder("project_qprofiles")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(projectUuid)
.addColumn(profileKey)
.build());
addIndex(context, "project_qprofiles", "uniq_project_qprofiles", true, projectUuid, profileKey);
}

private void createRulesProfiles(Context context) throws SQLException {
VarcharColumnDef keeCol = newLenientVarcharBuilder("kee").setLimit(255).setIsNullable(false).build();
context.execute(
newTableBuilder("rules_profiles")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newLenientVarcharBuilder("name").setLimit(100).setIsNullable(false).build())
.addColumn(newLenientVarcharBuilder("language").setLimit(20).setIsNullable(true).build())
.addColumn(keeCol)
.addColumn(newLenientVarcharBuilder("parent_kee").setLimit(255).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("rules_updated_at").setLimit(100).setIsNullable(true).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").setIsNullable(true).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("updated_at").setIsNullable(true).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("is_default").setIsNullable(false).build())
.build());
addIndex(context, "rules_profiles", "uniq_qprof_key", true, keeCol);
}

private void createRulesParameters(Context context) throws SQLException {
IntegerColumnDef ruleIdCol = newIntegerColumnDefBuilder().setColumnName("rule_id").setIsNullable(false).build();
context.execute(
newTableBuilder("rules_parameters")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(ruleIdCol)
.addColumn(newLenientVarcharBuilder("name").setLimit(128).setIsNullable(false).build())
.addColumn(newLenientVarcharBuilder("description").setLimit(4000).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("param_type").setLimit(512).setIsNullable(false).build())
.addColumn(newLenientVarcharBuilder("default_value").setLimit(4000).setIsNullable(true).build())
.build());
addIndex(context, "rules_parameters", "rules_parameters_rule_id", false, ruleIdCol);
}

private void createGroupsUsers(Context context) throws SQLException {
BigIntegerColumnDef userIdCol = newBigIntegerColumnDefBuilder().setColumnName("user_id").setIsNullable(true).build();
BigIntegerColumnDef groupIdCol = newBigIntegerColumnDefBuilder().setColumnName("group_id").setIsNullable(true).build();
context.execute(
newTableBuilder("groups_users")
.addColumn(userIdCol)
.addColumn(groupIdCol)
.build());
addIndex(context, "groups_users", "index_groups_users_on_user_id", false, userIdCol);
addIndex(context, "groups_users", "index_groups_users_on_group_id", false, groupIdCol);
addIndex(context, "groups_users", "groups_users_unique", true, groupIdCol, userIdCol);
}

private void createProjectMeasures(Context context) throws SQLException {
IntegerColumnDef personIdCol = newIntegerColumnDefBuilder().setColumnName("person_id").build();
IntegerColumnDef metricIdCol = newIntegerColumnDefBuilder().setColumnName("metric_id").setIsNullable(false).build();
IntegerColumnDef snapshotIdCol = newIntegerColumnDefBuilder().setColumnName("snapshot_id").setIsNullable(true).build();
context.execute(
newTableBuilder("project_measures")
.addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newDecimalColumnDefBuilder().setColumnName("value").setPrecision(38).setScale(20).build())
.addColumn(metricIdCol)
.addColumn(snapshotIdCol)
.addColumn(newIntegerColumnDefBuilder().setColumnName("rule_id").setIsNullable(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("rules_category_id").setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("text_value").setLimit(4000).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("tendency").build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("measure_date").build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("project_id").build())
.addColumn(newLenientVarcharBuilder("alert_status").setLimit(5).build())
.addColumn(newLenientVarcharBuilder("alert_text").setLimit(4000).build())
.addColumn(newLenientVarcharBuilder("url").setLimit(2000).build())
.addColumn(newLenientVarcharBuilder("description").setLimit(4000).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("rule_priority").build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("characteristic_id").build())
.addColumn(personIdCol)
.addColumn(newDecimalColumnDefBuilder().setColumnName("variation_value_1").setPrecision(38).setScale(20).build())
.addColumn(newDecimalColumnDefBuilder().setColumnName("variation_value_2").setPrecision(38).setScale(20).build())
.addColumn(newDecimalColumnDefBuilder().setColumnName("variation_value_3").setPrecision(38).setScale(20).build())
.addColumn(newDecimalColumnDefBuilder().setColumnName("variation_value_4").setPrecision(38).setScale(20).build())
.addColumn(newDecimalColumnDefBuilder().setColumnName("variation_value_5").setPrecision(38).setScale(20).build())
.addColumn(newBlobColumnDefBuilder().setColumnName("measure_data").build())
.build());
addIndex(context, "project_measures", "measures_sid_metric", false, snapshotIdCol, metricIdCol);
addIndex(context, "project_measures", "measures_person", false, personIdCol);
}

private void createManualMeasures(Context context) throws SQLException {
VarcharColumnDef componentUuidCol = newLenientVarcharBuilder("component_uuid").setLimit(50).build();
context.execute(
newTableBuilder("manual_measures")
.addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newIntegerColumnDefBuilder().setColumnName("metric_id").setIsNullable(false).build())
.addColumn(newDecimalColumnDefBuilder().setColumnName("value").setPrecision(38).setScale(20).build())
.addColumn(newLenientVarcharBuilder("text_value").setLimit(4000).build())
.addColumn(newLenientVarcharBuilder("user_login").setLimit(255).build())
.addColumn(newLenientVarcharBuilder("description").setLimit(4000).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").build())
.addColumn(componentUuidCol)
.build());
addIndex(context, "manual_measures", "manual_measures_component_uuid", false, componentUuidCol);
}

private void createProjects(Context context) throws SQLException {
VarcharColumnDef keeCol = newLenientVarcharBuilder("kee").setLimit(400).build();
VarcharColumnDef moduleUuidCol = newLenientVarcharBuilder("module_uuid").setLimit(50).build();
VarcharColumnDef projectUuidCol = newLenientVarcharBuilder("project_uuid").setLimit(50).build();
VarcharColumnDef qualifierCol = newLenientVarcharBuilder("qualifier").setLimit(10).build();
IntegerColumnDef rootIdCol = newIntegerColumnDefBuilder().setColumnName("root_id").build();
VarcharColumnDef uuidCol = newLenientVarcharBuilder("uuid").setLimit(50).build();
context.execute(
newTableBuilder("projects")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newLenientVarcharBuilder("name").setLimit(2000).build())
.addColumn(newLenientVarcharBuilder("description").setLimit(2000).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("enabled").setDefaultValue(true).setIsNullable(false).build())
.addColumn(newLenientVarcharBuilder("scope").setLimit(3).build())
.addColumn(qualifierCol)
.addColumn(keeCol)
.addColumn(rootIdCol)
.addColumn(newLenientVarcharBuilder("language").setLimit(20).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("copy_resource_id").build())
.addColumn(newLenientVarcharBuilder("long_name").setLimit(2000).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("person_id").build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").build())
.addColumn(newLenientVarcharBuilder("path").setLimit(2000).build())
.addColumn(newLenientVarcharBuilder("deprecated_kee").setLimit(400).build())
.addColumn(uuidCol)
.addColumn(projectUuidCol)
.addColumn(moduleUuidCol)
.addColumn(newLenientVarcharBuilder("module_uuid_path").setLimit(4000).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("authorization_updated_at").build())
.build());
addIndex(context, "projects", "projects_kee", true, keeCol);
addIndex(context, "projects", "projects_module_uuid", false, moduleUuidCol);
addIndex(context, "projects", "projects_project_uuid", false, projectUuidCol);
addIndex(context, "projects", "projects_qualifier", false, qualifierCol);
addIndex(context, "projects", "projects_root_id", false, rootIdCol);
addIndex(context, "projects", "projects_uuid", true, uuidCol);
}

private void createGroupRoles(Context context) throws SQLException {
IntegerColumnDef groupIdCol = newIntegerColumnDefBuilder().setColumnName("group_id").setIsNullable(true).build();
IntegerColumnDef resourceIdCol = newIntegerColumnDefBuilder().setColumnName("resource_id").setIsNullable(true).build();
VarcharColumnDef roleCol = newLenientVarcharBuilder("role").setLimit(64).setIsNullable(false).build();
context.execute(
newTableBuilder("group_roles")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(groupIdCol)
.addColumn(resourceIdCol)
.addColumn(roleCol)
.build());
addIndex(context, "group_roles", "group_roles_resource", false, resourceIdCol);
addIndex(context, "group_roles", "uniq_group_roles", true, groupIdCol, resourceIdCol, roleCol);
}

private void createRules(Context context) throws SQLException {
VarcharColumnDef pluginRuleKeyCol = newLenientVarcharBuilder("plugin_rule_key").setLimit(200).setIsNullable(false).build();
VarcharColumnDef pluginNameCol = newLenientVarcharBuilder("plugin_name").setLimit(255).setIsNullable(false).build();
context.execute(
newTableBuilder("rules")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newLenientVarcharBuilder("name").setLimit(200).setIsNullable(true).build())
.addColumn(pluginRuleKeyCol)
.addColumn(newLenientVarcharBuilder("plugin_config_key").setLimit(200).setIsNullable(true).build())
.addColumn(pluginNameCol)
.addColumn(newClobColumnDefBuilder().setColumnName("description").setIsNullable(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("priority").setIsNullable(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("template_id").setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("status").setLimit(40).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("language").setLimit(20).setIsNullable(true).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("note_created_at").setIsNullable(true).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("note_updated_at").setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("note_user_login").setLimit(255).setIsNullable(true).build())
.addColumn(newClobColumnDefBuilder().setColumnName("note_data").setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("remediation_function").setLimit(200).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("def_remediation_function").setLimit(20).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("remediation_gap_mult").setLimit(20).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("def_remediation_gap_mult").setLimit(20).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("remediation_base_effort").setLimit(20).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("def_remediation_base_effort").setLimit(20).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("gap_description").setLimit(4000).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("tags").setLimit(4000).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("system_tags").setLimit(4000).setIsNullable(true).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("is_template").setIsNullable(false).setDefaultValue(false).build())
.addColumn(newLenientVarcharBuilder("description_format").setLimit(20).setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").setIsNullable(true).build())
.addColumn(new TinyIntColumnDef.Builder().setColumnName("rule_type").setIsNullable(true).build())
.build());
addIndex(context, "rules", "rules_repo_key", true, pluginRuleKeyCol, pluginNameCol);
}

private void createWidgetProperties(Context context) throws SQLException {
IntegerColumnDef widgetIdCol = newIntegerColumnDefBuilder().setColumnName("widget_id").setIsNullable(false).build();
context.execute(
newTableBuilder("widget_properties")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(widgetIdCol)
.addColumn(newLenientVarcharBuilder("kee").setLimit(100).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("text_value").setLimit(4000).setIsNullable(true).build())
.build());
addIndex(context, "widget_properties", "widget_properties_widgets", false, widgetIdCol);
}

private void createEvents(Context context) throws SQLException {
VarcharColumnDef componentUuid = newLenientVarcharBuilder("component_uuid").setLimit(50).setIsNullable(true).build();
IntegerColumnDef snapshotId = newIntegerColumnDefBuilder().setColumnName("snapshot_id").setIsNullable(true).build();
context.execute(
newTableBuilder("events")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newLenientVarcharBuilder("name").setLimit(400).setIsNullable(true).build())
.addColumn(snapshotId)
.addColumn(newLenientVarcharBuilder("category").setLimit(50).build())
.addColumn(newLenientVarcharBuilder("description").setLimit(4000).build())
.addColumn(newLenientVarcharBuilder("event_data").setLimit(4000).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("event_date").setIsNullable(false).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
.addColumn(componentUuid)
.build());
addIndex(context, "events", "events_component_uuid", false, componentUuid);
addIndex(context, "events", "events_snapshot_id", false, snapshotId);
}

private void createQualityGates(Context context) throws SQLException {
VarcharColumnDef nameCol = newLenientVarcharBuilder("name").setLimit(100).setIsNullable(false).build();
context.execute(
newTableBuilder("quality_gates")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(nameCol)
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").setIsNullable(true).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("updated_at").setIsNullable(true).build())
.build());
addIndex(context, "quality_gates", "uniq_quality_gates", true, nameCol);
}

private void createQualityGateConditions(Context context) throws SQLException {
context.execute(
newTableBuilder("quality_gate_conditions")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newIntegerColumnDefBuilder().setColumnName("qgate_id").setIsNullable(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("metric_id").setIsNullable(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("period").setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("operator").setLimit(3).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("value_error").setLimit(64).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("value_warning").setLimit(64).setIsNullable(true).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("created_at").setIsNullable(true).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName("updated_at").setIsNullable(true).build())
.build());
}

private void createProperties(Context context) throws SQLException {
VarcharColumnDef propKey = newLenientVarcharBuilder("prop_key").setLimit(512).setIsNullable(true).build();
context.execute(
newTableBuilder("properties")
// do not define as primary key on purpose -> already set in org.sonar.db.version.v61.CreateTableProperties2
.addColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build())
.addColumn(propKey)
.addColumn(newIntegerColumnDefBuilder().setColumnName("resource_id").setIsNullable(true).build())
.addColumn(newClobColumnDefBuilder().setColumnName("text_value").setIsNullable(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("user_id").setIsNullable(true).build())
.build());
addIndex(context, "properties", "properties_key", false, propKey);
}

private void createProjectLinks(Context context) throws SQLException {
context.execute(
newTableBuilder("project_links")
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newLenientVarcharBuilder("link_type").setLimit(20).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("name").setLimit(128).setIsNullable(true).build())
.addColumn(newLenientVarcharBuilder("href").setLimit(2048).setIsNullable(false).build())
.addColumn(newLenientVarcharBuilder("component_uuid").setLimit(2048).setIsNullable(true).build())
.build());
}

private void createDuplicationsIndex(Context context) throws SQLException {
VarcharColumnDef hashCol = newLenientVarcharBuilder("hash").setLimit(50).setIsNullable(false).build();
IntegerColumnDef snapshotIdCol = newIntegerColumnDefBuilder().setColumnName("snapshot_id").setIsNullable(false).build();
context.execute(
newTableBuilder("duplications_index")
.addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(newIntegerColumnDefBuilder().setColumnName("project_snapshot_id").setIsNullable(false).build())
.addColumn(snapshotIdCol)
.addColumn(hashCol)
.addColumn(newIntegerColumnDefBuilder().setColumnName("index_in_file").setIsNullable(false).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("start_line").setIsNullable(false).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("end_line").setIsNullable(false).build())
.build());
addIndex(context, "duplications_index", "duplications_index_hash", false, hashCol);
addIndex(context, "duplications_index", "duplications_index_sid", false, snapshotIdCol);
}

private void addIndex(Context context, String table, String index, boolean unique, ColumnDef... columns) throws SQLException {
CreateIndexBuilder builder = new CreateIndexBuilder()
.setTable(table)
.setName(index)
.setUnique(unique);
for (ColumnDef column : columns) {
builder.addColumn(column);
}
context.execute(builder.build());
}

private static VarcharColumnDef.Builder newLenientVarcharBuilder(String column) {
return new VarcharColumnDef.Builder().setColumnName(column).setIgnoreOracleUnit(true);
}

private CreateTableBuilder newTableBuilder(String tableName) {
return new CreateTableBuilder(getDialect(), tableName);
}
}

+ 0
- 32
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v56/DbVersion56.java Voir le fichier

@@ -1,32 +0,0 @@
/*
* 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.v56;

import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
import org.sonar.server.platform.db.migration.version.DbVersion;

public class DbVersion56 implements DbVersion {
@Override
public void addSteps(MigrationStepRegistry registry) {
registry
.add(1, "Create initial schema", CreateInitialSchema.class)
.add(2, "Populate initial schema", PopulateInitialSchema.class);
}
}

+ 0
- 126
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v56/PopulateInitialSchema.java Voir le fichier

@@ -1,126 +0,0 @@
/*
* 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.v56;

import java.sql.SQLException;
import java.util.Date;
import org.sonar.api.utils.System2;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.Upsert;

public class PopulateInitialSchema extends DataChange {

private static final String ADMINS_GROUP = "sonar-administrators";
private static final String USERS_GROUP = "sonar-users";
private static final String ADMIN_USER = "admin";

private final System2 system2;

public PopulateInitialSchema(Database db, System2 system2) {
super(db);
this.system2 = system2;
}

@Override
public void execute(Context context) throws SQLException {
insertGroups(context);
insertGroupRoles(context);
insertAdminUser(context);
insertGroupMemberships(context);

}

private void insertGroups(Context context) throws SQLException {
truncateTable(context, "groups");

Date now = new Date(system2.now());
Upsert upsert = context.prepareUpsert("insert into groups (name, description, created_at, updated_at) values (?, ?, ?, ?)");
upsert.setString(1, ADMINS_GROUP)
.setString(2, "System administrators")
.setDate(3, now)
.setDate(4, now)
.addBatch();
upsert.setString(1, USERS_GROUP)
.setString(2, "Any new users created will automatically join this group")
.setDate(3, now)
.setDate(4, now)
.addBatch();
upsert
.execute()
.commit();
}

private static void insertGroupRoles(Context context) throws SQLException {
truncateTable(context, "group_roles");

// admin group
Upsert upsert = context.prepareUpsert("insert into group_roles (group_id, resource_id, role) values ((select id from groups where name='" + ADMINS_GROUP + "'), null, ?)");
upsert.setString(1, "admin").addBatch();
upsert.setString(1, "profileadmin").addBatch();
upsert.setString(1, "gateadmin").addBatch();
upsert.setString(1, "shareDashboard").addBatch();
upsert.setString(1, "provisioning").addBatch();
upsert
.execute()
.commit();

// anyone
upsert = context.prepareUpsert("insert into group_roles (group_id, resource_id, role) values (null, null, ?)");
upsert.setString(1, "scan").addBatch();
upsert.setString(1, "provisioning").addBatch();
upsert
.execute()
.commit();
}

private void insertAdminUser(Context context) throws SQLException {
truncateTable(context, "users");

long now = system2.now();
context.prepareUpsert("insert into users " +
"(login, name, email, external_identity, external_identity_provider, user_local, crypted_password, salt, " +
"created_at, updated_at, remember_token, remember_token_expires_at) " +
"values ('" + ADMIN_USER + "', 'Administrator', null, 'admin', 'sonarqube', ?, " +
"'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', ?, ?, null, null)")
.setBoolean(1, true)
.setLong(2, now)
.setLong(3, now)
.execute()
.commit();
}

private static void insertGroupMemberships(Context context) throws SQLException {
truncateTable(context, "groups_users");

Upsert upsert = context.prepareUpsert("insert into groups_users (user_id, group_id) values " +
"((select id from users where login='" + ADMIN_USER + "'), (select id from groups where name=?))");
upsert.setString(1, ADMINS_GROUP).addBatch();
upsert.setString(1, USERS_GROUP).addBatch();
upsert
.execute()
.commit();
}

private static void truncateTable(Context context, String table) throws SQLException {
context.prepareUpsert("truncate table " + table).execute().commit();
}

}

+ 0
- 24
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v56/package-info.java Voir le fichier

@@ -1,24 +0,0 @@
/*
* 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.server.platform.db.migration.version.v56;

import javax.annotation.ParametersAreNonnullByDefault;


+ 0
- 30
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v561/DbVersion561.java Voir le fichier

@@ -1,30 +0,0 @@
/*
* 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.v561;

import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
import org.sonar.server.platform.db.migration.version.DbVersion;

public class DbVersion561 implements DbVersion {
@Override
public void addSteps(MigrationStepRegistry registry) {
registry.add(1153, "Populate columns USERS.EXTERNAL_IDENTITY_*", UpdateUsersExternalIdentityWhenEmpty.class);
}
}

+ 0
- 69
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v561/UpdateUsersExternalIdentityWhenEmpty.java Voir le fichier

@@ -1,69 +0,0 @@
/*
* 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.v561;

import java.sql.SQLException;
import org.sonar.api.utils.System2;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;
import org.sonar.server.platform.db.migration.step.DataChange;

/**
* Update USERS.EXTERNAL_IDENTITY_PROVIDER to 'sonarqube' and USERS.EXTERNAL_IDENTITY to user's login when one of this 2 columns is null
*/
public class UpdateUsersExternalIdentityWhenEmpty extends DataChange {

private final System2 system2;

public UpdateUsersExternalIdentityWhenEmpty(Database db, System2 system2) {
super(db);
this.system2 = system2;
}

@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT u.id, u.login FROM users u WHERE external_identity_provider IS NULL OR external_identity IS NULL");
massUpdate.update("UPDATE users SET external_identity_provider=?, external_identity=?, updated_at=? WHERE id=?");
massUpdate.rowPluralName("users");
massUpdate.execute(new MigrationHandler(system2.now()));
}

private static class MigrationHandler implements MassUpdate.Handler {

private final long now;

public MigrationHandler(long now) {
this.now = now;
}

@Override
public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
update.setString(1, "sonarqube");
update.setString(2, row.getString(2));
update.setLong(3, now);
update.setLong(4, row.getLong(1));
return true;
}
}

}

+ 0
- 24
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v561/package-info.java Voir le fichier

@@ -1,24 +0,0 @@
/*
* 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.server.platform.db.migration.version.v561;

import javax.annotation.ParametersAreNonnullByDefault;


+ 0
- 45
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddAnalysisUuidColumnToCeActivity.java Voir le fichier

@@ -1,45 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
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.UUID_VARCHAR_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddAnalysisUuidColumnToCeActivity extends DdlChange {

private static final String TABLE_CE_ACTIVITY = "ce_activity";

public AddAnalysisUuidColumnToCeActivity(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_CE_ACTIVITY)
.addColumn(newVarcharColumnDefBuilder().setColumnName("analysis_uuid").setLimit(UUID_VARCHAR_SIZE).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 45
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddAnalysisUuidColumnToEvents.java Voir le fichier

@@ -1,45 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
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.UUID_VARCHAR_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddAnalysisUuidColumnToEvents extends DdlChange {

private static final String TABLE_EVENTS = "events";

public AddAnalysisUuidColumnToEvents(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_EVENTS)
.addColumn(newVarcharColumnDefBuilder().setColumnName("analysis_uuid").setLimit(UUID_VARCHAR_SIZE).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 45
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddAnalysisUuidColumnToMeasures.java Voir le fichier

@@ -1,45 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
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.UUID_VARCHAR_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddAnalysisUuidColumnToMeasures extends DdlChange {

private static final String TABLE_MEASURES = "project_measures";

public AddAnalysisUuidColumnToMeasures(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_MEASURES)
.addColumn(newVarcharColumnDefBuilder().setColumnName("analysis_uuid").setLimit(UUID_VARCHAR_SIZE).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 55
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddBColumnsToProjects.java Voir le fichier

@@ -1,55 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
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.BooleanColumnDef.newBooleanColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddBColumnsToProjects extends DdlChange {

private static final String TABLE_PROJECTS = "projects";

public AddBColumnsToProjects(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_PROJECTS)
.addColumn(newBooleanColumnDefBuilder().setColumnName("b_changed").build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("b_copy_component_uuid").setLimit(50).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("b_description").setLimit(2000).setIgnoreOracleUnit(true).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("b_enabled").build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("b_language").setLimit(20).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("b_long_name").setLimit(500).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("b_module_uuid").setLimit(50).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("b_module_uuid_path").setLimit(1500).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("b_name").setLimit(500).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("b_path").setLimit(2000).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("b_qualifier").setLimit(10).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 46
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddComponentUuidAndAnalysisUuidColumnToDuplicationsIndex.java Voir le fichier

@@ -1,46 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
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.UUID_VARCHAR_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddComponentUuidAndAnalysisUuidColumnToDuplicationsIndex extends DdlChange {

private static final String TABLE_PUBLICATIONS_INDEX = "duplications_index";

public AddComponentUuidAndAnalysisUuidColumnToDuplicationsIndex(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_PUBLICATIONS_INDEX)
.addColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("analysis_uuid").setLimit(UUID_VARCHAR_SIZE).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 45
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddComponentUuidColumnToMeasures.java Voir le fichier

@@ -1,45 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
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.UUID_VARCHAR_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddComponentUuidColumnToMeasures extends DdlChange {

private static final String TABLE_MEASURES = "project_measures";

public AddComponentUuidColumnToMeasures(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_MEASURES)
.addColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 46
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddComponentUuidColumnsToSnapshots.java Voir le fichier

@@ -1,46 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
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.UUID_VARCHAR_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddComponentUuidColumnsToSnapshots extends DdlChange {

private static final String TABLE_SNAPSHOTS = "snapshots";

public AddComponentUuidColumnsToSnapshots(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_SNAPSHOTS)
.addColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("root_component_uuid").setLimit(UUID_VARCHAR_SIZE).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 46
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddIndexOnAnalysisUuidOfMeasures.java Voir le fichier

@@ -1,46 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.IntegerColumnDef.newIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddIndexOnAnalysisUuidOfMeasures extends DdlChange {

public AddIndexOnAnalysisUuidOfMeasures(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
// this index must be present for the performance of next migration
context.execute(new CreateIndexBuilder()
.setTable("project_measures")
.setName("measures_analysis_metric")
.addColumn(newVarcharColumnDefBuilder().setColumnName("analysis_uuid").setLimit(50).setIgnoreOracleUnit(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("metric_id").build())
.build());
}
}

+ 0
- 44
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddIndexOnComponentUuidOfMeasures.java Voir le fichier

@@ -1,44 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddIndexOnComponentUuidOfMeasures extends DdlChange {

public AddIndexOnComponentUuidOfMeasures(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new CreateIndexBuilder()
.setTable("project_measures")
.setName("measures_component_uuid")
.addColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(50).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 44
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddLastUsedColumnToRulesProfiles.java Voir le fichier

@@ -1,44 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
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.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;

public class AddLastUsedColumnToRulesProfiles extends DdlChange {

private static final String TABLE_QUALITY_PROFILES = "rules_profiles";

public AddLastUsedColumnToRulesProfiles(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_QUALITY_PROFILES)
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("last_used").setIsNullable(true).build())
.build());
}

}

+ 0
- 44
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddProfileKeyToActivities.java Voir le fichier

@@ -1,44 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
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 AddProfileKeyToActivities extends DdlChange {

private static final String TABLE_ACTIVITIES = "activities";

public AddProfileKeyToActivities(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_ACTIVITIES)
.addColumn(newVarcharColumnDefBuilder().setColumnName("profile_key").setLimit(255).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 44
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddUniqueIndexOnUuidOfSnapshots.java Voir le fichier

@@ -1,44 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddUniqueIndexOnUuidOfSnapshots extends DdlChange {

public AddUniqueIndexOnUuidOfSnapshots(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new CreateIndexBuilder()
.setTable("snapshots")
.setName("analyses_uuid")
.addColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(50).setIgnoreOracleUnit(true).build())
.setUnique(true)
.build());
}
}

+ 0
- 44
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddUserUpdatedAtToRulesProfiles.java Voir le fichier

@@ -1,44 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
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.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;

public class AddUserUpdatedAtToRulesProfiles extends DdlChange {

private static final String TABLE_QUALITY_PROFILES = "rules_profiles";

public AddUserUpdatedAtToRulesProfiles(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_QUALITY_PROFILES)
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("user_updated_at").setIsNullable(true).build())
.build());
}

}

+ 0
- 45
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddUuidColumnToSnapshots.java Voir le fichier

@@ -1,45 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
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.UUID_VARCHAR_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddUuidColumnToSnapshots extends DdlChange {

private static final String TABLE_SNAPSHOTS = "snapshots";

public AddUuidColumnToSnapshots(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDialect(), TABLE_SNAPSHOTS)
.addColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(UUID_VARCHAR_SIZE).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 47
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddUuidColumnsToProjects.java Voir le fichier

@@ -1,47 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
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.UUID_VARCHAR_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddUuidColumnsToProjects extends DdlChange {

private static final String TABLE_PROJECTS = "projects";

public AddUuidColumnsToProjects(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDialect(), TABLE_PROJECTS)
.addColumn(newVarcharColumnDefBuilder().setColumnName("root_uuid").setLimit(UUID_VARCHAR_SIZE).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("copy_component_uuid").setLimit(UUID_VARCHAR_SIZE).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("developer_uuid").setLimit(UUID_VARCHAR_SIZE).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 44
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/AddUuidPathColumnToProjects.java Voir le fichier

@@ -1,44 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
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 AddUuidPathColumnToProjects extends DdlChange {

private static final String TABLE_PROJECTS = "projects";

public AddUuidPathColumnToProjects(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDialect(), TABLE_PROJECTS)
.addColumn(newVarcharColumnDefBuilder().setColumnName("uuid_path").setLimit(1500).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 45
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CleanEventsWithoutAnalysisUuid.java Voir le fichier

@@ -1,45 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.DataChange;

public class CleanEventsWithoutAnalysisUuid extends DataChange {

public CleanEventsWithoutAnalysisUuid(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT distinct snapshot_id from events e where e.snapshot_id is not null and e.analysis_uuid is null");
massUpdate.update("DELETE from events WHERE snapshot_id=?");
massUpdate.rowPluralName("no analysis uuid events");
massUpdate.execute((row, update) -> {
update.setLong(1, row.getLong(1));
return true;
});
}

}

+ 0
- 45
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CleanEventsWithoutSnapshotId.java Voir le fichier

@@ -1,45 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.DataChange;

public class CleanEventsWithoutSnapshotId extends DataChange {

public CleanEventsWithoutSnapshotId(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT e.id from events e where e.snapshot_id is null");
massUpdate.update("DELETE from events WHERE id=?");
massUpdate.rowPluralName("no snapshot id events");
massUpdate.execute((row, update) -> {
update.setLong(1, row.getLong(1));
return true;
});
}

}

+ 0
- 45
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CleanMeasuresWithNullAnalysisUuid.java Voir le fichier

@@ -1,45 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.DataChange;

public class CleanMeasuresWithNullAnalysisUuid extends DataChange {

public CleanMeasuresWithNullAnalysisUuid(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select id from project_measures where analysis_uuid is null");
massUpdate.update("delete from project_measures where id=?");
massUpdate.rowPluralName("measures");
massUpdate.execute((row, update) -> {
update.setLong(1, row.getLong(1));
return true;
});
}

}

+ 0
- 48
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CleanOrphanRowsInProjects.java Voir le fichier

@@ -1,48 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.DataChange;

public class CleanOrphanRowsInProjects extends DataChange {

public CleanOrphanRowsInProjects(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT p.id from projects p where p.root_uuid is null" +
" or (p.copy_resource_id is not null and p.copy_component_uuid is null)" +
" or (p.person_id is not null and p.developer_uuid is null)");
massUpdate.update("DELETE from projects WHERE id=?");
massUpdate.rowPluralName("orphan projects");
massUpdate.execute((row, update) -> {
long projectId = row.getLong(1);
update.setLong(1, projectId);
return true;
});
}

}

+ 0
- 62
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CleanOrphanRowsInSnapshots.java Voir le fichier

@@ -1,62 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.DataChange;

public class CleanOrphanRowsInSnapshots extends DataChange {

public CleanOrphanRowsInSnapshots(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT sn.id, sn.project_id, sn.root_project_id from snapshots sn where sn.component_uuid is null or sn.root_component_uuid is null");
massUpdate.update("DELETE from duplications_index WHERE snapshot_id=? or project_snapshot_id=?");
massUpdate.update("DELETE from project_measures WHERE snapshot_id=?");
massUpdate.update("DELETE from ce_activity WHERE snapshot_id=?");
massUpdate.update("DELETE from events WHERE snapshot_id=?");
massUpdate.update("DELETE from snapshots WHERE id=?");
massUpdate.rowPluralName("snapshots");
massUpdate.execute((row, update, updateIndex) -> {
long snapshotId = row.getLong(1);
switch (updateIndex) {
case 0:
update.setLong(1, snapshotId);
update.setLong(2, snapshotId);
return true;
case 1:
case 2:
case 3:
case 4:
update.setLong(1, snapshotId);
return true;
default:
throw new IllegalArgumentException("Unsupported update index " + updateIndex);
}
});
}

}

+ 0
- 156
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CleanUsurperRootComponents.java Voir le fichier

@@ -1,156 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.DataChange;

public class CleanUsurperRootComponents extends DataChange {

public CleanUsurperRootComponents(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
// fix snapshots which don't have the scope and/or qualifier of their associated component
fixSnapshotScopeAndQualifier(context);
// delete components declaring themselves as root in table PROJECTS but which don't have a root scope and/or qualifier
cleanUsurperRootComponents(context);
// components which has snapshots reference a component as root which is not a root
cleanSnapshotWithIncorrectRoot(context);
}

private static void fixSnapshotScopeAndQualifier(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select" +
" sn.id,p.scope,p.qualifier" +
" from" +
" snapshots sn, projects p" +
" where" +
" p.uuid = sn.component_uuid" +
" and (p.qualifier<>sn.qualifier or p.scope<>sn.scope)");
massUpdate.update("update snapshots set scope=?,qualifier=? where id=?");
massUpdate.rowPluralName("snapshots with inconsistent scope or qualifier");
massUpdate.execute((row, update) -> {
long snapshotId = row.getLong(1);
String scope = row.getString(2);
String qualifier = row.getString(3);

update.setString(1, scope);
update.setString(2, qualifier);
update.setLong(3, snapshotId);

return true;
});
}

private static void cleanUsurperRootComponents(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select p.id,p.uuid from projects p " +
" where" +
" p.project_uuid = p.uuid" +
" and not (" +
" p.scope = 'PRJ'" +
" and p.qualifier in ('TRK', 'VW', 'DEV')" +
" )");
massUpdate.update("delete from duplications_index where snapshot_id in (select id from snapshots where component_uuid=?)");
massUpdate.update("delete from project_measures where component_uuid=?");
massUpdate.update("delete from ce_activity where component_uuid=?");
massUpdate.update("delete from events where component_uuid=?");
massUpdate.update("delete from project_links where component_uuid=?");
massUpdate.update("delete from snapshots where component_uuid=? or root_component_uuid=?");
massUpdate.update("delete from issues where component_uuid=? or project_uuid=?");
massUpdate.update("delete from file_sources where file_uuid=? or project_uuid=?");
massUpdate.update("delete from group_roles where resource_id=?");
massUpdate.update("delete from user_roles where resource_id=?");
massUpdate.update("delete from properties where resource_id=?");
massUpdate.update("delete from widgets where resource_id=?");
massUpdate.update("delete from projects where uuid=?");
massUpdate.rowPluralName("usurper root components");
massUpdate.execute((row, update, updateIndex) -> {
long componentId = row.getLong(1);
String componentUuid = row.getString(2);
switch (updateIndex) {
case 0:
case 1:
case 2:
case 3:
case 4:
update.setString(1, componentUuid);
return true;
case 5:
case 6:
case 7:
update.setString(1, componentUuid);
update.setString(2, componentUuid);
return true;
case 8:
case 9:
case 10:
case 11:
update.setLong(1, componentId);
return true;
case 12:
update.setString(1, componentUuid);
return true;
default:
throw new IllegalArgumentException("Unsupported update index " + updateIndex);
}
});
}

private static void cleanSnapshotWithIncorrectRoot(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select" +
" sn.id" +
" from " +
" projects p, snapshots sn" +
" where" +
" p.uuid = sn.root_component_uuid" +
" and not (" +
" p.scope = 'PRJ'" +
" and p.qualifier in ('TRK', 'VW', 'DEV')" +
" )");
massUpdate.update("DELETE from ce_activity WHERE snapshot_id=?");
massUpdate.update("DELETE from events WHERE snapshot_id=?");
massUpdate.update("DELETE from project_measures WHERE snapshot_id=?");
massUpdate.update("DELETE from duplications_index WHERE project_snapshot_id=?");
massUpdate.update("DELETE from snapshots WHERE id=?");
massUpdate.rowPluralName("snapshots with incorrect root");
massUpdate.execute((row, update, updateIndex) -> {
long snapshotId = row.getLong(1);
switch (updateIndex) {
case 0:
case 1:
case 2:
case 3:
case 4:
update.setLong(1, snapshotId);
return true;
default:
throw new IllegalArgumentException("Unsupported update index " + updateIndex);
}
});
}

}

+ 0
- 66
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CreatePermTemplatesCharacteristics.java Voir le fichier

@@ -1,66 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
import org.sonar.server.platform.db.migration.def.IntegerColumnDef;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
import static org.sonar.server.platform.db.migration.sql.CreateTableBuilder.ColumnFlag.AUTO_INCREMENT;
import static org.sonar.server.platform.db.migration.def.IntegerColumnDef.newIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class CreatePermTemplatesCharacteristics extends DdlChange {

private static final String TABLE_NAME = "perm_tpl_characteristics";

public CreatePermTemplatesCharacteristics(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
IntegerColumnDef templateIdColumn = newIntegerColumnDefBuilder().setColumnName("template_id").setIsNullable(false).build();
VarcharColumnDef permissionKeyColumn = newVarcharColumnDefBuilder().setColumnName("permission_key").setLimit(64).setIsNullable(false).setIgnoreOracleUnit(true).build();
context.execute(
new CreateTableBuilder(getDialect(), TABLE_NAME)
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(templateIdColumn)
.addColumn(permissionKeyColumn)
.addColumn(newBooleanColumnDefBuilder().setColumnName("with_project_creator").setIsNullable(false).setDefaultValue(false).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").setIsNullable(false).build())
.build());

context.execute(new CreateIndexBuilder()
.setTable(TABLE_NAME)
.setName("uniq_perm_tpl_charac")
.setUnique(true)
.addColumn(templateIdColumn)
.addColumn(permissionKeyColumn)
.build());
}
}

+ 0
- 51
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/CreateTemporaryIndicesFor1211.java Voir le fichier

@@ -1,51 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.IntegerColumnDef.newIntegerColumnDefBuilder;

public class CreateTemporaryIndicesFor1211 extends DdlChange {

static final String INDEX_ON_CE_ACTIVITY = "ce_activity_snapshot_id";
static final String INDEX_ON_DUPLICATIONS_INDEX = "dup_index_psid";

public CreateTemporaryIndicesFor1211(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new CreateIndexBuilder()
.setTable("ce_activity")
.setName(INDEX_ON_CE_ACTIVITY)
.addColumn(newIntegerColumnDefBuilder().setColumnName("snapshot_id").build())
.build());
context.execute(new CreateIndexBuilder()
.setTable("duplications_index")
.setName(INDEX_ON_DUPLICATIONS_INDEX)
.addColumn(newIntegerColumnDefBuilder().setColumnName("project_snapshot_id").build())
.build());
}
}

+ 0
- 110
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DbVersion60.java Voir le fichier

@@ -1,110 +0,0 @@
/*
* 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.v60;

import java.util.stream.Stream;
import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
import org.sonar.server.platform.db.migration.version.DbVersion;

public class DbVersion60 implements DbVersion {
@Override
public Stream<Object> getSupportComponents() {
return Stream.of(
// Migration1223
FixProjectUuidOfDeveloperProjects.class,
CleanUsurperRootComponents.class);
}

@Override
public void addSteps(MigrationStepRegistry registry) {
registry
.add(1200, "Create table PERM_TPL_CHARACTERISTICS", CreatePermTemplatesCharacteristics.class)
.add(1205, "Drop index resource_index_rid from RESOURCE_INDEX", DropResourceIndexRidFromResourceIndex.class)
.add(1207, "Drop unused columns on PROJECT_MEASURES", DropUnusedMeasuresColumns.class)
.add(1208, "Add columns SNAPSHOTS.*COMPONENT_UUID", AddComponentUuidColumnsToSnapshots.class)
.add(1209, "Populate column SNAPSHOTS.*COMPONENT_UUID", PopulateComponentUuidColumnsOfSnapshots.class)
.add(1210, "Create temporary indices for migration 1211", CreateTemporaryIndicesFor1211.class)
.add(1211, "Clean orphan rows in SNAPSHOTS", CleanOrphanRowsInSnapshots.class)
.add(1212, "Drop temporary indices for migration 1211", DropTemporaryIndicesOf1210.class)
.add(1213, "Make column SNAPSHOTS.UUID not nullable", MakeComponentUuidColumnsNotNullOnSnapshots.class)
.add(1214, "Drop columns SNAPSHOTS.SNAPSHOT_*_ID", DropSnapshotProjectIdFromSnapshots.class)
.add(1215, "Drop columns SNAPSHOTS.*_ID", DropIdColumnsFromSnapshots.class)
.add(1216, "Add column PROJECT_MEASURES.COMPONENT_UUID", AddComponentUuidColumnToMeasures.class)
.add(1217, "Populate column PROJECT_MEASURES.COMPONENT_UUID", PopulateComponentUuidOfMeasures.class)
.add(1218, "Delete orphan measures without component", DeleteOrphanMeasuresWithoutComponent.class)
.add(1219, "Make column PROJECT_MEASURES.COMPONENT_UUID not nullable", MakeComponentUuidNotNullOnMeasures.class)
.add(1220, "Drop column PROJECT_MEASURES.PROJECT_ID", DropProjectIdColumnFromMeasures.class)
.add(1221, "Add index measures_component_uuid", AddIndexOnComponentUuidOfMeasures.class)
.add(1222, "Drop columns USERS.REMEMBER_TOKEN_*", DropRememberMeColumnsFromUsers.class)
.add(1223, "Clean orphan rows and fix incorrect data in table PROJECTS", Migration1223.class)
.add(1224, "Add columns PROJECTS.*_UUID", AddUuidColumnsToProjects.class)
.add(1225, "Populate columns PROJECTS.*_UUID", PopulateUuidColumnsOfProjects.class)
.add(1226, "Clean orphan rows in table PROJECTS", CleanOrphanRowsInProjects.class)
.add(1227, "Drop index projects_uuid", DropIndexProjectsUuidFromProjects.class)
.add(1228, "Make columns PROJECTS.*_UUID not nullable", MakeUuidColumnsNotNullOnProjects.class)
.add(1229, "Recreate index projects_uuid", RecreateIndexProjectsUuidFromProjects.class)
.add(1230, "Drop index projects_root_id", DropIndexProjectsRootIdFromProjects.class)
.add(1231, "Drop columns PROJECTS.*_ID", DropIdColumnsFromProjects.class)
.add(1232, "Add column SNAPSHOTS.UUID", AddUuidColumnToSnapshots.class)
.add(1233, "Populate column SNAPSHOTS.UUID", PopulateUuidColumnOnSnapshots.class)
.add(1234, "Make column SNAPSHOTS.UUID not nullable", MakeUuidColumnNotNullOnSnapshots.class)
.add(1235, "Add unique index analyses_uuid", AddUniqueIndexOnUuidOfSnapshots.class)
.add(1236, "Add column CE_ACTIVITY.ANALYSIS_UUID", AddAnalysisUuidColumnToCeActivity.class)
.add(1237, "Populate column CE_ACTIVITY.ANALYSIS_UUID", PopulateAnalysisUuidColumnOnCeActivity.class)
.add(1238, "Drop column CE_ACTIVITY.SNAPSHOT_ID", DropSnapshotIdColumnFromCeActivity.class)
.add(1239, "Add columns DUPLICATION_INDEX.*_UUID", AddComponentUuidAndAnalysisUuidColumnToDuplicationsIndex.class)
.add(1240, "Populate columns DUPLICATION_INDEX.*_UUID", PopulateComponentUuidAndAnalysisUuidOfDuplicationsIndex.class)
.add(1241, "Clean orphan rows in table DUPLICATION_INDEX", DeleteOrphanDuplicationsIndexRowsWithoutComponentOrAnalysis.class)
.add(1242, "Make columns DUPLICATION_INDEX.*_UUID not nullable", MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex.class)
.add(1243, "Drop index duplications_index_sid", DropIndexDuplicationsIndexSidFromDuplicationsIndex.class)
.add(1244, "Drop columns DUPLICATION_INDEX.*SNAPSHOT_ID", DropSnapshotIdColumnsFromDuplicationsIndex.class)
.add(1246, "Add column RULES_PROFILES.LAST_USED", AddLastUsedColumnToRulesProfiles.class)
.add(1247, "Populate column RULES_PROFILES.LAST_USED", PopulateLastUsedColumnOfRulesProfiles.class)
.add(1248, "Add column EVENTS.ANALYSIS_UUID", AddAnalysisUuidColumnToEvents.class)
.add(1249, "Populate column EVENTS.ANALYSIS_UUID", PopulateAnalysisUuidOnEvents.class)
.add(1250, "Clean events without analysis_uuid", CleanEventsWithoutAnalysisUuid.class)
.add(1251, "Clean events without snapshot_id", CleanEventsWithoutSnapshotId.class)
.add(1252, "Make column EVENTS.ANALYSIS_UUID not nullable", MakeAnalysisUuidNotNullOnEvents.class)
.add(1253, "Drop index events_snapshot_id", DropIndexEventsSnapshotIdFromEvents.class)
.add(1254, "Drop columns EVENTS.SNAPSHOT_ID", DropSnapshotIdColumnFromEvents.class)
.add(1256, "Add column PROJECTS.UUID_PATH", AddUuidPathColumnToProjects.class)
.add(1257, "Populate column PROJECTS.UUID_PATH", PopulateUuidPathColumnOnProjects.class)
.add(1258, "Make column PROJECTS.UUID_PATH not nullable", MakeUuidPathColumnNotNullOnProjects.class)
.add(1259, "Remove password of non local users", RemoveUsersPasswordWhenNotLocal.class)
.add(1260, "Add column ACTIVITIES.PROFILE_KEY", AddProfileKeyToActivities.class)
.add(1261, "Populate column ACTIVITIES.PROFILE_KEY", PopulateProfileKeyOfActivities.class)
.add(1262, "Make column ACTIVITIES.PROFILE_KEY not nullable", MakeProfileKeyNotNullOnActivities.class)
.add(1263, "Add column RULES_PROFILES.USER_UPDATED_AT", AddUserUpdatedAtToRulesProfiles.class)
.add(1264, "Populate column RULES_PROFILES.USER_UPDATED_AT", PopulateUserUpdatedAtOfRulesProfiles.class)
.add(1265, "Add column PROJECT_MEASURES.ANALYSIS_UUID", AddAnalysisUuidColumnToMeasures.class)
.add(1266, "Add index measures_analysis_metric", AddIndexOnAnalysisUuidOfMeasures.class)
.add(1267, "Populate column PROJECT_MEASURES.ANALYSIS_UUID", PopulateAnalysisUuidOnMeasures.class)
.add(1268, "Clean orphan measures", CleanMeasuresWithNullAnalysisUuid.class)
.add(1269, "Temporary drop of index measures_analysis_metric", TemporarilyDropIndexOfAnalysisUuidOnMeasures.class)
.add(1270, "Make column PROJECT_MEASURES.ANALYSIS_UUID not nullable", MakeAnalysisUuidNotNullOnMeasures.class)
.add(1271, "Restore index measures_analysis_metric", AddIndexOnAnalysisUuidOfMeasures.class)
.add(1272, "Delete snapshots but the one of root components", DropTreesOfSnapshots.class)
.add(1273, "Drop indices on tree columns of table SNAPSHOTS", DropIndicesOnTreeColumnsOfSnapshots.class)
.add(1274, "Drop tree columns of table SNAPSHOTS", DropTreeColumnsFromSnapshots.class)
.add(1275, "Drop index measures_sid_metric", DropIndexOnSnapshotIdOfMeasures.class)
.add(1276, "Drop column PROJECT_MEASURES.SNAPSHOT_ID", DropSnapshotIdColumnFromMeasures.class)
.add(1277, "Add columns PROJECTS.B_*", AddBColumnsToProjects.class);
}
}

+ 0
- 61
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DeleteOrphanDuplicationsIndexRowsWithoutComponentOrAnalysis.java Voir le fichier

@@ -1,61 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.DataChange;

public class DeleteOrphanDuplicationsIndexRowsWithoutComponentOrAnalysis extends DataChange {

public DeleteOrphanDuplicationsIndexRowsWithoutComponentOrAnalysis(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
deleteRowsWithoutComponentUuid(context);
deleteRowsWithoutAnalysisUuid(context);
}

private static void deleteRowsWithoutComponentUuid(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT id from duplications_index where component_uuid is null");
massUpdate.update("DELETE from duplications_index WHERE id=?");
massUpdate.rowPluralName("duplications index rows without component");
massUpdate.execute((row, update) -> {
update.setLong(1, row.getLong(1));
return true;
});
}

private static void deleteRowsWithoutAnalysisUuid(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT distinct project_snapshot_id from duplications_index where analysis_uuid is null");
massUpdate.update("DELETE from duplications_index WHERE project_snapshot_id=?");
massUpdate.rowPluralName("duplications index rows without analysis");
massUpdate.execute((row, update) -> {
update.setLong(1, row.getLong(1));
return true;
});
}

}

+ 0
- 45
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DeleteOrphanMeasuresWithoutComponent.java Voir le fichier

@@ -1,45 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.DataChange;

public class DeleteOrphanMeasuresWithoutComponent extends DataChange {

public DeleteOrphanMeasuresWithoutComponent(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT id from project_measures where component_uuid is null");
massUpdate.update("DELETE from project_measures WHERE id=?");
massUpdate.rowPluralName("measures");
massUpdate.execute((row, update) -> {
update.setLong(1, row.getLong(1));
return true;
});
}

}

+ 0
- 44
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIdColumnsFromProjects.java Voir le fichier

@@ -1,44 +0,0 @@
/*
* 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.v60;

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 DropIdColumnsFromProjects extends DdlChange {

private static final String TABLE_PROJECTS = "projects";

public DropIdColumnsFromProjects(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(
new DropColumnsBuilder(
getDialect(), TABLE_PROJECTS,
"root_id", "copy_resource_id", "person_id")
.build());
}

}

+ 0
- 44
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIdColumnsFromSnapshots.java Voir le fichier

@@ -1,44 +0,0 @@
/*
* 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.v60;

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 DropIdColumnsFromSnapshots extends DdlChange {

private static final String TABLE_SNAPSHOTS = "snapshots";

public DropIdColumnsFromSnapshots(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(
new DropColumnsBuilder(
getDatabase().getDialect(), TABLE_SNAPSHOTS,
"project_id", "root_project_id")
.build());
}

}

+ 0
- 39
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIndexDuplicationsIndexSidFromDuplicationsIndex.java Voir le fichier

@@ -1,39 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropIndexDuplicationsIndexSidFromDuplicationsIndex extends DdlChange {
public DropIndexDuplicationsIndexSidFromDuplicationsIndex(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropIndexBuilder(getDialect())
.setTable("duplications_index")
.setName("duplications_index_sid")
.build());
}
}

+ 0
- 39
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIndexEventsSnapshotIdFromEvents.java Voir le fichier

@@ -1,39 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropIndexEventsSnapshotIdFromEvents extends DdlChange {
public DropIndexEventsSnapshotIdFromEvents(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropIndexBuilder(getDialect())
.setTable("events")
.setName("events_snapshot_id")
.build());
}
}

+ 0
- 39
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIndexOnSnapshotIdOfMeasures.java Voir le fichier

@@ -1,39 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropIndexOnSnapshotIdOfMeasures extends DdlChange {
public DropIndexOnSnapshotIdOfMeasures(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropIndexBuilder(getDialect())
.setTable("project_measures")
.setName("measures_sid_metric")
.build());
}
}

+ 0
- 39
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIndexProjectsRootIdFromProjects.java Voir le fichier

@@ -1,39 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropIndexProjectsRootIdFromProjects extends DdlChange {
public DropIndexProjectsRootIdFromProjects(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropIndexBuilder(getDialect())
.setTable("projects")
.setName("projects_root_id")
.build());
}
}

+ 0
- 39
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIndexProjectsUuidFromProjects.java Voir le fichier

@@ -1,39 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropIndexProjectsUuidFromProjects extends DdlChange {
public DropIndexProjectsUuidFromProjects(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropIndexBuilder(getDialect())
.setTable("projects")
.setName("projects_uuid")
.build());
}
}

+ 0
- 46
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropIndicesOnTreeColumnsOfSnapshots.java Voir le fichier

@@ -1,46 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropIndicesOnTreeColumnsOfSnapshots extends DdlChange {
public DropIndicesOnTreeColumnsOfSnapshots(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
dropIndex(context, "snapshots_qualifier");
dropIndex(context, "snapshots_root");
dropIndex(context, "snapshots_parent");
dropIndex(context, "snapshot_root_component");
}

private void dropIndex(Context context, String index) throws SQLException {
context.execute(new DropIndexBuilder(getDialect())
.setTable("snapshots")
.setName(index)
.build());
}
}

+ 0
- 41
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropProjectIdColumnFromMeasures.java Voir le fichier

@@ -1,41 +0,0 @@
/*
* 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.v60;

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 DropProjectIdColumnFromMeasures extends DdlChange {

private static final String TABLE_MEASURES = "project_measures";

public DropProjectIdColumnFromMeasures(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(
new DropColumnsBuilder(getDatabase().getDialect(), TABLE_MEASURES, "project_id").build());
}

}

+ 0
- 40
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropRememberMeColumnsFromUsers.java Voir le fichier

@@ -1,40 +0,0 @@
/*
* 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.v60;

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 DropRememberMeColumnsFromUsers extends DdlChange {

private static final String TABLE_USERS = "users";

public DropRememberMeColumnsFromUsers(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropColumnsBuilder(getDialect(), TABLE_USERS, "remember_token", "remember_token_expires_at").build());
}

}

+ 0
- 41
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropResourceIndexRidFromResourceIndex.java Voir le fichier

@@ -1,41 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropResourceIndexRidFromResourceIndex extends DdlChange {

public DropResourceIndexRidFromResourceIndex(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropIndexBuilder(getDialect())
.setTable("resource_index")
.setName("resource_index_rid")
.build());
}

}

+ 0
- 44
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropSnapshotIdColumnFromCeActivity.java Voir le fichier

@@ -1,44 +0,0 @@
/*
* 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.v60;

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 DropSnapshotIdColumnFromCeActivity extends DdlChange {

private static final String TABLE_CE_ACTIVITY = "ce_activity";

public DropSnapshotIdColumnFromCeActivity(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(
new DropColumnsBuilder(
getDatabase().getDialect(), TABLE_CE_ACTIVITY,
"snapshot_id")
.build());
}

}

+ 0
- 40
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropSnapshotIdColumnFromEvents.java Voir le fichier

@@ -1,40 +0,0 @@
/*
* 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.v60;

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 DropSnapshotIdColumnFromEvents extends DdlChange {

private static final String TABLE_EVENTS = "events";

public DropSnapshotIdColumnFromEvents(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropColumnsBuilder(getDatabase().getDialect(), TABLE_EVENTS, "snapshot_id").build());
}

}

+ 0
- 40
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropSnapshotIdColumnFromMeasures.java Voir le fichier

@@ -1,40 +0,0 @@
/*
* 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.v60;

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 DropSnapshotIdColumnFromMeasures extends DdlChange {

private static final String TABLE = "project_measures";

public DropSnapshotIdColumnFromMeasures(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropColumnsBuilder(getDatabase().getDialect(), TABLE, "snapshot_id").build());
}

}

+ 0
- 41
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropSnapshotIdColumnsFromDuplicationsIndex.java Voir le fichier

@@ -1,41 +0,0 @@
/*
* 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.v60;

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 DropSnapshotIdColumnsFromDuplicationsIndex extends DdlChange {

private static final String TABLE_DUPLICATIONS_INDEX = "duplications_index";

public DropSnapshotIdColumnsFromDuplicationsIndex(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(
new DropColumnsBuilder(getDialect(), TABLE_DUPLICATIONS_INDEX, "project_snapshot_id", "snapshot_id").build());
}

}

+ 0
- 46
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropSnapshotProjectIdFromSnapshots.java Voir le fichier

@@ -1,46 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropSnapshotProjectIdFromSnapshots extends DdlChange {

private static final String TABLE_SNAPSHOTS = "snapshots";

public DropSnapshotProjectIdFromSnapshots(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropIndexBuilder(getDialect())
.setTable(TABLE_SNAPSHOTS)
.setName("snapshot_project_id")
.build());
context.execute(new DropIndexBuilder(getDialect())
.setTable(TABLE_SNAPSHOTS)
.setName("snapshots_root_project_id")
.build());
}
}

+ 0
- 46
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropTemporaryIndicesOf1210.java Voir le fichier

@@ -1,46 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropTemporaryIndicesOf1210 extends DdlChange {

public DropTemporaryIndicesOf1210(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropIndexBuilder(getDialect())
.setTable("ce_activity")
.setName(CreateTemporaryIndicesFor1211.INDEX_ON_CE_ACTIVITY)
.build());

context.execute(new DropIndexBuilder(getDialect())
.setTable("duplications_index")
.setName(CreateTemporaryIndicesFor1211.INDEX_ON_DUPLICATIONS_INDEX)
.build());
}

}

+ 0
- 41
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropTreeColumnsFromSnapshots.java Voir le fichier

@@ -1,41 +0,0 @@
/*
* 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.v60;

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 DropTreeColumnsFromSnapshots extends DdlChange {

private static final String TABLE = "snapshots";

public DropTreeColumnsFromSnapshots(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
String[] columns = {"parent_snapshot_id", "scope", "qualifier", "root_snapshot_id", "path", "depth", "root_component_uuid"};
context.execute(new DropColumnsBuilder(getDatabase().getDialect(), TABLE, columns).build());
}

}

+ 0
- 50
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropTreesOfSnapshots.java Voir le fichier

@@ -1,50 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;
import org.sonar.server.platform.db.migration.step.DataChange;

public class DropTreesOfSnapshots extends DataChange {

public DropTreesOfSnapshots(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select id from snapshots where depth > 0");
massUpdate.update("delete from snapshots where id=?");
massUpdate.rowPluralName("snapshots");
massUpdate.execute(DropTreesOfSnapshots::handle);
}

private static boolean handle(Select.Row row, SqlStatement update) throws SQLException {
long id = row.getLong(1);
update.setLong(1, id);
return true;
}

}

+ 0
- 58
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/DropUnusedMeasuresColumns.java Voir le fichier

@@ -1,58 +0,0 @@
/*
* 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.v60;

import com.google.common.annotations.VisibleForTesting;
import java.sql.SQLException;
import java.util.List;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

/**
* Drop the following columns from the project_measures table :
* - rule_category_id
* - tendency
* - url
* - measure_date
* - url
* - rule_priority
* - rule_id
* - Characteristic_id
*/
public class DropUnusedMeasuresColumns extends DdlChange {

public DropUnusedMeasuresColumns(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(generateSql());
}

@VisibleForTesting
List<String> generateSql() {
return new DropColumnsBuilder(getDatabase().getDialect(), "project_measures",
"rules_category_id", "tendency", "measure_date", "url", "rule_priority", "characteristic_id", "rule_id")
.build();
}

}

+ 0
- 53
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/FixProjectUuidOfDeveloperProjects.java Voir le fichier

@@ -1,53 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;
import org.sonar.server.platform.db.migration.step.DataChange;

public class FixProjectUuidOfDeveloperProjects extends DataChange {

public FixProjectUuidOfDeveloperProjects(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select distinct p.person_id,d.uuid from projects p, projects d where p.qualifier = 'DEV_PRJ' and p.project_uuid != d.uuid and d.id = p.person_id");
massUpdate.update("update projects set project_uuid = ? where person_id = ? and qualifier = 'DEV_PRJ' and project_uuid != ?");
massUpdate.rowPluralName("developers with incorrect project_uuid");
massUpdate.execute(FixProjectUuidOfDeveloperProjects::handleComponent);
}

private static boolean handleComponent(Select.Row row, SqlStatement update) throws SQLException {
long personId = row.getLong(1);
String developerUuid = row.getString(2);
update.setString(1, developerUuid);
update.setLong(2, personId);
update.setString(3, developerUuid);

return true;
}
}

+ 0
- 59
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeAnalysisUuidNotNullOnEvents.java Voir le fichier

@@ -1,59 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_VARCHAR_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class MakeAnalysisUuidNotNullOnEvents extends DdlChange {

private static final String TABLE_EVENTS = "events";

public MakeAnalysisUuidNotNullOnEvents(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
VarcharColumnDef analysisUuidColumn = newVarcharColumnDefBuilder()
.setColumnName("analysis_uuid")
.setLimit(UUID_VARCHAR_SIZE)
.setIsNullable(false)
.setIgnoreOracleUnit(true)
.build();
context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE_EVENTS)
.updateColumn(analysisUuidColumn)
.build());

context.execute(new CreateIndexBuilder()
.setTable(TABLE_EVENTS)
.setName("events_analysis")
.addColumn(analysisUuidColumn)
.build());
}

}

+ 0
- 45
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeAnalysisUuidNotNullOnMeasures.java Voir le fichier

@@ -1,45 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_VARCHAR_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class MakeAnalysisUuidNotNullOnMeasures extends DdlChange {

private static final String TABLE_MEASURES = "project_measures";

public MakeAnalysisUuidNotNullOnMeasures(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE_MEASURES)
.updateColumn(newVarcharColumnDefBuilder().setColumnName("analysis_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 66
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex.java Voir le fichier

@@ -1,66 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_VARCHAR_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex extends DdlChange {

private static final String TABLE_DUPLICATIONS_INDEX = "duplications_index";

public MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
VarcharColumnDef analysisUuid = newUuidColumn("analysis_uuid");
VarcharColumnDef componentUuid = newUuidColumn("component_uuid");
context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE_DUPLICATIONS_INDEX)
.updateColumn(componentUuid)
.updateColumn(analysisUuid)
.build());

context.execute(new CreateIndexBuilder()
.setTable(TABLE_DUPLICATIONS_INDEX)
.setName("duplication_analysis_component")
.addColumn(analysisUuid)
.addColumn(componentUuid)
.build());
}

private static VarcharColumnDef newUuidColumn(String columnName) {
return newVarcharColumnDefBuilder()
.setColumnName(columnName)
.setLimit(UUID_VARCHAR_SIZE)
.setIsNullable(false)
.setIgnoreOracleUnit(true)
.build();
}

}

+ 0
- 70
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeComponentUuidColumnsNotNullOnSnapshots.java Voir le fichier

@@ -1,70 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_VARCHAR_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class MakeComponentUuidColumnsNotNullOnSnapshots extends DdlChange {

private static final String TABLE_SNAPSHOTS = "snapshots";

public MakeComponentUuidColumnsNotNullOnSnapshots(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
VarcharColumnDef componentUuid = newUuidColumn("component_uuid");
VarcharColumnDef rootComponentUuid = newUuidColumn("root_component_uuid");
context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE_SNAPSHOTS)
.updateColumn(componentUuid)
.updateColumn(rootComponentUuid)
.build());

context.execute(new CreateIndexBuilder()
.setTable(TABLE_SNAPSHOTS)
.setName("snapshot_component")
.addColumn(componentUuid)
.build());
context.execute(new CreateIndexBuilder()
.setTable(TABLE_SNAPSHOTS)
.setName("snapshot_root_component")
.addColumn(rootComponentUuid)
.build());
}

private static VarcharColumnDef newUuidColumn(String columnName) {
return newVarcharColumnDefBuilder()
.setColumnName(columnName)
.setLimit(UUID_VARCHAR_SIZE)
.setIsNullable(false)
.setIgnoreOracleUnit(true)
.build();
}

}

+ 0
- 45
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeComponentUuidNotNullOnMeasures.java Voir le fichier

@@ -1,45 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_VARCHAR_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class MakeComponentUuidNotNullOnMeasures extends DdlChange {

private static final String TABLE_MEASURES = "project_measures";

public MakeComponentUuidNotNullOnMeasures(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE_MEASURES)
.updateColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 44
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeProfileKeyNotNullOnActivities.java Voir le fichier

@@ -1,44 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class MakeProfileKeyNotNullOnActivities extends DdlChange {

private static final String TABLE_ACTIVITIES = "activities";

public MakeProfileKeyNotNullOnActivities(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE_ACTIVITIES)
.updateColumn(newVarcharColumnDefBuilder().setColumnName("profile_key").setLimit(255).setIsNullable(false).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 45
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeUuidColumnNotNullOnSnapshots.java Voir le fichier

@@ -1,45 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_VARCHAR_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class MakeUuidColumnNotNullOnSnapshots extends DdlChange {

private static final String TABLE_SNAPSHOTS = "snapshots";

public MakeUuidColumnNotNullOnSnapshots(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE_SNAPSHOTS)
.updateColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 55
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeUuidColumnsNotNullOnProjects.java Voir le fichier

@@ -1,55 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_VARCHAR_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class MakeUuidColumnsNotNullOnProjects extends DdlChange {

private static final String TABLE_PROJECTS = "projects";

public MakeUuidColumnsNotNullOnProjects(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
VarcharColumnDef rootUuid = newVarcharColumnDefBuilder().setColumnName("root_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build();
context.execute(new AlterColumnsBuilder(getDialect(), TABLE_PROJECTS)
.updateColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).setIgnoreOracleUnit(true).build())
.updateColumn(rootUuid)
.build());

context.execute(new CreateIndexBuilder()
.setTable(TABLE_PROJECTS)
.setName("projects_root_uuid")
.addColumn(rootUuid)
.build());
}

}

+ 0
- 44
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/MakeUuidPathColumnNotNullOnProjects.java Voir le fichier

@@ -1,44 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class MakeUuidPathColumnNotNullOnProjects extends DdlChange {

private static final String TABLE_PROJECTS = "projects";

public MakeUuidPathColumnNotNullOnProjects(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AlterColumnsBuilder(getDialect(), TABLE_PROJECTS)
.updateColumn(newVarcharColumnDefBuilder().setColumnName("uuid_path").setLimit(1500).setIsNullable(false).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 43
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/Migration1223.java Voir le fichier

@@ -1,43 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.server.platform.db.migration.step.MigrationStep;

/**
* This migration step is a substitute for the Ruby migration file which called two java migrations:
* {@link FixProjectUuidOfDeveloperProjects} and {@link CleanUsurperRootComponents}.
*/
public class Migration1223 implements MigrationStep {
private final FixProjectUuidOfDeveloperProjects projectUuidOfDeveloperProjects;
private final CleanUsurperRootComponents cleanUsurperRootComponents;

public Migration1223(FixProjectUuidOfDeveloperProjects projectUuidOfDeveloperProjects, CleanUsurperRootComponents cleanUsurperRootComponents) {
this.projectUuidOfDeveloperProjects = projectUuidOfDeveloperProjects;
this.cleanUsurperRootComponents = cleanUsurperRootComponents;
}

@Override
public void execute() throws SQLException {
projectUuidOfDeveloperProjects.execute();
cleanUsurperRootComponents.execute();
}
}

+ 0
- 54
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidColumnOnCeActivity.java Voir le fichier

@@ -1,54 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;
import org.sonar.server.platform.db.migration.step.DataChange;

public class PopulateAnalysisUuidColumnOnCeActivity extends DataChange {

public PopulateAnalysisUuidColumnOnCeActivity(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT a.id, s.uuid from ce_activity a inner join snapshots s on s.id=a.snapshot_id where a.snapshot_id is not null and a.analysis_uuid is null");
massUpdate.update("UPDATE ce_activity SET analysis_uuid=? WHERE id=?");
massUpdate.rowPluralName("ce_activity");
massUpdate.execute(PopulateAnalysisUuidColumnOnCeActivity::handle);
}

private static boolean handle(Select.Row row, SqlStatement update) throws SQLException {
long id = row.getLong(1);
String analysisUuid = row.getString(2);

update.setString(1, analysisUuid);
update.setLong(2, id);

return true;
}

}

+ 0
- 55
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnEvents.java Voir le fichier

@@ -1,55 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;
import org.sonar.server.platform.db.migration.step.DataChange;

public class PopulateAnalysisUuidOnEvents extends DataChange {

public PopulateAnalysisUuidOnEvents(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT distinct e.snapshot_id, s.uuid from events e" +
" inner join snapshots s on s.id=e.snapshot_id and s.scope = 'PRJ' and s.qualifier in ('TRK', 'DEV', 'VW')" +
" where e.snapshot_id is not null and e.analysis_uuid is null");
massUpdate.update("UPDATE events SET analysis_uuid=? WHERE snapshot_id=? and analysis_uuid is null");
massUpdate.rowPluralName("analysis uuid of root component events");
massUpdate.execute(PopulateAnalysisUuidOnEvents::handle);
}

private static boolean handle(Select.Row row, SqlStatement update) throws SQLException {
long snapshotId = row.getLong(1);
String snapshotUuid = row.getString(2);

update.setString(1, snapshotUuid);
update.setLong(2, snapshotId);

return true;
}
}

+ 0
- 74
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnMeasures.java Voir le fichier

@@ -1,74 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;

public class PopulateAnalysisUuidOnMeasures extends DataChange {

public PopulateAnalysisUuidOnMeasures(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
Map<Long, String> rootSnapshotUuids = loadRootSnapshotUuids(context);


MassUpdate massUpdate = context.prepareMassUpdate();
// mysql can take hours if the 2 requests are merged into a single one
massUpdate.select("select distinct m.snapshot_id as sId, s.root_snapshot_id as rootSid " +
"from project_measures m " +
"inner join snapshots s on m.snapshot_id = s.id " +
"where m.analysis_uuid is null"
);
massUpdate.update("update project_measures set analysis_uuid=? where snapshot_id = ? and analysis_uuid is null");
massUpdate.rowPluralName("measures");
massUpdate.execute((row, update) -> handleRow(row, update, rootSnapshotUuids));
}

private static Map<Long, String> loadRootSnapshotUuids(Context context) throws SQLException {
Map<Long, String> snapshotUuidsByIds = new HashMap<>();
context.prepareSelect("select distinct id, uuid from snapshots where depth=0")
.scroll(row -> snapshotUuidsByIds.put(row.getLong(1), row.getString(2)));
return snapshotUuidsByIds;
}

private static boolean handleRow(Select.Row row, SqlStatement update, Map<Long, String> rootSnapshotUuids) throws SQLException {
long snapshotId = row.getLong(1);
Long rootSnapshotId = row.getNullableLong(2);
String analysisUuid = rootSnapshotUuids.get(rootSnapshotId == null ? snapshotId : rootSnapshotId);
if (analysisUuid == null) {
return false;
}

update.setString(1, analysisUuid);
update.setLong(2, snapshotId);
return true;
}

}

+ 0
- 81
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateComponentUuidAndAnalysisUuidOfDuplicationsIndex.java Voir le fichier

@@ -1,81 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;
import org.sonar.server.platform.db.migration.step.DataChange;

public class PopulateComponentUuidAndAnalysisUuidOfDuplicationsIndex extends DataChange {

public PopulateComponentUuidAndAnalysisUuidOfDuplicationsIndex(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
populateComponentUuid(context);
populateAnalysisUuid(context);
}

private static void populateComponentUuid(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select distinct di.snapshot_id, s.component_uuid from duplications_index di" +
" inner join snapshots s on s.id=di.snapshot_id" +
" where di.component_uuid is null");
massUpdate.update("UPDATE duplications_index SET component_uuid=? WHERE snapshot_id=? and component_uuid is null");
massUpdate.rowPluralName("component uuid of duplications_index entries");
massUpdate.execute(PopulateComponentUuidAndAnalysisUuidOfDuplicationsIndex::handleComponentUuid);
}

private static boolean handleComponentUuid(Select.Row row, SqlStatement update) throws SQLException {
long snapshotId = row.getLong(1);
String componentUuid = row.getString(2);

update.setString(1, componentUuid);
update.setLong(2, snapshotId);

return true;
}

private static void populateAnalysisUuid(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select distinct di.project_snapshot_id, s.uuid from duplications_index di" +
" inner join snapshots s on s.id=di.project_snapshot_id" +
" where di.analysis_uuid is null");
massUpdate.update("UPDATE duplications_index SET analysis_uuid=? WHERE project_snapshot_id=? and analysis_uuid is null");
massUpdate.rowPluralName("analysis uuid of duplications_index entries");
massUpdate.execute(PopulateComponentUuidAndAnalysisUuidOfDuplicationsIndex::handleAnalysisUuid);
}

private static boolean handleAnalysisUuid(Select.Row row, SqlStatement update) throws SQLException {
long projectSnapshotId = row.getLong(1);
String snapshotUuid = row.getString(2);

update.setString(1, snapshotUuid);
update.setLong(2, projectSnapshotId);

return true;
}

}

+ 0
- 85
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateComponentUuidColumnsOfSnapshots.java Voir le fichier

@@ -1,85 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;
import org.sonar.server.platform.db.migration.step.DataChange;

public class PopulateComponentUuidColumnsOfSnapshots extends DataChange {

public PopulateComponentUuidColumnsOfSnapshots(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
Map<Long, String> componentUuidById = buildComponentUuidMap(context);
if (componentUuidById.isEmpty()) {
return;
}

populateUuidColumns(context, componentUuidById);
}

private static Map<Long, String> buildComponentUuidMap(Context context) throws SQLException {
Map<Long, String> componentUuidById = new HashMap<>();
context.prepareSelect("select distinct p.id, p.uuid from projects p" +
" join snapshots sn1 on sn1.project_id = p.id and sn1.component_uuid is null")
.scroll(row -> componentUuidById.put(row.getLong(1), row.getString(2)));
context.prepareSelect("select distinct p.id, p.uuid from projects p" +
" join snapshots sn2 on sn2.root_project_id = p.id and sn2.root_component_uuid is null")
.scroll(row -> componentUuidById.put(row.getLong(1), row.getString(2)));
return componentUuidById;
}

private static void populateUuidColumns(Context context, Map<Long, String> componentUuidById) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT sn.id, sn.project_id, sn.root_project_id from snapshots sn where sn.component_uuid is null or sn.root_component_uuid is null");
massUpdate.update("UPDATE snapshots SET component_uuid=?, root_component_uuid=? WHERE id=?");
massUpdate.rowPluralName("snapshots");
massUpdate.execute((row, update) -> handle(componentUuidById, row, update));
}

private static boolean handle(Map<Long, String> componentUuidById, Select.Row row, SqlStatement update) throws SQLException {
long id = row.getLong(1);
long componentId = row.getLong(2);
long rootProjectId = row.getLong(3);

String componentUuid = componentUuidById.get(componentId);
String rootComponentUuid = componentUuidById.get(rootProjectId);

if (componentUuid == null && rootComponentUuid == null) {
return false;
}

update.setString(1, componentUuid);
update.setString(2, rootComponentUuid);
update.setLong(3, id);

return true;
}

}

+ 0
- 54
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateComponentUuidOfMeasures.java Voir le fichier

@@ -1,54 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;
import org.sonar.server.platform.db.migration.step.DataChange;

public class PopulateComponentUuidOfMeasures extends DataChange {

public PopulateComponentUuidOfMeasures(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select distinct pm.snapshot_id, s.component_uuid from project_measures pm inner join snapshots s on s.id=pm.snapshot_id where pm.component_uuid is null");
massUpdate.update("UPDATE project_measures SET component_uuid=? WHERE snapshot_id=? and component_uuid is null");
massUpdate.rowPluralName("measures");
massUpdate.execute(this::handle);
}

public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
long snapshotId = row.getLong(1);
String componentUuid = row.getString(2);

update.setString(1, componentUuid);
update.setLong(2, snapshotId);

return true;
}

}

+ 0
- 90
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateLastUsedColumnOfRulesProfiles.java Voir le fichier

@@ -1,90 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;
import org.sonar.server.platform.db.migration.step.DataChange;

public class PopulateLastUsedColumnOfRulesProfiles extends DataChange {

private static final Pattern PATTERN_QP_KEY = Pattern.compile("\"key\"\\s*:\\s*\"(.*?)\"");

public PopulateLastUsedColumnOfRulesProfiles(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
Map<String, Long> lastAnalysisDatesByQualityProfileKey = buildQualityProfilesMap(context);
if (lastAnalysisDatesByQualityProfileKey.isEmpty()) {
return;
}

populateLastUsedColumn(context, lastAnalysisDatesByQualityProfileKey);
}

private static Map<String, Long> buildQualityProfilesMap(Context context) throws SQLException {
Map<String, Long> lastAnalysisDatesByQPKeys = new HashMap<>();

context.prepareSelect("select s.created_at, pm.text_value " +
"from project_measures pm " +
" inner join snapshots s on pm.snapshot_id = s.id " +
" inner join metrics m on pm.metric_id=m.id " +
"where s.islast=? " +
" and m.name='quality_profiles' " +
"order by s.created_at ")
.setBoolean(1, true)
.scroll(row -> {
long analysisDate = row.getLong(1);
String json = row.getString(2);
Matcher matcher = PATTERN_QP_KEY.matcher(json);
while (matcher.find()) {
lastAnalysisDatesByQPKeys.put(matcher.group(1), analysisDate);
}
});
return lastAnalysisDatesByQPKeys;
}

private static void populateLastUsedColumn(Context context, Map<String, Long> lastAnalysisDatesByQualityProfileKey) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select id, kee from rules_profiles where last_used is null");
massUpdate.update("update rules_profiles set last_used=? where id=?");
massUpdate.rowPluralName("rules_profiles");
massUpdate.execute((row, update) -> handle(lastAnalysisDatesByQualityProfileKey, row, update));
}

private static boolean handle(Map<String, Long> lastAnalysisDatesByQualityProfileKey, Select.Row row, SqlStatement update) throws SQLException {
int qualityProfileId = row.getInt(1);
String qualityProfileKey = row.getString(2);

update.setLong(1, lastAnalysisDatesByQualityProfileKey.get(qualityProfileKey));
update.setInt(2, qualityProfileId);

return true;
}
}

+ 0
- 66
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateProfileKeyOfActivities.java Voir le fichier

@@ -1,66 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import java.util.Map;
import org.sonar.api.utils.KeyValueFormat;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;
import org.sonar.server.platform.db.migration.step.DataChange;

import static org.apache.commons.lang.StringUtils.isBlank;

public class PopulateProfileKeyOfActivities extends DataChange {

public PopulateProfileKeyOfActivities(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select id, data_field from activities where profile_key is null");
massUpdate.update("update activities set profile_key=?, data_field=? where id=?");
massUpdate.rowPluralName("activities");
massUpdate.execute(PopulateProfileKeyOfActivities::handle);

// SONAR-8534 delete orphans
context.prepareUpsert("delete from activities where profile_key is null")
.execute()
.commit();
}

private static boolean handle(Select.Row row, SqlStatement update) throws SQLException {
int id = row.getInt(1);
String data = row.getString(2);
Map<String, String> fields = KeyValueFormat.parse(data);
String profileKey = fields.remove("profileKey");
if (isBlank(profileKey)) {
return false;
}
update.setString(1, profileKey);
update.setString(2, KeyValueFormat.format(fields));
update.setInt(3, id);
return true;
}
}

+ 0
- 91
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateUserUpdatedAtOfRulesProfiles.java Voir le fichier

@@ -1,91 +0,0 @@
/*
* 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.v60;

import com.google.common.base.Throwables;
import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.CheckForNull;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;
import org.sonar.server.platform.db.migration.step.DataChange;

public class PopulateUserUpdatedAtOfRulesProfiles extends DataChange {

private static final String SQL_SELECT_PROFILES_NOT_UPDATED = "select kee from rules_profiles where user_updated_at is null";

public PopulateUserUpdatedAtOfRulesProfiles(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
Map<String, Long> userUpdatedAtByProfileKeys = buildUserUpdatedAtMap(context);
populateUserUpdatedAtColumn(context, userUpdatedAtByProfileKeys);
}

private static Map<String, Long> buildUserUpdatedAtMap(Context context) throws SQLException {
Map<String, Long> lastAnalysisDatesByQPKeys = new HashMap<>();
List<String> profileKeys = context.prepareSelect(SQL_SELECT_PROFILES_NOT_UPDATED).list(row -> row.getString(1));
profileKeys.forEach(profileKey -> lastAnalysisDatesByQPKeys.put(profileKey, getUserUpdateAt(context, profileKey)));

return lastAnalysisDatesByQPKeys;
}

@CheckForNull
private static Long getUserUpdateAt(Context context, String profileKey) {
try {
return context.prepareSelect("select created_at as \"createdAt\" " +
"from activities " +
"where user_login is not null " +
" and profile_key=? " +
"order by created_at DESC ")
.setString(1, profileKey)
.get(row -> {
Date userUpdatedAt = row.getNullableDate(1);
return userUpdatedAt == null ? null : userUpdatedAt.getTime();
});
} catch (SQLException e) {
throw Throwables.propagate(e);
}
}

private static void populateUserUpdatedAtColumn(Context context, Map<String, Long> userUpdatedAdByProfileKey) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select(SQL_SELECT_PROFILES_NOT_UPDATED);
massUpdate.update("update rules_profiles set user_updated_at=? where kee=?");
massUpdate.rowPluralName("quality profiles");
massUpdate.execute((row, update) -> handle(userUpdatedAdByProfileKey, row, update));
}

private static boolean handle(Map<String, Long> userUpdatedAtByProfileKey, Select.Row row, SqlStatement update) throws SQLException {
String profileKey = row.getString(1);

update.setLong(1, userUpdatedAtByProfileKey.get(profileKey));
update.setString(2, profileKey);

return true;
}
}

+ 0
- 55
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateUuidColumnOnSnapshots.java Voir le fichier

@@ -1,55 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;
import org.sonar.server.platform.db.migration.step.DataChange;

public class PopulateUuidColumnOnSnapshots extends DataChange {

private final UuidFactory uuidFactory;

public PopulateUuidColumnOnSnapshots(Database db, UuidFactory uuidFactory) {
super(db);
this.uuidFactory = uuidFactory;
}

@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT s.id from snapshots s where s.uuid is null");
massUpdate.update("UPDATE snapshots SET uuid=? WHERE id=?");
massUpdate.rowPluralName("snapshots");
massUpdate.execute(this::handle);
}

private boolean handle(Select.Row row, SqlStatement update) throws SQLException {
long id = row.getLong(1);
update.setString(1, uuidFactory.create());
update.setLong(2, id);
return true;
}

}

+ 0
- 167
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateUuidColumnsOfProjects.java Voir le fichier

@@ -1,167 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;
import org.sonar.server.platform.db.migration.step.DataChange;

public class PopulateUuidColumnsOfProjects extends DataChange {
private static final Logger LOG = Loggers.get(PopulateUuidColumnsOfProjects.class);

public PopulateUuidColumnsOfProjects(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {

Map<Long, String> componentUuidById = buildComponentUuidMap(context);
if (componentUuidById.isEmpty()) {
return;
}

populateRootUuidColumnForRoots(context);
populateRootUuidColumnForSubnodes(context, componentUuidById);
populateCopyComponentUuidColumn(context, componentUuidById);
populatePersonUuidColumn(context, componentUuidById);
}

private static Map<Long, String> buildComponentUuidMap(Context context) throws SQLException {
Map<Long, String> componentUuidById = new HashMap<>();
// rootId for root nodes (ie. column root_id is null)
context.prepareSelect("select distinct p1.id, p1.uuid from projects p1" +
" where p1.root_id is null and p1.root_uuid is null")
.scroll(row -> componentUuidById.put(row.getLong(1), row.getString(2)));
// rootId for other nodes (ie. column root_id is not null)
context.prepareSelect("select distinct p1.id, p1.uuid from projects p1" +
" join projects p2 on p1.id = p2.root_id" +
" where p2.root_uuid is null")
.scroll(row -> componentUuidById.put(row.getLong(1), row.getString(2)));
// copyResourceId
context.prepareSelect("select distinct p1.id, p1.uuid from projects p1" +
" join projects p2 on p1.id = p2.copy_resource_id" +
" where p2.copy_resource_id is not null and p2.copy_component_uuid is null")
.scroll(row -> componentUuidById.put(row.getLong(1), row.getString(2)));
// person_id
context.prepareSelect("select distinct p1.id, p1.uuid from projects p1" +
" join projects p2 on p1.id = p2.person_id" +
" where p2.person_id is not null and p2.developer_uuid is null")
.scroll(row -> componentUuidById.put(row.getLong(1), row.getString(2)));
return componentUuidById;
}

private static void populateRootUuidColumnForRoots(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT distinct p.id from projects p where p.root_id is null and p.root_uuid is null");
massUpdate.update("UPDATE projects SET root_uuid=uuid WHERE id=? and root_id is null and root_uuid is null");
massUpdate.rowPluralName("root uuid of root components");
massUpdate.execute(PopulateUuidColumnsOfProjects::handleRootIdUpdateForRootNodes);
}

private static boolean handleRootIdUpdateForRootNodes(Select.Row row, SqlStatement update) throws SQLException {
long rootId = row.getLong(1);

update.setLong(1, rootId);

return true;
}

private static void populateRootUuidColumnForSubnodes(Context context, Map<Long, String> componentUuidById) throws SQLException {
// update all rows with specific root_id which have no root_uuid yet in a single update
// this will be efficient as root_id is indexed
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT distinct p.root_id from projects p where p.root_id is not null and p.root_uuid is null");
massUpdate.update("UPDATE projects SET root_uuid=? WHERE root_id=? and root_uuid is null");
massUpdate.rowPluralName("root uuid of non-root components");
massUpdate.execute((row, update) -> handleRootIdUpdateForSubNodes(componentUuidById, row, update));
}

private static boolean handleRootIdUpdateForSubNodes(Map<Long, String> componentUuidById, Select.Row row, SqlStatement update) throws SQLException {
long rootId = row.getLong(1);
String rootUuid = componentUuidById.get(rootId);

if (rootUuid == null) {
LOG.trace("No UUID found for rootId={}", rootUuid);
return false;
}

update.setString(1, rootUuid);
update.setLong(2, rootId);

return true;
}

private static void populateCopyComponentUuidColumn(Context context, Map<Long, String> componentUuidById) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT p.id, p.copy_resource_id from projects p where p.copy_resource_id is not null and p.copy_component_uuid is null");
massUpdate.update("UPDATE projects SET copy_component_uuid=? WHERE id=?");
massUpdate.rowPluralName("copy component uuid of components");
massUpdate.execute((row, update) -> handleCopyComponentUuidUpdate(componentUuidById, row, update));
}

private static boolean handleCopyComponentUuidUpdate(Map<Long, String> componentUuidById, Select.Row row, SqlStatement update) throws SQLException {
long id = row.getLong(1);
long copyResourceId = row.getLong(2);

String copyComponentUuid = componentUuidById.get(copyResourceId);
if (copyComponentUuid == null) {
LOG.trace("No UUID found for copyResourceId={}", copyResourceId);
return false;
}

update.setString(1, copyComponentUuid);
update.setLong(2, id);

return true;
}

private static void populatePersonUuidColumn(Context context, Map<Long, String> componentUuidById) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT p.id, p.person_id from projects p where p.person_id is not null and p.developer_uuid is null");
massUpdate.update("UPDATE projects SET developer_uuid=? WHERE id=?");
massUpdate.rowPluralName("person uuid of components");
massUpdate.execute((row, update) -> handleDeveloperUuuidUpdate(componentUuidById, row, update));
}

private static boolean handleDeveloperUuuidUpdate(Map<Long, String> componentUuidById, Select.Row row, SqlStatement update) throws SQLException {
long id = row.getLong(1);
long personId = row.getLong(2);

String developerUuid = componentUuidById.get(personId);
if (developerUuid == null) {
LOG.trace("No UUID found for personId={}", personId);
return false;
}

update.setString(1, developerUuid);
update.setLong(2, id);

return true;
}

}

+ 0
- 169
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateUuidPathColumnOnProjects.java Voir le fichier

@@ -1,169 +0,0 @@
/*
* 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.v60;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Nullable;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;
import org.sonar.server.platform.db.migration.step.DataChange;

import static java.util.stream.Collectors.toCollection;

public class PopulateUuidPathColumnOnProjects extends DataChange {

private static final Logger LOG = Loggers.get(PopulateUuidPathColumnOnProjects.class);
private static final Joiner PATH_JOINER = Joiner.on('.');
private static final Splitter PATH_SPLITTER = Splitter.on('.').omitEmptyStrings();
private static final String PATH_SEPARATOR = ".";
private static final String ROOT_PATH = PATH_SEPARATOR;

public PopulateUuidPathColumnOnProjects(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
// group upgrades by tree of component
List<String> rootComponentUuids = context
.prepareSelect("select distinct project_uuid from projects where uuid_path is null")
.list(row -> row.getString(1));
for (String rootUuid : rootComponentUuids) {
handleRoot(rootUuid, context);
}

handleOrphans(context);
}

private static void handleRoot(String rootComponentUuid, Context context) throws SQLException {
Relations relations = new Relations();
context
.prepareSelect("select s.id, s.path, s.component_uuid from snapshots s where s.root_component_uuid=? and s.islast=?")
.setString(1, rootComponentUuid)
.setBoolean(2, true)
.scroll(row -> {
long snapshotId = row.getLong(1);
String snapshotPath = row.getString(2);
String componentUuid = row.getString(3);
relations.add(new Snapshot(snapshotId, snapshotPath, componentUuid));
});

MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select p.uuid, p.project_uuid from projects p where p.project_uuid=? and p.uuid_path is null").setString(1, rootComponentUuid);
massUpdate.update("update projects set uuid_path=? where uuid=? and uuid_path is null");
massUpdate.rowPluralName("components in tree of " + rootComponentUuid);
massUpdate.execute((row, update) -> handleComponent(relations, row, update));
}

private static void handleOrphans(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select uuid, project_uuid from projects where uuid_path is null");
massUpdate.update("update projects set uuid_path=? where uuid=? and uuid_path is null");
massUpdate.rowPluralName("orphan components");
massUpdate.execute((row, update, updateIndex) -> {
String uuid = row.getString(1);
String rootUuid = row.getString(2);
String path = uuid.equals(rootUuid) ? ROOT_PATH : (PATH_SEPARATOR + rootUuid + PATH_SEPARATOR);
update.setString(1, path);
update.setString(2, uuid);
return true;
});
}

private static boolean handleComponent(Relations relations, Select.Row row, SqlStatement update) throws SQLException {
String componentUuid = row.getString(1);
String rootComponentUuid = row.getString(2);

if (componentUuid.equals(rootComponentUuid)) {
// Root component, no need to use the table SNAPSHOTS.
// Moreover it allows to support provisioned projects (zero analysis)
update.setString(1, PATH_SEPARATOR);
update.setString(2, componentUuid);
return true;
}

Snapshot snapshot = relations.snapshotsByComponentUuid.get(componentUuid);
if (snapshot == null) {
LOG.trace("No UUID found for component UUID={}", componentUuid);
return false;
}

List<String> componentUuidPath = Arrays.stream(snapshot.snapshotPath)
.mapToObj(relations.snapshotsById::get)
.filter(Objects::nonNull)
.map(s -> s.componentUuid)
.collect(toCollection(ArrayList::new));
if (componentUuidPath.size() != snapshot.snapshotPath.length) {
LOG.trace("Some component UUIDs not found for snapshots [{}]", snapshot.snapshotPath);
return false;
}

update.setString(1, PATH_SEPARATOR + PATH_JOINER.join(componentUuidPath) + PATH_SEPARATOR);
update.setString(2, componentUuid);
return true;
}

private static final class Relations {
private final Map<String, Snapshot> snapshotsByComponentUuid = new HashMap<>();
private final Map<Long, Snapshot> snapshotsById = new HashMap<>();

void add(Snapshot snapshot) {
snapshotsByComponentUuid.put(snapshot.componentUuid, snapshot);
snapshotsById.put(snapshot.id, snapshot);
}
}

private static final class Snapshot {
private static final long[] EMPTY_PATH = new long[0];
private final long id;
private final long[] snapshotPath;
private final String componentUuid;

public Snapshot(long id, String snapshotPath, String componentUuid) {
this.id = id;
this.snapshotPath = parsePath(snapshotPath);
this.componentUuid = componentUuid;
}

// inputs: null (on Oracle), "", "1." or "1.2.3."
private static long[] parsePath(@Nullable String snapshotPath) {
if (snapshotPath == null) {
return EMPTY_PATH;
}
return PATH_SPLITTER
.splitToList(snapshotPath)
.stream()
.mapToLong(Long::parseLong)
.toArray();
}
}
}

+ 0
- 43
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/RecreateIndexProjectsUuidFromProjects.java Voir le fichier

@@ -1,43 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class RecreateIndexProjectsUuidFromProjects extends DdlChange {

public RecreateIndexProjectsUuidFromProjects(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new CreateIndexBuilder()
.setTable("projects")
.setName("projects_uuid")
.addColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(50).setIgnoreOracleUnit(true).build())
.build());
}
}

+ 0
- 50
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/RemoveUsersPasswordWhenNotLocal.java Voir le fichier

@@ -1,50 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.api.utils.System2;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.DataChange;

public class RemoveUsersPasswordWhenNotLocal extends DataChange {

private final System2 system2;

public RemoveUsersPasswordWhenNotLocal(Database db, System2 system2) {
super(db);
this.system2 = system2;
}

@Override
public void execute(Context context) throws SQLException {
long now = system2.now();
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT u.id FROM users u WHERE (u.crypted_password IS NOT NULL OR u.salt IS NOT NULL) AND u.user_local=?").setBoolean(1, false);
massUpdate.update("UPDATE users SET crypted_password=null, salt=null, updated_at=? WHERE id=?");
massUpdate.rowPluralName("none local users with password");
massUpdate.execute((row, update) -> {
update.setLong(1, now);
update.setLong(2, row.getLong(1));
return true;
});
}
}

+ 0
- 44
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/TemporarilyDropIndexOfAnalysisUuidOnMeasures.java Voir le fichier

@@ -1,44 +0,0 @@
/*
* 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.v60;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

/**
* the index must be dropped for the compatibility of migration 1270
* with MSSQL
*/
public class TemporarilyDropIndexOfAnalysisUuidOnMeasures extends DdlChange {

public TemporarilyDropIndexOfAnalysisUuidOnMeasures(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropIndexBuilder(getDialect())
.setTable("project_measures")
.setName("measures_analysis_metric")
.build());
}
}

+ 0
- 23
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/package-info.java Voir le fichier

@@ -1,23 +0,0 @@
/*
* 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.server.platform.db.migration.version.v60;

import javax.annotation.ParametersAreNonnullByDefault;

+ 0
- 44
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/AddBUuidPathToProjects.java Voir le fichier

@@ -1,44 +0,0 @@
/*
* 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.v61;

import java.sql.SQLException;
import org.sonar.db.Database;
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 AddBUuidPathToProjects extends DdlChange {

private static final String TABLE_PROJECTS = "projects";

public AddBUuidPathToProjects(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_PROJECTS)
.addColumn(newVarcharColumnDefBuilder().setColumnName("b_uuid_path").setLimit(1500).setIgnoreOracleUnit(true).build())
.build());
}

}

+ 0
- 46
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/AddErrorColumnsToCeActivity.java Voir le fichier

@@ -1,46 +0,0 @@
/*
* 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.v61;

import java.sql.SQLException;
import org.sonar.db.Database;
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.ClobColumnDef.newClobColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddErrorColumnsToCeActivity extends DdlChange {

private static final String TABLE_CE_ACTIVITY = "ce_activity";

public AddErrorColumnsToCeActivity(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_CE_ACTIVITY)
.addColumn(newVarcharColumnDefBuilder().setColumnName("error_message").setLimit(1000).setIgnoreOracleUnit(true).build())
.addColumn(newClobColumnDefBuilder().setColumnName("error_stacktrace").setIsNullable(true).build())
.build());
}

}

+ 0
- 68
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/CopyActivitiesToQprofileChanges.java Voir le fichier

@@ -1,68 +0,0 @@
/*
* 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.v61;

import java.sql.SQLException;
import java.util.Date;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;

public class CopyActivitiesToQprofileChanges extends DataChange {

public CopyActivitiesToQprofileChanges(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.rowPluralName("activities");
massUpdate
.select("select a.log_key, a.profile_key, a.created_at, a.user_login, a.log_action, a.data_field " +
"from activities a " +
"left join qprofile_changes qc on qc.kee = a.log_key " +
"where a.log_type=? " +
"and a.log_action is not null " +
"and a.profile_key is not null " +
"and a.created_at is not null " +
"and qc.kee is null")
.setString(1, "QPROFILE");

massUpdate.update("insert into qprofile_changes (kee, qprofile_key, created_at, user_login, change_type, change_data) values (?,?,?,?,?,?)");
massUpdate.execute((row, update) -> {
String key = row.getString(1);
String profileKey = row.getString(2);
Date createdAt = row.getDate(3);
String login = row.getNullableString(4);
String type = row.getString(5);
String data = row.getNullableString(6);

update.setString(1, key);
update.setString(2, profileKey);
update.setLong(3, createdAt.getTime());
update.setString(4, login);
update.setString(5, type);
update.setString(6, data);
return true;
});
}

}

+ 0
- 47
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/CreateTableCeTaskInput.java Voir le fichier

@@ -1,47 +0,0 @@
/*
* 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.v61;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.BlobColumnDef.newBlobColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class CreateTableCeTaskInput extends DdlChange {
public CreateTableCeTaskInput(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(
new CreateTableBuilder(getDialect(), "ce_task_input")
.addPkColumn(newVarcharColumnDefBuilder().setColumnName("task_uuid").setLimit(UUID_SIZE).setIsNullable(false).setIgnoreOracleUnit(true).build())
.addColumn(newBlobColumnDefBuilder().setColumnName("input_data").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").setIsNullable(false).build())
.build());
}
}

+ 0
- 49
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/CreateTableInternalProperties.java Voir le fichier

@@ -1,49 +0,0 @@
/*
* 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.v61;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.ClobColumnDef.newClobColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.MAX_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class CreateTableInternalProperties extends DdlChange {
public CreateTableInternalProperties(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(
new CreateTableBuilder(getDialect(), "internal_properties")
.addPkColumn(newVarcharColumnDefBuilder().setColumnName("kee").setLimit(20).setIsNullable(false).setIgnoreOracleUnit(true).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("is_empty").setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("text_value").setLimit(MAX_SIZE).setIgnoreOracleUnit(true).build())
.addColumn(newClobColumnDefBuilder().setColumnName("clob_value").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
.build());
}
}

+ 0
- 69
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/CreateTableProperties2.java Voir le fichier

@@ -1,69 +0,0 @@
/*
* 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.v61;

import java.sql.SQLException;
import java.util.List;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;

import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.ClobColumnDef.newClobColumnDefBuilder;
import static org.sonar.server.platform.db.migration.sql.CreateTableBuilder.ColumnFlag.AUTO_INCREMENT;
import static org.sonar.server.platform.db.migration.def.IntegerColumnDef.newIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.MAX_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class CreateTableProperties2 extends DdlChange {

private static final String TABLE_NAME = "properties2";

public CreateTableProperties2(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
VarcharColumnDef propKey = newVarcharColumnDefBuilder().setColumnName("prop_key").setLimit(512).setIsNullable(false).setIgnoreOracleUnit(true).build();
List<String> stmts = new CreateTableBuilder(getDialect(), TABLE_NAME)
.addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
.addColumn(propKey)
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("resource_id").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("user_id").setIsNullable(true).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("is_empty").setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("text_value").setLimit(MAX_SIZE).setIgnoreOracleUnit(true).build())
.addColumn(newClobColumnDefBuilder().setColumnName("clob_value").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
// table with be renamed to properties in following migration, use final constraint name right away
.withPkConstraintName("pk_properties")
.build();
context.execute(stmts);

context.execute(new CreateIndexBuilder()
.setTable(TABLE_NAME)
.setName("properties2_key")
.addColumn(propKey)
.build());
}
}

+ 0
- 49
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/CreateTableQprofileChanges.java Voir le fichier

@@ -1,49 +0,0 @@
/*
* 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.v61;

import java.sql.SQLException;
import java.util.List;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.ClobColumnDef.newClobColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class CreateTableQprofileChanges extends DdlChange {
public CreateTableQprofileChanges(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
List<String> stmts = new CreateTableBuilder(getDialect(), "qprofile_changes")
.addPkColumn(newVarcharColumnDefBuilder().setColumnName("kee").setLimit(40).setIsNullable(false).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("qprofile_key").setLimit(255).setIsNullable(false).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("change_type").setLimit(20).setIsNullable(false).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("user_login").setLimit(255).setIsNullable(true).setIgnoreOracleUnit(true).build())
.addColumn(newClobColumnDefBuilder().setColumnName("change_data").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
.build();
context.execute(stmts);
}
}

+ 0
- 46
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/CreateTableRuleRepositories.java Voir le fichier

@@ -1,46 +0,0 @@
/*
* 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.v61;

import java.sql.SQLException;
import java.util.List;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class CreateTableRuleRepositories extends DdlChange {
public CreateTableRuleRepositories(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
List<String> stmts = new CreateTableBuilder(getDialect(), "rule_repositories")
.addPkColumn(newVarcharColumnDefBuilder().setColumnName("kee").setLimit(200).setIsNullable(false).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("language").setLimit(20).setIsNullable(false).setIgnoreOracleUnit(true).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("name").setLimit(4000).setIsNullable(false).setIgnoreOracleUnit(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
.build();
context.execute(stmts);
}
}

+ 0
- 47
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/CreateTableScannerContext.java Voir le fichier

@@ -1,47 +0,0 @@
/*
* 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.v61;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.BlobColumnDef.newBlobColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class CreateTableScannerContext extends DdlChange {
public CreateTableScannerContext(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(
new CreateTableBuilder(getDialect(), "ce_scanner_context")
.addPkColumn(newVarcharColumnDefBuilder().setColumnName("task_uuid").setLimit(UUID_SIZE).setIsNullable(false).setIgnoreOracleUnit(true).build())
.addColumn(newBlobColumnDefBuilder().setColumnName("context_data").setIsNullable(false).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").setIsNullable(false).build())
.build());
}
}

+ 0
- 56
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/DbVersion61.java Voir le fichier

@@ -1,56 +0,0 @@
/*
* 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.v61;

import java.util.stream.Stream;
import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
import org.sonar.server.platform.db.migration.version.DbVersion;

public class DbVersion61 implements DbVersion {
@Override
public Stream<Object> getSupportComponents() {
return Stream.of(
// Migration1304
ShrinkModuleUuidPathOfProjects.class,
AddBUuidPathToProjects.class);
}

@Override
public void addSteps(MigrationStepRegistry registry) {
registry
.add(1300, "Delete project dashboards and widgets", DeleteProjectDashboards.class)
.add(1301, "Drop column DASHBOARDS.IS_GLOBAL", DropIsGlobalFromDashboards.class)
.add(1302, "Create table CE_TASK_INPUT", CreateTableCeTaskInput.class)
.add(1303, "Clear CE_QUEUE content", DeleteReportsFromCeQueue.class)
.add(1304, "Shrink column PROJECTS.MODULE_UUID_PATH", Migration1304.class)
.add(1307, "Add columns CE_ACTIVITY.ERROR_*", AddErrorColumnsToCeActivity.class)
.add(1309, "Create table CE_SCANNER_CONTEXT", CreateTableScannerContext.class)
.add(1310, "Create table INTERNAL_PROPERTIES", CreateTableInternalProperties.class)
.add(1311, "Move views config from PROPERTIES to INTERNAL_PROPERTIES", RemoveViewsDefinitionFromProperties.class)
.add(1312, "Create table PROPERTIES2", CreateTableProperties2.class)
.add(1313, "Populate table PROPERTIES2", PopulateTableProperties2.class)
.add(1314, "Drop table PROPERTIES", DropTableProperties.class)
.add(1315, "Rename table PROPERTIES2 to PROPERTIES", RenameTableProperties2ToProperties.class)
.add(1316, "Create table QPROFILE_CHANGES", CreateTableQprofileChanges.class)
.add(1317, "Populate table QPROFILE_CHANGES", CopyActivitiesToQprofileChanges.class)
.add(1318, "Drop table ACTIVITIES", DropTableActivities.class)
.add(1319, "Create table RULE_REPOSITORIES", CreateTableRuleRepositories.class);
}
}

+ 0
- 74
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/DeleteProjectDashboards.java Voir le fichier

@@ -1,74 +0,0 @@
/*
* 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.v61;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;

public class DeleteProjectDashboards extends DataChange {

public DeleteProjectDashboards(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
deleteWidgetProperties(context);
deleteDashboardsAndWidgets(context);
}

private static void deleteWidgetProperties(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT w.id " +
"FROM widgets w " +
" INNER JOIN dashboards d on w.dashboard_id=d.id " +
"WHERE d.is_global=?")
.setBoolean(1, false);
massUpdate.update("DELETE from widget_properties WHERE widget_id=?");
massUpdate.rowPluralName("delete widget properties of project dashboards");
massUpdate.execute((row, update) -> {
update.setLong(1, row.getLong(1));
return true;
});
}

private static void deleteDashboardsAndWidgets(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT id FROM dashboards d WHERE d.is_global=?").setBoolean(1, false);
massUpdate.update("DELETE from widgets WHERE dashboard_id=?");
massUpdate.update("DELETE from active_dashboards WHERE dashboard_id=?");
massUpdate.update("DELETE from dashboards WHERE id=?");
massUpdate.rowPluralName("delete project dashboards");
massUpdate.execute((row, update, updateIndex) -> {
long dashboardId = row.getLong(1);
switch (updateIndex) {
case 0:
case 1:
case 2:
update.setLong(1, dashboardId);
return true;
default:
throw new IllegalArgumentException("Unsupported update index " + updateIndex);
}
});
}
}

+ 0
- 47
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/DeleteReportsFromCeQueue.java Voir le fichier

@@ -1,47 +0,0 @@
/*
* 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.v61;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;

/**
* SONAR-7903 - in version 6.1 analysis reports are not persisted on FS anymore
* but in DB. For simplicity of migration report files are not copied to DB.
* To avoid failures on missing reports, tasks are simply ignored and removed from
* queue.
*/
public class DeleteReportsFromCeQueue extends DataChange {

public DeleteReportsFromCeQueue(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context
.prepareUpsert("delete from ce_queue where task_type=?")
.setString(1, "REPORT")
.execute()
.commit();
}

}

+ 0
- 40
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/DropIsGlobalFromDashboards.java Voir le fichier

@@ -1,40 +0,0 @@
/*
* 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.v61;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DdlChange;
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;

public class DropIsGlobalFromDashboards extends DdlChange {

private static final String TABLE_DASHBOARDS = "dashboards";

public DropIsGlobalFromDashboards(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropColumnsBuilder(getDialect(), TABLE_DASHBOARDS, "is_global").build());
}

}

+ 0
- 46
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/DropTableActivities.java Voir le fichier

@@ -1,46 +0,0 @@
/*
* 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.v61;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DdlChange;
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
import org.sonar.server.platform.db.migration.sql.DropTableBuilder;

public class DropTableActivities extends DdlChange {

private static final String TABLE_ACTIVITIES = "activities";

public DropTableActivities(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropIndexBuilder(getDialect())
.setTable(TABLE_ACTIVITIES)
.setName("activities_log_key")
.build());

context.execute(new DropTableBuilder(getDialect(), TABLE_ACTIVITIES).build());
}

}

+ 0
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v61/DropTableProperties.java Voir le fichier


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff

Chargement…
Annuler
Enregistrer