aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration
diff options
context:
space:
mode:
authorMichal Duda <michal.duda@sonarsource.com>2020-04-23 20:16:38 +0200
committersonartech <sonartech@sonarsource.com>2020-05-25 20:05:22 +0000
commitbf05b3c7c2e5157047dccefcfb38af0033c77f20 (patch)
treeab4dcbce1ecf30e9782c8ec3bdc56f607ce1e1b0 /server/sonar-db-migration
parent88e71c8c976210624ddb296f24f2ddcbe53417b4 (diff)
downloadsonarqube-bf05b3c7c2e5157047dccefcfb38af0033c77f20.tar.gz
sonarqube-bf05b3c7c2e5157047dccefcfb38af0033c77f20.zip
SONAR-13221 change PK of RULES and update FK
Diffstat (limited to 'server/sonar-db-migration')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java82
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTable.java38
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRules.java58
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTable.java37
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTable.java41
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTable.java37
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuid.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuid.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTable.java70
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTable.java43
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTable.java37
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumn.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTable.java63
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable.java41
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTable.java37
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumn.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTable.java62
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTable.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTable.java41
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTable.java37
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumn.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable.java38
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTable.java41
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTable.java37
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumn.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTable.java81
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTable.java45
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTable.java37
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumn.java49
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest.java66
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest.java56
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest.java43
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest.java74
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest.java75
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest.java51
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest.java79
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest.java54
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest.java43
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest.java84
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest.java51
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest.java80
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest.java54
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest.java43
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest.java86
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest.java51
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest.java81
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest.java54
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest.java87
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest.java80
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.java56
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest.java43
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest.java85
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest.java53
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest.java78
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest.java57
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest.java43
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest.java84
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest/schema.sql29
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest/schema.sql29
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest/schema.sql30
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest/schema.sql30
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest/schema.sql31
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest/schema.sql31
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest/schema.sql31
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest/schema.sql31
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest/schema.sql42
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest/schema.sql42
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest/schema.sql43
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest/schema.sql43
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest/schema.sql43
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest/schema.sql43
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest/schema.sql41
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest/schema.sql41
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql42
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql42
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest/schema.sql42
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest/schema.sql42
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest/schema.sql69
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest/schema.sql69
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest/schema.sql70
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest/schema.sql70
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest/schema.sql70
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest/schema.sql50
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest/schema.sql50
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest/schema.sql51
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest/schema.sql51
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest/schema.sql51
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest/schema.sql51
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest/schema.sql41
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest/schema.sql42
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest/schema.sql43
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest/schema.sql43
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest/schema.sql43
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest/schema.sql43
112 files changed, 5742 insertions, 0 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java
index 200853aebe8..73716cd4e5e 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java
@@ -221,6 +221,43 @@ import org.sonar.server.platform.db.migration.version.v83.qualitygates.DropQGate
import org.sonar.server.platform.db.migration.version.v83.qualitygates.DropUniqueIndexOnUuidColumnOfQualityGatesTable;
import org.sonar.server.platform.db.migration.version.v83.qualitygates.MakeQGateUuidColumnNotNullableForQGateConditions;
import org.sonar.server.platform.db.migration.version.v83.qualitygates.PopulateQGateUuidColumnForQGateConditions;
+import org.sonar.server.platform.db.migration.version.v83.rules.AddPrimaryKeyOnUuidColumnOfRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.AddUuidAndTemplateUuidColumnsToRules;
+import org.sonar.server.platform.db.migration.version.v83.rules.DropIdColumnOfRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.DropPrimaryKeyOnIdColumnOfRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.DropTemplateIdColumnOfRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.MakeRulesUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.rules.PopulateRulesTemplateUuid;
+import org.sonar.server.platform.db.migration.version.v83.rules.PopulateRulesUuid;
+import org.sonar.server.platform.db.migration.version.v83.rules.activerules.AddIndexToActiveRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.activerules.AddRuleUuidColumnToActiveRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.activerules.DropIndexOnRuleIdColumnOfActiveRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.activerules.DropRuleIdColumnOfActiveRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.activerules.MakeActiveRulesRuleUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.rules.activerules.PopulateActiveRulesRuleUuidColumn;
+import org.sonar.server.platform.db.migration.version.v83.rules.deprecatedrulekeys.AddIndexToDeprecatedRuleKeysTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.deprecatedrulekeys.AddRuleUuidColumnToDeprecatedRuleKeysTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.deprecatedrulekeys.DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.deprecatedrulekeys.DropRuleIdColumnOfDeprecatedRuleKeysTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.deprecatedrulekeys.MakeDeprecatedRuleKeysRuleUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.rules.deprecatedrulekeys.PopulateDeprecatedRuleKeysRuleUuidColumn;
+import org.sonar.server.platform.db.migration.version.v83.rules.issues.AddIndexToIssuesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.issues.AddRuleUuidColumnToIssuesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.issues.DropIndexOnRuleIdColumnOfIssuesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.issues.DropRuleIdColumnOfIssuesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.issues.PopulateIssuesRuleUuidColumn;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesmetadata.AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesmetadata.AddRuleUuidColumnToRulesMetadataTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesmetadata.DropPrimaryKeyOnIdColumnOfRulesMetadataTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesmetadata.DropRuleIdColumnOfRulesMetadataTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesmetadata.MakeRulesMetadataRuleUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesmetadata.PopulateRulesMetadataRuleUuidColumn;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesparameters.AddIndexesToRulesParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesparameters.AddRuleUuidColumnToRulesParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesparameters.DropIndexesOnRuleIdColumnOfRulesParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesparameters.DropRuleIdColumnOfRulesParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesparameters.MakeRulesParametersRuleUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesparameters.PopulateRulesParametersRuleUuidColumn;
import org.sonar.server.platform.db.migration.version.v83.rulesparameters.AddPrimaryKeyOnUuidColumnOfRulesParametersTable;
import org.sonar.server.platform.db.migration.version.v83.rulesparameters.AddUuidColumnToRulesParameters;
import org.sonar.server.platform.db.migration.version.v83.rulesparameters.DropIdColumnOfRulesParametersTable;
@@ -716,6 +753,51 @@ public class DbVersion83 implements DbVersion {
.add(3671, "Add PK index on 'uuid' column of 'USERS' table", AddPrimaryKeyOnUuidColumnOfUsersTable.class)
.add(3672, "Drop 'id' column of 'USERS' table", DropIdColumnOfUsersTable.class)
+ // Migration of RULES table
+ .add(3673, "Add 'uuid' column for 'RULES'", AddUuidAndTemplateUuidColumnsToRules.class)
+ .add(3674, "Populate 'uuid' column for 'RULES'", PopulateRulesUuid.class)
+ .add(3675, "Make 'uuid' column not nullable for 'RULES'", MakeRulesUuidColumnNotNullable.class)
+ .add(3676, "Populate 'templateUuid' column for 'RULES'", PopulateRulesTemplateUuid.class)
+ .add(3677, "Drop column 'templateId' column for 'RULES'", DropTemplateIdColumnOfRulesTable.class)
+ // Migration of RULES_METADATA FK to RULES, switch from rule_id to rule_uuid
+ .add(3678, "Add 'RULE_UUID' column for 'RULES_METADATA' table", AddRuleUuidColumnToRulesMetadataTable.class)
+ .add(3679, "Populate 'RULE_UUID' column for 'RULES_METADATA' table", PopulateRulesMetadataRuleUuidColumn.class)
+ .add(3680, "Make 'RULE_UUID' column not nullable for 'RULES_METADATA' table", MakeRulesMetadataRuleUuidColumnNotNullable.class)
+ .add(3681, "Drop primary key on 'RULE_ID' column of 'RULES_METADATA' table", DropPrimaryKeyOnIdColumnOfRulesMetadataTable.class)
+ .add(3682, "Add primary key on 'RULE_UUID' column of 'RULES_METADATA' table", AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable.class)
+ .add(3683, "Drop column 'RULE_ID' of 'RULES_METADATA' table", DropRuleIdColumnOfRulesMetadataTable.class)
+ // Migration of RULES_PARAMETERS FK to RULES, switch from rule_id to rule_uuid
+ .add(3684, "Add 'RULE_UUID' column for 'RULES_PARAMETERS' table", AddRuleUuidColumnToRulesParametersTable.class)
+ .add(3685, "Populate 'RULE_UUID' column for 'RULES_PARAMETERS' table", PopulateRulesParametersRuleUuidColumn.class)
+ .add(3686, "Make 'RULE_UUID' column not nullable for 'RULES_PARAMETERS' table", MakeRulesParametersRuleUuidColumnNotNullable.class)
+ .add(3687, "Drop indexes on 'RULE_ID' of 'RULES_PARAMETERS' table", DropIndexesOnRuleIdColumnOfRulesParametersTable.class)
+ .add(3688, "Add indexes to 'RULES_PARAMETERS' table", AddIndexesToRulesParametersTable.class)
+ .add(3689, "Drop column 'RULE_ID' of 'RULES_PARAMETERS' table", DropRuleIdColumnOfRulesParametersTable.class)
+ // Migration of ACTIVE_RULES FK to RULES, switch from rule_id to rule_uuid
+ .add(3690, "Add 'RULE_UUID' column for 'ACTIVE_RULES' table", AddRuleUuidColumnToActiveRulesTable.class)
+ .add(3691, "Populate 'RULE_UUID' column for 'ACTIVE_RULES' table", PopulateActiveRulesRuleUuidColumn.class)
+ .add(3692, "Make 'RULE_UUID' column not nullable for 'ACTIVE_RULES' table", MakeActiveRulesRuleUuidColumnNotNullable.class)
+ .add(3693, "Drop indexes on 'RULE_ID' of 'ACTIVE_RULES' table", DropIndexOnRuleIdColumnOfActiveRulesTable.class)
+ .add(3694, "Add indexes to 'ACTIVE_RULES' table", AddIndexToActiveRulesTable.class)
+ .add(3695, "Drop column 'RULE_ID' of 'ACTIVE_RULES' table", DropRuleIdColumnOfActiveRulesTable.class)
+ // Migration of DEPRECATED_RULE_KEYS FK to RULES, switch from rule_id to rule_uuid
+ .add(3696, "Add 'RULE_UUID' column for 'DEPRECATED_RULE_KEYS' table", AddRuleUuidColumnToDeprecatedRuleKeysTable.class)
+ .add(3697, "Populate 'RULE_UUID' column for 'DEPRECATED_RULE_KEYS' table", PopulateDeprecatedRuleKeysRuleUuidColumn.class)
+ .add(3698, "Make 'RULE_UUID' column not nullable for 'DEPRECATED_RULE_KEYS' table", MakeDeprecatedRuleKeysRuleUuidColumnNotNullable.class)
+ .add(3699, "Drop index on 'RULE_ID' of 'DEPRECATED_RULE_KEYS' table", DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable.class)
+ .add(3700, "Add index to 'DEPRECATED_RULE_KEYS' table", AddIndexToDeprecatedRuleKeysTable.class)
+ .add(3701, "Drop column 'RULE_ID' of 'DEPRECATED_RULE_KEYS' table", DropRuleIdColumnOfDeprecatedRuleKeysTable.class)
+ // Migration of ISSUE FK to RULES, switch from rule_id to rule_uuid
+ .add(3702, "Add 'RULE_UUID' column for 'ISSUES' table", AddRuleUuidColumnToIssuesTable.class)
+ .add(3703, "Populate 'RULE_UUID' column for 'ISSUES' table", PopulateIssuesRuleUuidColumn.class)
+ .add(3704, "Drop index on 'RULE_ID' of 'ISSUES' table", DropIndexOnRuleIdColumnOfIssuesTable.class)
+ .add(3705, "Add index to 'ISSUES' table", AddIndexToIssuesTable.class)
+ .add(3706, "Drop column 'RULE_ID' of 'ISSUES' table", DropRuleIdColumnOfIssuesTable.class)
+ // continue with RULES table cleanup
+ .add(3707, "Drop primary key on 'ID' column of 'RULES' table", DropPrimaryKeyOnIdColumnOfRulesTable.class)
+ .add(3708, "Add primary key on 'UUID' column of 'RULES' table", AddPrimaryKeyOnUuidColumnOfRulesTable.class)
+ .add(3709, "Drop column 'ID' of 'RULES' table", DropIdColumnOfRulesTable.class)
+
;
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTable.java
new file mode 100644
index 00000000000..54636e8f742
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTable.java
@@ -0,0 +1,38 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+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.version.v83.util.AddPrimaryKeyBuilder;
+
+public class AddPrimaryKeyOnUuidColumnOfRulesTable extends DdlChange {
+
+ public AddPrimaryKeyOnUuidColumnOfRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddPrimaryKeyBuilder("rules", "uuid").build());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRules.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRules.java
new file mode 100644
index 00000000000..ba203f53a7d
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRules.java
@@ -0,0 +1,58 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddUuidAndTemplateUuidColumnsToRules extends DdlChange {
+ private static final String TABLE = "rules";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ private static final VarcharColumnDef templateUuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("template_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddUuidAndTemplateUuidColumnsToRules(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(uuidColumnDefinition)
+ .addColumn(templateUuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTable.java
new file mode 100644
index 00000000000..cdde386e05a
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTable.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+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 DropIdColumnOfRulesTable extends DdlChange {
+
+ public DropIdColumnOfRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "rules", "id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTable.java
new file mode 100644
index 00000000000..20c1b53c9ea
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTable.java
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+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.version.v83.util.DropPrimaryKeySqlGenerator;
+
+public class DropPrimaryKeyOnIdColumnOfRulesTable extends DdlChange {
+
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator;
+
+ public DropPrimaryKeyOnIdColumnOfRulesTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
+ super(db);
+ this.dropPrimaryKeySqlGenerator = dropPrimaryKeySqlGenerator;
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(dropPrimaryKeySqlGenerator.generate("rules", "id", true));
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTable.java
new file mode 100644
index 00000000000..027f971fe70
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTable.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+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 DropTemplateIdColumnOfRulesTable extends DdlChange {
+
+ public DropTemplateIdColumnOfRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "rules", "template_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullable.java
new file mode 100644
index 00000000000..86bf5f85471
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeRulesUuidColumnNotNullable extends DdlChange {
+ private static final String TABLE = "rules";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeRulesUuidColumnNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+ .updateColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuid.java
new file mode 100644
index 00000000000..9b235a2c47d
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuid.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+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 PopulateRulesTemplateUuid extends DataChange {
+
+ public PopulateRulesTemplateUuid(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select(
+ "select ru.id, rt.uuid from rules ru " +
+ "left join rules rt on rt.id = ru.template_id " +
+ "where ru.template_uuid is null and ru.template_id is not null");
+ massUpdate.update("update rules set template_uuid = ? where id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuid.java
new file mode 100644
index 00000000000..1d919988bd8
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuid.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.sonar.core.util.UuidFactory;
+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 PopulateRulesUuid extends DataChange {
+
+ private final UuidFactory uuidFactory;
+
+ public PopulateRulesUuid(Database db, UuidFactory uuidFactory) {
+ super(db);
+ this.uuidFactory = uuidFactory;
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select id from rules where uuid is null");
+ massUpdate.update("update rules set uuid = ? where id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, uuidFactory.create());
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTable.java
new file mode 100644
index 00000000000..0e2c2158d1c
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTable.java
@@ -0,0 +1,70 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+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 AddIndexToActiveRulesTable extends DdlChange {
+ private static final String TABLE = "active_rules";
+ private static final String INDEX_NAME = "uniq_profile_rule_uuids";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(false)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+ private static final VarcharColumnDef profileUuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("profile_uuid")
+ .setIsNullable(false)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddIndexToActiveRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (!indexExists()) {
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE)
+ .setName(INDEX_NAME)
+ .addColumn(profileUuidColumnDefinition)
+ .addColumn(uuidColumnDefinition)
+ .setUnique(true)
+ .build());
+ }
+ }
+
+ private boolean indexExists() throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.indexExists(TABLE, INDEX_NAME, connection);
+ }
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTable.java
new file mode 100644
index 00000000000..fee60d1416a
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddRuleUuidColumnToActiveRulesTable extends DdlChange {
+ private static final String TABLE = "active_rules";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddRuleUuidColumnToActiveRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTable.java
new file mode 100644
index 00000000000..c177926955a
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTable.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+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 DropIndexOnRuleIdColumnOfActiveRulesTable extends DdlChange {
+ private static final String TABLE_NAME = "active_rules";
+ private static final String INDEX_NAME = "uniq_profile_rule_ids";
+
+ public DropIndexOnRuleIdColumnOfActiveRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable(TABLE_NAME)
+ .setName(INDEX_NAME)
+ .build());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTable.java
new file mode 100644
index 00000000000..b2f9995af46
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTable.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+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 DropRuleIdColumnOfActiveRulesTable extends DdlChange {
+
+ public DropRuleIdColumnOfActiveRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "active_rules", "rule_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullable.java
new file mode 100644
index 00000000000..b4b0ffa2c36
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeActiveRulesRuleUuidColumnNotNullable extends DdlChange {
+ private static final String TABLE = "active_rules";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeActiveRulesRuleUuidColumnNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+ .updateColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumn.java
new file mode 100644
index 00000000000..f6ce521e292
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumn.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+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 PopulateActiveRulesRuleUuidColumn extends DataChange {
+
+ public PopulateActiveRulesRuleUuidColumn(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select ar.rule_id, ru.uuid " +
+ "from active_rules ar " +
+ "join rules ru on ar.rule_id = ru.id " +
+ "where ar.rule_uuid is null");
+ massUpdate.update("update active_rules set rule_uuid = ? where rule_id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTable.java
new file mode 100644
index 00000000000..129f57b3e7f
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTable.java
@@ -0,0 +1,63 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+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 AddIndexToDeprecatedRuleKeysTable extends DdlChange {
+ private static final String TABLE = "deprecated_rule_keys";
+ private static final String INDEX_NAME = "rule_uuid_deprecated_rule_keys";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(false)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddIndexToDeprecatedRuleKeysTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (!indexExists()) {
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE)
+ .setName(INDEX_NAME)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+ }
+
+ private boolean indexExists() throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.indexExists(TABLE, INDEX_NAME, connection);
+ }
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTable.java
new file mode 100644
index 00000000000..7920fe3c0fe
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddRuleUuidColumnToDeprecatedRuleKeysTable extends DdlChange {
+ private static final String TABLE = "deprecated_rule_keys";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddRuleUuidColumnToDeprecatedRuleKeysTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable.java
new file mode 100644
index 00000000000..047a4981073
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable.java
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+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 DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable extends DdlChange {
+
+ public DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable("deprecated_rule_keys")
+ .setName("rule_id_deprecated_rule_keys")
+ .build());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTable.java
new file mode 100644
index 00000000000..4c671299c08
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTable.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+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 DropRuleIdColumnOfDeprecatedRuleKeysTable extends DdlChange {
+
+ public DropRuleIdColumnOfDeprecatedRuleKeysTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "deprecated_rule_keys", "rule_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullable.java
new file mode 100644
index 00000000000..8023282925b
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeDeprecatedRuleKeysRuleUuidColumnNotNullable extends DdlChange {
+ private static final String TABLE = "deprecated_rule_keys";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeDeprecatedRuleKeysRuleUuidColumnNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+ .updateColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumn.java
new file mode 100644
index 00000000000..b58d8988bda
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumn.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+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 PopulateDeprecatedRuleKeysRuleUuidColumn extends DataChange {
+
+ public PopulateDeprecatedRuleKeysRuleUuidColumn(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select drk.rule_id, ru.uuid " +
+ "from deprecated_rule_keys drk " +
+ "join rules ru on drk.rule_id = ru.id " +
+ "where drk.rule_uuid is null");
+ massUpdate.update("update deprecated_rule_keys set rule_uuid = ? where rule_id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTable.java
new file mode 100644
index 00000000000..6e1a5a84447
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTable.java
@@ -0,0 +1,62 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+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 AddIndexToIssuesTable extends DdlChange {
+ private static final String TABLE = "issues";
+ private static final String INDEX_NAME = "issues_rule_uuid";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(true)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddIndexToIssuesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (!indexExists()) {
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE)
+ .setName(INDEX_NAME)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+ }
+
+ private boolean indexExists() throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.indexExists(TABLE, INDEX_NAME, connection);
+ }
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTable.java
new file mode 100644
index 00000000000..0808b9defc9
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTable.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddRuleUuidColumnToIssuesTable extends DdlChange {
+ private static final String TABLE = "issues";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(true)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddRuleUuidColumnToIssuesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTable.java
new file mode 100644
index 00000000000..f28152e0807
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTable.java
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+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 DropIndexOnRuleIdColumnOfIssuesTable extends DdlChange {
+
+ public DropIndexOnRuleIdColumnOfIssuesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable("issues")
+ .setName("issues_rule_id")
+ .build());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTable.java
new file mode 100644
index 00000000000..069d44556af
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTable.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+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 DropRuleIdColumnOfIssuesTable extends DdlChange {
+
+ public DropRuleIdColumnOfIssuesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "issues", "rule_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumn.java
new file mode 100644
index 00000000000..afa594c2692
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumn.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+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 PopulateIssuesRuleUuidColumn extends DataChange {
+
+ public PopulateIssuesRuleUuidColumn(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select iss.rule_id, ru.uuid " +
+ "from issues iss " +
+ "join rules ru on iss.rule_id = ru.id " +
+ "where iss.rule_uuid is null");
+ massUpdate.update("update issues set rule_uuid = ? where rule_id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable.java
new file mode 100644
index 00000000000..8eb875ecb8a
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable.java
@@ -0,0 +1,38 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+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.version.v83.util.AddPrimaryKeyBuilder;
+
+public class AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable extends DdlChange {
+
+ public AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddPrimaryKeyBuilder("rules_metadata", "rule_uuid", "organization_uuid").build());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTable.java
new file mode 100644
index 00000000000..5cfa390a7ec
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddRuleUuidColumnToRulesMetadataTable extends DdlChange {
+ private static final String TABLE = "rules_metadata";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddRuleUuidColumnToRulesMetadataTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTable.java
new file mode 100644
index 00000000000..ef9a32a26c6
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTable.java
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+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.version.v83.util.DropPrimaryKeySqlGenerator;
+
+public class DropPrimaryKeyOnIdColumnOfRulesMetadataTable extends DdlChange {
+
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator;
+
+ public DropPrimaryKeyOnIdColumnOfRulesMetadataTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
+ super(db);
+ this.dropPrimaryKeySqlGenerator = dropPrimaryKeySqlGenerator;
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(dropPrimaryKeySqlGenerator.generate("rules_metadata", "rule_id", false));
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTable.java
new file mode 100644
index 00000000000..cd1b7d8eb8e
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTable.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+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 DropRuleIdColumnOfRulesMetadataTable extends DdlChange {
+
+ public DropRuleIdColumnOfRulesMetadataTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "rules_metadata", "rule_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullable.java
new file mode 100644
index 00000000000..c71a1b9e32f
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeRulesMetadataRuleUuidColumnNotNullable extends DdlChange {
+ private static final String TABLE = "rules_metadata";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeRulesMetadataRuleUuidColumnNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+ .updateColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumn.java
new file mode 100644
index 00000000000..646ae438e41
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumn.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+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 PopulateRulesMetadataRuleUuidColumn extends DataChange {
+
+ public PopulateRulesMetadataRuleUuidColumn(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select rm.rule_id, ru.uuid " +
+ "from rules_metadata rm " +
+ "join rules ru on rm.rule_id = ru.id " +
+ "where rm.rule_uuid is null");
+ massUpdate.update("update rules_metadata set rule_uuid = ? where rule_id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTable.java
new file mode 100644
index 00000000000..aab7f110df7
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTable.java
@@ -0,0 +1,81 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+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 AddIndexesToRulesParametersTable extends DdlChange {
+ private static final String TABLE = "rules_parameters";
+ private static final String RULE_UUID_INDEX = "rules_parameters_rule_uuid";
+ private static final String RULE_UUID_NAME_UNIQUE_INDEX = "rules_parameters_unique";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ private static final VarcharColumnDef nameColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("name")
+ .setLimit(128)
+ .setIsNullable(false)
+ .build();
+
+ public AddIndexesToRulesParametersTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (indexDoesNotExist(RULE_UUID_INDEX)) {
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE)
+ .setName(RULE_UUID_INDEX)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+
+ if (indexDoesNotExist(RULE_UUID_NAME_UNIQUE_INDEX)) {
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE)
+ .setName(RULE_UUID_NAME_UNIQUE_INDEX)
+ .addColumn(uuidColumnDefinition)
+ .addColumn(nameColumnDefinition)
+ .setUnique(true)
+ .build());
+ }
+ }
+
+ private boolean indexDoesNotExist(String index) throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return !DatabaseUtils.indexExists(TABLE, index, connection);
+ }
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTable.java
new file mode 100644
index 00000000000..edb9de28196
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddRuleUuidColumnToRulesParametersTable extends DdlChange {
+ private static final String TABLE = "rules_parameters";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddRuleUuidColumnToRulesParametersTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTable.java
new file mode 100644
index 00000000000..b512dfbecba
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTable.java
@@ -0,0 +1,45 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+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 DropIndexesOnRuleIdColumnOfRulesParametersTable extends DdlChange {
+
+ public DropIndexesOnRuleIdColumnOfRulesParametersTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable("rules_parameters")
+ .setName("rules_parameters_rule_id")
+ .build());
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable("rules_parameters")
+ .setName("rules_parameters_unique")
+ .build());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTable.java
new file mode 100644
index 00000000000..c078f553a83
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTable.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+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 DropRuleIdColumnOfRulesParametersTable extends DdlChange {
+
+ public DropRuleIdColumnOfRulesParametersTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "rules_parameters", "rule_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullable.java
new file mode 100644
index 00000000000..103ed3541d1
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeRulesParametersRuleUuidColumnNotNullable extends DdlChange {
+ private static final String TABLE = "rules_parameters";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeRulesParametersRuleUuidColumnNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+ .updateColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumn.java
new file mode 100644
index 00000000000..89a16ddc5b6
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumn.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+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 PopulateRulesParametersRuleUuidColumn extends DataChange {
+
+ public PopulateRulesParametersRuleUuidColumn(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select rp.rule_id, ru.uuid " +
+ "from rules_parameters rp " +
+ "join rules ru on rp.rule_id = ru.id " +
+ "where rp.rule_uuid is null");
+ massUpdate.update("update rules_parameters set rule_uuid = ? where rule_id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest.java
new file mode 100644
index 00000000000..d13c9e7300d
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyOnUuidColumnOfRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfRulesTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new AddPrimaryKeyOnUuidColumnOfRulesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertPrimaryKey("rules", "pk_rules", "uuid");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest.java
new file mode 100644
index 00000000000..f5c6c269cb3
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest.java
@@ -0,0 +1,66 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddUuidAndTemplateUuidColumnsToRulesTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddUuidAndTemplateUuidColumnsToRulesTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddUuidAndTemplateUuidColumnsToRules(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L);
+ insertRule(2L);
+ insertRule(3L);
+ insertRule(4L);
+ }
+
+ @Test
+ public void add_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("rules", "uuid", Types.VARCHAR, 40, true);
+
+ assertThat(db.countSql("select count(*) from rules"))
+ .isEqualTo(4);
+ }
+
+ private void insertRule(long id) {
+ db.executeInsert("rules",
+ "id", id,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest.java
new file mode 100644
index 00000000000..dcc9910b73f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropIdColumnOfRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfRulesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropIdColumnOfRulesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("rules", "id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest.java
new file mode 100644
index 00000000000..e49d5b9a201
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest.java
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+import org.sonar.server.platform.db.migration.version.v83.util.SqlHelper;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropPrimaryKeyOnIdColumnOfRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesTable(db.database(),
+ new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database())));
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertTableExists("rules");
+ db.assertPrimaryKey("rules", "pk_rules", "id");
+
+ underTest.execute();
+
+ db.assertNoPrimaryKey("rules");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest.java
new file mode 100644
index 00000000000..0bc6c4b94b3
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropTemplateIdColumnOfRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropTemplateIdColumnOfRulesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropTemplateIdColumnOfRulesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("rules", "template_id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest.java
new file mode 100644
index 00000000000..f1c661646a5
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeRulesUuidColumnNotNullableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeRulesUuidColumnNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeRulesUuidColumnNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("rules", "uuid", VARCHAR, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest.java
new file mode 100644
index 00000000000..3503979f94a
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest.java
@@ -0,0 +1,74 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import javax.annotation.Nullable;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateRulesTemplateUuidTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateRulesTemplateUuidTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateRulesTemplateUuid(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-1", 1L);
+ insertRule(2L, "uuid-2", 1L);
+ insertRule(3L, "uuid-3", null);
+ insertRule(4L, "uuid-4", 2L);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from rules"))
+ .isEqualTo(4);
+ assertThat(db.select("select uuid, template_id, template_uuid from rules"))
+ .extracting(m -> m.get("UUID"), m -> m.get("TEMPLATE_ID"), m -> m.get("TEMPLATE_UUID"))
+ .containsExactlyInAnyOrder(
+ tuple("uuid-1", 1L, "uuid-1"),
+ tuple("uuid-2", 1L, "uuid-1"),
+ tuple("uuid-3", null, null),
+ tuple("uuid-4", 2L, "uuid-2"));
+ }
+
+ private void insertRule(long id, String uuid, @Nullable Long templateId) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "template_id", templateId,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest.java
new file mode 100644
index 00000000000..5c4d8bae2bd
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest.java
@@ -0,0 +1,75 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+import static org.mockito.ArgumentMatchers.anyString;
+
+public class PopulateRulesUuidTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateRulesUuidTest.class, "schema.sql");
+
+ private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+ private DataChange underTest = new PopulateRulesUuid(db.database(), uuidFactory);
+
+ @Before
+ public void setup() {
+ insertRule(1L);
+ insertRule(2L);
+ insertRule(3L);
+ insertRule(4L);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from rules"))
+ .isEqualTo(4);
+ assertThat(db.select("select uuid from rules")
+ .stream()
+ .map(row -> row.get("UUID"))
+ .filter(Objects::isNull)
+ .collect(Collectors.toList())).isEmpty();
+ }
+
+ private void insertRule(long id) {
+ db.executeInsert("rules",
+ "id", id,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest.java
new file mode 100644
index 00000000000..fd4282d750f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest.java
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class AddIndexToActiveRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddIndexToActiveRulesTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new AddIndexToActiveRulesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertUniqueIndex("active_rules", "uniq_profile_rule_uuids", "profile_uuid", "rule_uuid");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertUniqueIndex("active_rules", "uniq_profile_rule_uuids", "profile_uuid", "rule_uuid");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest.java
new file mode 100644
index 00000000000..3b660a6cac0
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest.java
@@ -0,0 +1,79 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddRuleUuidColumnToActiveRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddRuleUuidColumnToActiveRulesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddRuleUuidColumnToActiveRulesTable(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+ insertRule(4L, "uuid-rule-4");
+
+ insertActiveRule("uuid-ar-1", 1L, "uuid-profile-1");
+ insertActiveRule("uuid-ar-2", 1L, "uuid-profile-2");
+ insertActiveRule("uuid-ar-3", 2L, "uuid-profile-1");
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("active_rules", "rule_uuid", Types.VARCHAR, 40, true);
+ assertThat(db.countSql("select count(*) from active_rules"))
+ .isEqualTo(3);
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertActiveRule(String uuid, long ruleId, String profileUuid) {
+ db.executeInsert("active_rules",
+ "uuid", uuid,
+ "rule_id", ruleId,
+ "profile_uuid", profileUuid,
+ "failure_level", 1);
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest.java
new file mode 100644
index 00000000000..4cd93709c2f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest.java
@@ -0,0 +1,54 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class DropIndexOnRuleIdColumnOfActiveRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnRuleIdColumnOfActiveRulesTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropIndexOnRuleIdColumnOfActiveRulesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertTableExists("active_rules");
+ db.assertUniqueIndex("active_rules", "uniq_profile_rule_ids", "profile_uuid", "rule_id");
+
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("active_rules", "uniq_profile_rule_ids");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("active_rules", "uniq_profile_rule_ids");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest.java
new file mode 100644
index 00000000000..b8c2a7a0285
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropRuleIdColumnOfActiveRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropRuleIdColumnOfActiveRulesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropRuleIdColumnOfActiveRulesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("active_rules", "id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest.java
new file mode 100644
index 00000000000..98a0fe477e4
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeActiveRulesRuleUuidColumnNotNullableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeActiveRulesRuleUuidColumnNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeActiveRulesRuleUuidColumnNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("active_rules", "rule_uuid", VARCHAR, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest.java
new file mode 100644
index 00000000000..9431c36ab30
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest.java
@@ -0,0 +1,84 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateActiveRulesRuleUuidColumnTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateActiveRulesRuleUuidColumnTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateActiveRulesRuleUuidColumn(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+ insertRule(4L, "uuid-rule-4");
+
+ insertActiveRule("uuid-ar-1", 1L, "uuid-profile-1");
+ insertActiveRule("uuid-ar-2", 1L, "uuid-profile-2");
+ insertActiveRule("uuid-ar-3", 2L, "uuid-profile-1");
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from active_rules"))
+ .isEqualTo(3);
+ assertThat(db.select("select uuid, rule_id, rule_uuid from active_rules"))
+ .extracting(m -> m.get("UUID"), m -> m.get("RULE_ID"), m -> m.get("RULE_UUID"))
+ .containsExactlyInAnyOrder(
+ tuple("uuid-ar-1", 1L, "uuid-rule-1"),
+ tuple("uuid-ar-2", 1L, "uuid-rule-1"),
+ tuple("uuid-ar-3", 2L, "uuid-rule-2"));
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertActiveRule(String uuid, long ruleId, String profileUuid) {
+ db.executeInsert("active_rules",
+ "uuid", uuid,
+ "rule_id", ruleId,
+ "profile_uuid", profileUuid,
+ "failure_level", 1);
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest.java
new file mode 100644
index 00000000000..aa35897ee63
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest.java
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class AddIndexToDeprecatedRuleKeysTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddIndexToDeprecatedRuleKeysTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new AddIndexToDeprecatedRuleKeysTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertIndex("deprecated_rule_keys", "rule_uuid_deprecated_rule_keys", "rule_uuid");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndex("deprecated_rule_keys", "rule_uuid_deprecated_rule_keys", "rule_uuid");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest.java
new file mode 100644
index 00000000000..63fe5aabc74
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest.java
@@ -0,0 +1,80 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddRuleUuidColumnToDeprecatedRuleKeysTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddRuleUuidColumnToDeprecatedRuleKeysTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddRuleUuidColumnToDeprecatedRuleKeysTable(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+
+ insertDeprecatedRuleKeyRow("uuid-drk-1", 1L);
+ insertDeprecatedRuleKeyRow("uuid-drk-2", 1L);
+ insertDeprecatedRuleKeyRow("uuid-drk-3", 2L);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("deprecated_rule_keys", "rule_uuid", Types.VARCHAR, 40, true);
+ assertThat(db.countSql("select count(*) from deprecated_rule_keys"))
+ .isEqualTo(3);
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertDeprecatedRuleKeyRow(String uuid, long ruleId) {
+ db.executeInsert("deprecated_rule_keys",
+ "uuid", uuid,
+ "rule_id", ruleId,
+ "old_repository_key", "old-repo-key" + uuid,
+ "old_rule_key", "old-rule-key" + uuid,
+ "created_at", System2.INSTANCE.now());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest.java
new file mode 100644
index 00000000000..242bda7ec84
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest.java
@@ -0,0 +1,54 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertTableExists("deprecated_rule_keys");
+ db.assertIndex("deprecated_rule_keys", "rule_id_deprecated_rule_keys", "rule_id");
+
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("deprecated_rule_keys", "rule_id_deprecated_rule_keys");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("deprecated_rule_keys", "rule_id_deprecated_rule_keys");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest.java
new file mode 100644
index 00000000000..c733836c101
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropRuleIdColumnOfDeprecatedRuleKeysTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropRuleIdColumnOfDeprecatedRuleKeysTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropRuleIdColumnOfDeprecatedRuleKeysTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("deprecated_rule_keys", "id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest.java
new file mode 100644
index 00000000000..25d4c0d689e
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeDeprecatedRuleKeysRuleUuidColumnNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("deprecated_rule_keys", "rule_uuid", VARCHAR, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest.java
new file mode 100644
index 00000000000..6621b2b96f2
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest.java
@@ -0,0 +1,86 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateDeprecatedRuleKeysRuleUuidColumnTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateDeprecatedRuleKeysRuleUuidColumnTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateDeprecatedRuleKeysRuleUuidColumn(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+ insertRule(4L, "uuid-rule-4");
+
+ insertDeprecatedRuleKeyRow("uuid-drk-1", 1L);
+ insertDeprecatedRuleKeyRow("uuid-drk-2", 1L);
+ insertDeprecatedRuleKeyRow("uuid-drk-3", 2L);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from deprecated_rule_keys"))
+ .isEqualTo(3);
+ assertThat(db.select("select uuid, rule_id, rule_uuid from deprecated_rule_keys"))
+ .extracting(m -> m.get("UUID"), m -> m.get("RULE_ID"), m -> m.get("RULE_UUID"))
+ .containsExactlyInAnyOrder(
+ tuple("uuid-drk-1", 1L, "uuid-rule-1"),
+ tuple("uuid-drk-2", 1L, "uuid-rule-1"),
+ tuple("uuid-drk-3", 2L, "uuid-rule-2"));
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertDeprecatedRuleKeyRow(String uuid, long ruleId) {
+ db.executeInsert("deprecated_rule_keys",
+ "uuid", uuid,
+ "rule_id", ruleId,
+ "old_repository_key", "old-repo-key" + uuid,
+ "old_rule_key", "old-rule-key" + uuid,
+ "created_at", System2.INSTANCE.now());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest.java
new file mode 100644
index 00000000000..6433bd453fb
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest.java
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class AddIndexToIssuesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddIndexToIssuesTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new AddIndexToIssuesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertIndex("issues", "issues_rule_uuid", "rule_uuid");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndex("issues", "issues_rule_uuid", "rule_uuid");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest.java
new file mode 100644
index 00000000000..4e62b298628
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest.java
@@ -0,0 +1,81 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import javax.annotation.Nullable;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddRuleUuidColumnToIssuesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddRuleUuidColumnToIssuesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddRuleUuidColumnToIssuesTable(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+ insertRule(4L, "uuid-rule-4");
+
+ insertIssue("kee-iss-1", 1L);
+ insertIssue("kee-iss-2", 1L);
+ insertIssue("kee-iss-3", 2L);
+ insertIssue("kee-iss-4", null);
+ insertIssue("kee-iss-5", null);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("issues", "rule_uuid", Types.VARCHAR, 40, true);
+ assertThat(db.countSql("select count(*) from issues"))
+ .isEqualTo(5);
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertIssue(String kee, @Nullable Long ruleId) {
+ db.executeInsert("issues",
+ "kee", kee,
+ "rule_id", ruleId,
+ "manual_severity", false);
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest.java
new file mode 100644
index 00000000000..dfe194f3465
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest.java
@@ -0,0 +1,54 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class DropIndexOnRuleIdColumnOfIssuesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnRuleIdColumnOfIssuesTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropIndexOnRuleIdColumnOfIssuesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertTableExists("issues");
+ db.assertIndex("issues", "issues_rule_id", "rule_id");
+
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("issues", "issues_rule_id");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("issues", "issues_rule_id");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest.java
new file mode 100644
index 00000000000..b529a45245d
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropRuleIdColumnOfIssuesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropRuleIdColumnOfIssuesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropRuleIdColumnOfIssuesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("issues", "id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest.java
new file mode 100644
index 00000000000..5de76c19f38
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest.java
@@ -0,0 +1,87 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.SQLException;
+import javax.annotation.Nullable;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateIssuesRuleUuidColumnTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateIssuesRuleUuidColumnTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateIssuesRuleUuidColumn(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+ insertRule(4L, "uuid-rule-4");
+
+ insertIssue("kee-iss-1", 1L);
+ insertIssue("kee-iss-2", 1L);
+ insertIssue("kee-iss-3", 2L);
+ insertIssue("kee-iss-4", null);
+ insertIssue("kee-iss-5", null);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from issues")).isEqualTo(5);
+ assertThat(db.select("select kee, rule_id, rule_uuid from issues"))
+ .extracting(m -> m.get("KEE"), m -> m.get("RULE_ID"), m -> m.get("RULE_UUID"))
+ .containsExactlyInAnyOrder(
+ tuple("kee-iss-1", 1L, "uuid-rule-1"),
+ tuple("kee-iss-2", 1L, "uuid-rule-1"),
+ tuple("kee-iss-3", 2L, "uuid-rule-2"),
+ tuple("kee-iss-4", null, null),
+ tuple("kee-iss-5", null, null));
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertIssue(String kee, @Nullable Long ruleId) {
+ db.executeInsert("issues",
+ "kee", kee,
+ "rule_id", ruleId,
+ "manual_severity", false);
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest.java
new file mode 100644
index 00000000000..992c26cf15b
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertPrimaryKey("rules_metadata", "pk_rules_metadata", "rule_uuid", "organization_uuid");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest.java
new file mode 100644
index 00000000000..64b45d13936
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest.java
@@ -0,0 +1,80 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddRuleUuidColumnToRulesMetadataTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddRuleUuidColumnToRulesMetadataTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddRuleUuidColumnToRulesMetadataTable(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+ insertRule(4L, "uuid-rule-4");
+
+ insertRuleMetadata(1L, "org-1");
+ insertRuleMetadata(1L, "org-2");
+ insertRuleMetadata(2L, "org-1");
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("rules_metadata", "rule_uuid", Types.VARCHAR, 40, true);
+ assertThat(db.countSql("select count(*) from rules_metadata"))
+ .isEqualTo(3);
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertRuleMetadata(long ruleId, String organizationUuid) {
+ db.executeInsert("rules_metadata",
+ "rule_id", ruleId,
+ "organization_uuid", organizationUuid,
+ "created_at", System2.INSTANCE.now(),
+ "updated_at", System2.INSTANCE.now());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.java
new file mode 100644
index 00000000000..e2b617b16ba
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.java
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+import org.sonar.server.platform.db.migration.version.v83.util.SqlHelper;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesMetadataTable(db.database(),
+ new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database())));
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertTableExists("rules_metadata");
+ db.assertPrimaryKey("rules_metadata", "pk_rules_metadata", "rule_id", "organization_uuid");
+
+ underTest.execute();
+
+ db.assertNoPrimaryKey("rules_metadata");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest.java
new file mode 100644
index 00000000000..24eeacc8495
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropRuleIdColumnOfRulesMetadataTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropRuleIdColumnOfRulesMetadataTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropRuleIdColumnOfRulesMetadataTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("rules_metadata", "id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest.java
new file mode 100644
index 00000000000..2fdb200fee3
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeRulesMetadataRuleUuidColumnNotNullableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeRulesMetadataRuleUuidColumnNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeRulesMetadataRuleUuidColumnNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("rules_metadata", "rule_uuid", VARCHAR, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest.java
new file mode 100644
index 00000000000..02333f271aa
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest.java
@@ -0,0 +1,85 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateRulesMetadataRuleUuidColumnTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateRulesMetadataRuleUuidColumnTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateRulesMetadataRuleUuidColumn(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+ insertRule(4L, "uuid-rule-4");
+
+ insertRuleMetadata(1L, "org-1");
+ insertRuleMetadata(1L, "org-2");
+ insertRuleMetadata(2L, "org-1");
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from rules_metadata"))
+ .isEqualTo(3);
+ assertThat(db.select("select rule_id, organization_uuid, rule_uuid from rules_metadata"))
+ .extracting(m -> m.get("RULE_ID"), m -> m.get("ORGANIZATION_UUID"), m -> m.get("RULE_UUID"))
+ .containsExactlyInAnyOrder(
+ tuple(1L, "org-1", "uuid-rule-1"),
+ tuple(1L, "org-2", "uuid-rule-1"),
+ tuple(2L, "org-1", "uuid-rule-2"));
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertRuleMetadata(long ruleId, String organizationUuid) {
+ db.executeInsert("rules_metadata",
+ "rule_id", ruleId,
+ "organization_uuid", organizationUuid,
+ "created_at", System2.INSTANCE.now(),
+ "updated_at", System2.INSTANCE.now());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest.java
new file mode 100644
index 00000000000..a442c2f1311
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest.java
@@ -0,0 +1,53 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class AddIndexesToRulesParametersTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddIndexesToRulesParametersTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new AddIndexesToRulesParametersTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertIndex("rules_parameters", "rules_parameters_rule_uuid", "rule_uuid");
+ db.assertUniqueIndex("rules_parameters", "rules_parameters_unique", "rule_uuid", "name");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndex("rules_parameters", "rules_parameters_rule_uuid", "rule_uuid");
+ db.assertUniqueIndex("rules_parameters", "rules_parameters_unique", "rule_uuid", "name");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest.java
new file mode 100644
index 00000000000..7a8d1d95d0f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest.java
@@ -0,0 +1,78 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddRuleUuidColumnToRulesParametersTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddRuleUuidColumnToRulesParametersTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddRuleUuidColumnToRulesParametersTable(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+
+ insertRulesParametersEntry("uuid-rp-1", 1L);
+ insertRulesParametersEntry("uuid-rp-2", 1L);
+ insertRulesParametersEntry("uuid-rp-3", 2L);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("rules_parameters", "rule_uuid", Types.VARCHAR, 40, true);
+ assertThat(db.countSql("select count(*) from rules_parameters"))
+ .isEqualTo(3);
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertRulesParametersEntry(String uuid, long ruleId) {
+ db.executeInsert("rules_parameters",
+ "uuid", uuid,
+ "rule_id", ruleId,
+ "name", "name-" + uuid,
+ "param_type", "STRING");
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest.java
new file mode 100644
index 00000000000..35418be3a2f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest.java
@@ -0,0 +1,57 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class DropIndexesOnRuleIdColumnOfRulesParametersTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIndexesOnRuleIdColumnOfRulesParametersTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropIndexesOnRuleIdColumnOfRulesParametersTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertTableExists("rules_parameters");
+ db.assertIndex("rules_parameters", "rules_parameters_rule_id", "rule_id");
+ db.assertUniqueIndex("rules_parameters", "rules_parameters_unique", "rule_id", "name");
+
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("rules_parameters", "rules_parameters_rule_id");
+ db.assertIndexDoesNotExist("rules_parameters", "rules_parameters_unique");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("rules_parameters", "rules_parameters_rule_id");
+ db.assertIndexDoesNotExist("rules_parameters", "rules_parameters_unique");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest.java
new file mode 100644
index 00000000000..7c4f9b3c242
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropRuleIdColumnOfRulesParametersTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropRuleIdColumnOfRulesParametersTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropRuleIdColumnOfRulesParametersTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("rules_parameters", "id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest.java
new file mode 100644
index 00000000000..b657984f530
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeRulesParametersRuleUuidColumnNotNullableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeRulesParametersRuleUuidColumnNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeRulesParametersRuleUuidColumnNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("rules_parameters", "rule_uuid", VARCHAR, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest.java
new file mode 100644
index 00000000000..4f8b401bc88
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest.java
@@ -0,0 +1,84 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateRulesParametersRuleUuidColumnTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateRulesParametersRuleUuidColumnTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateRulesParametersRuleUuidColumn(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+
+ insertRulesParametersEntry("uuid-rp-1", 1L);
+ insertRulesParametersEntry("uuid-rp-2", 1L);
+ insertRulesParametersEntry("uuid-rp-3", 2L);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from rules_parameters"))
+ .isEqualTo(3);
+ assertThat(db.select("select uuid, rule_id, rule_uuid from rules_parameters"))
+ .extracting(m -> m.get("UUID"), m -> m.get("RULE_ID"), m -> m.get("RULE_UUID"))
+ .containsExactlyInAnyOrder(
+ tuple("uuid-rp-1", 1L, "uuid-rule-1"),
+ tuple("uuid-rp-2", 1L, "uuid-rule-1"),
+ tuple("uuid-rp-3", 2L, "uuid-rule-2"));
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertRulesParametersEntry(String uuid, long ruleId) {
+ db.executeInsert("rules_parameters",
+ "uuid", uuid,
+ "rule_id", ruleId,
+ "name", "name-" + uuid,
+ "param_type", "STRING");
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest/schema.sql
new file mode 100644
index 00000000000..df25471a0ba
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest/schema.sql
@@ -0,0 +1,29 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest/schema.sql
new file mode 100644
index 00000000000..66e55fb1b3f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest/schema.sql
@@ -0,0 +1,29 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "TEMPLATE_ID" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest/schema.sql
new file mode 100644
index 00000000000..4045c3e578a
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest/schema.sql
@@ -0,0 +1,30 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest/schema.sql
new file mode 100644
index 00000000000..04dc8de79c8
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest/schema.sql
@@ -0,0 +1,30 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest/schema.sql
new file mode 100644
index 00000000000..ee19fb605ea
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest/schema.sql
@@ -0,0 +1,31 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "TEMPLATE_ID" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest/schema.sql
new file mode 100644
index 00000000000..e2d578ae008
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest/schema.sql
@@ -0,0 +1,31 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "TEMPLATE_ID" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40),
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest/schema.sql
new file mode 100644
index 00000000000..ee19fb605ea
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest/schema.sql
@@ -0,0 +1,31 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "TEMPLATE_ID" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest/schema.sql
new file mode 100644
index 00000000000..e2d578ae008
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest/schema.sql
@@ -0,0 +1,31 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "TEMPLATE_ID" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40),
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest/schema.sql
new file mode 100644
index 00000000000..b3b1b4d7c04
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest/schema.sql
@@ -0,0 +1,42 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ACTIVE_RULES"(
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_UUID" VARCHAR(40) NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest/schema.sql
new file mode 100644
index 00000000000..d05e47d8bc5
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest/schema.sql
@@ -0,0 +1,42 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ACTIVE_RULES"(
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_UUID", "RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest/schema.sql
new file mode 100644
index 00000000000..9156127c902
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest/schema.sql
@@ -0,0 +1,43 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ACTIVE_RULES"(
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_UUID" VARCHAR(40) NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_UUID", "RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest/schema.sql
new file mode 100644
index 00000000000..d786db82af6
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest/schema.sql
@@ -0,0 +1,43 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ACTIVE_RULES"(
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_UUID" VARCHAR(40) NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_UUIDS" ON "ACTIVE_RULES"("PROFILE_UUID", "RULE_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest/schema.sql
new file mode 100644
index 00000000000..ac68fc9c530
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest/schema.sql
@@ -0,0 +1,43 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ACTIVE_RULES"(
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_UUID" VARCHAR(40) NOT NULL,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_UUID", "RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest/schema.sql
new file mode 100644
index 00000000000..ac68fc9c530
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest/schema.sql
@@ -0,0 +1,43 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ACTIVE_RULES"(
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_UUID" VARCHAR(40) NOT NULL,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_UUID", "RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest/schema.sql
new file mode 100644
index 00000000000..7d99e6c84e9
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest/schema.sql
@@ -0,0 +1,41 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "DEPRECATED_RULE_KEYS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "OLD_REPOSITORY_KEY" VARCHAR(255) NOT NULL,
+ "OLD_RULE_KEY" VARCHAR(200) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "DEPRECATED_RULE_KEYS" ADD CONSTRAINT "PK_DEPRECATED_RULE_KEYS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("OLD_REPOSITORY_KEY", "OLD_RULE_KEY");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest/schema.sql
new file mode 100644
index 00000000000..5f7d81c739c
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest/schema.sql
@@ -0,0 +1,41 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "DEPRECATED_RULE_KEYS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "OLD_REPOSITORY_KEY" VARCHAR(255) NOT NULL,
+ "OLD_RULE_KEY" VARCHAR(200) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "DEPRECATED_RULE_KEYS" ADD CONSTRAINT "PK_DEPRECATED_RULE_KEYS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("OLD_REPOSITORY_KEY", "OLD_RULE_KEY");
+CREATE INDEX "RULE_ID_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql
new file mode 100644
index 00000000000..9f9a6ff004a
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql
@@ -0,0 +1,42 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "DEPRECATED_RULE_KEYS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "OLD_REPOSITORY_KEY" VARCHAR(255) NOT NULL,
+ "OLD_RULE_KEY" VARCHAR(200) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "DEPRECATED_RULE_KEYS" ADD CONSTRAINT "PK_DEPRECATED_RULE_KEYS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("OLD_REPOSITORY_KEY", "OLD_RULE_KEY");
+CREATE INDEX "RULE_ID_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql
new file mode 100644
index 00000000000..557f113a0c2
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql
@@ -0,0 +1,42 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "DEPRECATED_RULE_KEYS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "OLD_REPOSITORY_KEY" VARCHAR(255) NOT NULL,
+ "OLD_RULE_KEY" VARCHAR(200) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "DEPRECATED_RULE_KEYS" ADD CONSTRAINT "PK_DEPRECATED_RULE_KEYS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("OLD_REPOSITORY_KEY", "OLD_RULE_KEY");
+CREATE INDEX "RULE_UUID_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("RULE_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest/schema.sql
new file mode 100644
index 00000000000..a33abf46805
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest/schema.sql
@@ -0,0 +1,42 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "DEPRECATED_RULE_KEYS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "OLD_REPOSITORY_KEY" VARCHAR(255) NOT NULL,
+ "OLD_RULE_KEY" VARCHAR(200) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "DEPRECATED_RULE_KEYS" ADD CONSTRAINT "PK_DEPRECATED_RULE_KEYS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("OLD_REPOSITORY_KEY", "OLD_RULE_KEY");
+CREATE INDEX "RULE_ID_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest/schema.sql
new file mode 100644
index 00000000000..a33abf46805
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest/schema.sql
@@ -0,0 +1,42 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "DEPRECATED_RULE_KEYS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "OLD_REPOSITORY_KEY" VARCHAR(255) NOT NULL,
+ "OLD_RULE_KEY" VARCHAR(200) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "DEPRECATED_RULE_KEYS" ADD CONSTRAINT "PK_DEPRECATED_RULE_KEYS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("OLD_REPOSITORY_KEY", "OLD_RULE_KEY");
+CREATE INDEX "RULE_ID_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest/schema.sql
new file mode 100644
index 00000000000..d02b9c74ec2
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest/schema.sql
@@ -0,0 +1,69 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ISSUES"(
+ "KEE" VARCHAR(50) NOT NULL,
+ "RULE_ID" INTEGER,
+ "SEVERITY" VARCHAR(10),
+ "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+ "MESSAGE" VARCHAR(4000),
+ "LINE" INTEGER,
+ "GAP" DOUBLE,
+ "STATUS" VARCHAR(20),
+ "RESOLUTION" VARCHAR(20),
+ "CHECKSUM" VARCHAR(1000),
+ "REPORTER" VARCHAR(255),
+ "ASSIGNEE" VARCHAR(255),
+ "AUTHOR_LOGIN" VARCHAR(255),
+ "ACTION_PLAN_KEY" VARCHAR(50),
+ "ISSUE_ATTRIBUTES" VARCHAR(4000),
+ "EFFORT" INTEGER,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "ISSUE_CREATION_DATE" BIGINT,
+ "ISSUE_UPDATE_DATE" BIGINT,
+ "ISSUE_CLOSE_DATE" BIGINT,
+ "TAGS" VARCHAR(4000),
+ "COMPONENT_UUID" VARCHAR(50),
+ "PROJECT_UUID" VARCHAR(50),
+ "LOCATIONS" BLOB,
+ "ISSUE_TYPE" TINYINT,
+ "FROM_HOTSPOT" BOOLEAN,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
+CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
+CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
+CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
+CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
+CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
+CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
+CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest/schema.sql
new file mode 100644
index 00000000000..89488e5506f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest/schema.sql
@@ -0,0 +1,69 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ISSUES"(
+ "KEE" VARCHAR(50) NOT NULL,
+ "RULE_ID" INTEGER,
+ "SEVERITY" VARCHAR(10),
+ "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+ "MESSAGE" VARCHAR(4000),
+ "LINE" INTEGER,
+ "GAP" DOUBLE,
+ "STATUS" VARCHAR(20),
+ "RESOLUTION" VARCHAR(20),
+ "CHECKSUM" VARCHAR(1000),
+ "REPORTER" VARCHAR(255),
+ "ASSIGNEE" VARCHAR(255),
+ "AUTHOR_LOGIN" VARCHAR(255),
+ "ACTION_PLAN_KEY" VARCHAR(50),
+ "ISSUE_ATTRIBUTES" VARCHAR(4000),
+ "EFFORT" INTEGER,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "ISSUE_CREATION_DATE" BIGINT,
+ "ISSUE_UPDATE_DATE" BIGINT,
+ "ISSUE_CLOSE_DATE" BIGINT,
+ "TAGS" VARCHAR(4000),
+ "COMPONENT_UUID" VARCHAR(50),
+ "PROJECT_UUID" VARCHAR(50),
+ "LOCATIONS" BLOB,
+ "ISSUE_TYPE" TINYINT,
+ "FROM_HOTSPOT" BOOLEAN
+);
+ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
+CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
+CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
+CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
+CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
+CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
+CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
+CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID");
+CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest/schema.sql
new file mode 100644
index 00000000000..d6c8f6b855e
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest/schema.sql
@@ -0,0 +1,70 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ISSUES"(
+ "KEE" VARCHAR(50) NOT NULL,
+ "RULE_ID" INTEGER,
+ "SEVERITY" VARCHAR(10),
+ "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+ "MESSAGE" VARCHAR(4000),
+ "LINE" INTEGER,
+ "GAP" DOUBLE,
+ "STATUS" VARCHAR(20),
+ "RESOLUTION" VARCHAR(20),
+ "CHECKSUM" VARCHAR(1000),
+ "REPORTER" VARCHAR(255),
+ "ASSIGNEE" VARCHAR(255),
+ "AUTHOR_LOGIN" VARCHAR(255),
+ "ACTION_PLAN_KEY" VARCHAR(50),
+ "ISSUE_ATTRIBUTES" VARCHAR(4000),
+ "EFFORT" INTEGER,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "ISSUE_CREATION_DATE" BIGINT,
+ "ISSUE_UPDATE_DATE" BIGINT,
+ "ISSUE_CLOSE_DATE" BIGINT,
+ "TAGS" VARCHAR(4000),
+ "COMPONENT_UUID" VARCHAR(50),
+ "PROJECT_UUID" VARCHAR(50),
+ "LOCATIONS" BLOB,
+ "ISSUE_TYPE" TINYINT,
+ "FROM_HOTSPOT" BOOLEAN,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
+CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
+CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
+CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
+CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
+CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
+CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
+CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID");
+CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest/schema.sql
new file mode 100644
index 00000000000..a2da6523742
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest/schema.sql
@@ -0,0 +1,70 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ISSUES"(
+ "KEE" VARCHAR(50) NOT NULL,
+ "RULE_ID" INTEGER,
+ "SEVERITY" VARCHAR(10),
+ "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+ "MESSAGE" VARCHAR(4000),
+ "LINE" INTEGER,
+ "GAP" DOUBLE,
+ "STATUS" VARCHAR(20),
+ "RESOLUTION" VARCHAR(20),
+ "CHECKSUM" VARCHAR(1000),
+ "REPORTER" VARCHAR(255),
+ "ASSIGNEE" VARCHAR(255),
+ "AUTHOR_LOGIN" VARCHAR(255),
+ "ACTION_PLAN_KEY" VARCHAR(50),
+ "ISSUE_ATTRIBUTES" VARCHAR(4000),
+ "EFFORT" INTEGER,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "ISSUE_CREATION_DATE" BIGINT,
+ "ISSUE_UPDATE_DATE" BIGINT,
+ "ISSUE_CLOSE_DATE" BIGINT,
+ "TAGS" VARCHAR(4000),
+ "COMPONENT_UUID" VARCHAR(50),
+ "PROJECT_UUID" VARCHAR(50),
+ "LOCATIONS" BLOB,
+ "ISSUE_TYPE" TINYINT,
+ "FROM_HOTSPOT" BOOLEAN,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
+CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
+CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
+CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
+CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
+CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
+CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
+CREATE INDEX "ISSUES_RULE_UUID" ON "ISSUES"("RULE_UUID");
+CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest/schema.sql
new file mode 100644
index 00000000000..d6c8f6b855e
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest/schema.sql
@@ -0,0 +1,70 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ISSUES"(
+ "KEE" VARCHAR(50) NOT NULL,
+ "RULE_ID" INTEGER,
+ "SEVERITY" VARCHAR(10),
+ "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+ "MESSAGE" VARCHAR(4000),
+ "LINE" INTEGER,
+ "GAP" DOUBLE,
+ "STATUS" VARCHAR(20),
+ "RESOLUTION" VARCHAR(20),
+ "CHECKSUM" VARCHAR(1000),
+ "REPORTER" VARCHAR(255),
+ "ASSIGNEE" VARCHAR(255),
+ "AUTHOR_LOGIN" VARCHAR(255),
+ "ACTION_PLAN_KEY" VARCHAR(50),
+ "ISSUE_ATTRIBUTES" VARCHAR(4000),
+ "EFFORT" INTEGER,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "ISSUE_CREATION_DATE" BIGINT,
+ "ISSUE_UPDATE_DATE" BIGINT,
+ "ISSUE_CLOSE_DATE" BIGINT,
+ "TAGS" VARCHAR(4000),
+ "COMPONENT_UUID" VARCHAR(50),
+ "PROJECT_UUID" VARCHAR(50),
+ "LOCATIONS" BLOB,
+ "ISSUE_TYPE" TINYINT,
+ "FROM_HOTSPOT" BOOLEAN,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
+CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
+CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
+CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
+CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
+CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
+CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
+CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID");
+CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest/schema.sql
new file mode 100644
index 00000000000..7e46834a915
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest/schema.sql
@@ -0,0 +1,50 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_METADATA"(
+ "RULE_ID" INTEGER NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "NOTE_DATA" CLOB(2147483647),
+ "NOTE_USER_UUID" VARCHAR(255),
+ "NOTE_CREATED_AT" BIGINT,
+ "NOTE_UPDATED_AT" BIGINT,
+ "REMEDIATION_FUNCTION" VARCHAR(20),
+ "REMEDIATION_GAP_MULT" VARCHAR(20),
+ "REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "TAGS" VARCHAR(4000),
+ "AD_HOC_NAME" VARCHAR(200),
+ "AD_HOC_DESCRIPTION" CLOB(2147483647),
+ "AD_HOC_SEVERITY" VARCHAR(10),
+ "AD_HOC_TYPE" TINYINT,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest/schema.sql
new file mode 100644
index 00000000000..6dd1263edd1
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest/schema.sql
@@ -0,0 +1,50 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_METADATA"(
+ "RULE_ID" INTEGER NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "NOTE_DATA" CLOB(2147483647),
+ "NOTE_USER_UUID" VARCHAR(255),
+ "NOTE_CREATED_AT" BIGINT,
+ "NOTE_UPDATED_AT" BIGINT,
+ "REMEDIATION_FUNCTION" VARCHAR(20),
+ "REMEDIATION_GAP_MULT" VARCHAR(20),
+ "REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "TAGS" VARCHAR(4000),
+ "AD_HOC_NAME" VARCHAR(200),
+ "AD_HOC_DESCRIPTION" CLOB(2147483647),
+ "AD_HOC_SEVERITY" VARCHAR(10),
+ "AD_HOC_TYPE" TINYINT,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "RULES_METADATA" ADD CONSTRAINT "PK_RULES_METADATA" PRIMARY KEY("RULE_ID", "ORGANIZATION_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest/schema.sql
new file mode 100644
index 00000000000..9f014613799
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest/schema.sql
@@ -0,0 +1,51 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_METADATA"(
+ "RULE_ID" INTEGER NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "NOTE_DATA" CLOB(2147483647),
+ "NOTE_USER_UUID" VARCHAR(255),
+ "NOTE_CREATED_AT" BIGINT,
+ "NOTE_UPDATED_AT" BIGINT,
+ "REMEDIATION_FUNCTION" VARCHAR(20),
+ "REMEDIATION_GAP_MULT" VARCHAR(20),
+ "REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "TAGS" VARCHAR(4000),
+ "AD_HOC_NAME" VARCHAR(200),
+ "AD_HOC_DESCRIPTION" CLOB(2147483647),
+ "AD_HOC_SEVERITY" VARCHAR(10),
+ "AD_HOC_TYPE" TINYINT,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "RULES_METADATA" ADD CONSTRAINT "PK_RULES_METADATA" PRIMARY KEY("RULE_ID", "ORGANIZATION_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest/schema.sql
new file mode 100644
index 00000000000..d7862acb77c
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest/schema.sql
@@ -0,0 +1,51 @@
+create TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+alter table "RULES" add CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+create UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_METADATA"(
+ "RULE_ID" INTEGER NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "NOTE_DATA" CLOB(2147483647),
+ "NOTE_USER_UUID" VARCHAR(255),
+ "NOTE_CREATED_AT" BIGINT,
+ "NOTE_UPDATED_AT" BIGINT,
+ "REMEDIATION_FUNCTION" VARCHAR(20),
+ "REMEDIATION_GAP_MULT" VARCHAR(20),
+ "REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "TAGS" VARCHAR(4000),
+ "AD_HOC_NAME" VARCHAR(200),
+ "AD_HOC_DESCRIPTION" CLOB(2147483647),
+ "AD_HOC_SEVERITY" VARCHAR(10),
+ "AD_HOC_TYPE" TINYINT,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "RULES_METADATA" ADD CONSTRAINT "PK_RULES_METADATA" PRIMARY KEY("RULE_UUID", "ORGANIZATION_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest/schema.sql
new file mode 100644
index 00000000000..9e725d8243b
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest/schema.sql
@@ -0,0 +1,51 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_METADATA"(
+ "RULE_ID" INTEGER NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "NOTE_DATA" CLOB(2147483647),
+ "NOTE_USER_UUID" VARCHAR(255),
+ "NOTE_CREATED_AT" BIGINT,
+ "NOTE_UPDATED_AT" BIGINT,
+ "REMEDIATION_FUNCTION" VARCHAR(20),
+ "REMEDIATION_GAP_MULT" VARCHAR(20),
+ "REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "TAGS" VARCHAR(4000),
+ "AD_HOC_NAME" VARCHAR(200),
+ "AD_HOC_DESCRIPTION" CLOB(2147483647),
+ "AD_HOC_SEVERITY" VARCHAR(10),
+ "AD_HOC_TYPE" TINYINT,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES_METADATA" ADD CONSTRAINT "PK_RULES_METADATA" PRIMARY KEY("RULE_ID", "ORGANIZATION_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest/schema.sql
new file mode 100644
index 00000000000..9e725d8243b
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest/schema.sql
@@ -0,0 +1,51 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_METADATA"(
+ "RULE_ID" INTEGER NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "NOTE_DATA" CLOB(2147483647),
+ "NOTE_USER_UUID" VARCHAR(255),
+ "NOTE_CREATED_AT" BIGINT,
+ "NOTE_UPDATED_AT" BIGINT,
+ "REMEDIATION_FUNCTION" VARCHAR(20),
+ "REMEDIATION_GAP_MULT" VARCHAR(20),
+ "REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "TAGS" VARCHAR(4000),
+ "AD_HOC_NAME" VARCHAR(200),
+ "AD_HOC_DESCRIPTION" CLOB(2147483647),
+ "AD_HOC_SEVERITY" VARCHAR(10),
+ "AD_HOC_TYPE" TINYINT,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES_METADATA" ADD CONSTRAINT "PK_RULES_METADATA" PRIMARY KEY("RULE_ID", "ORGANIZATION_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest/schema.sql
new file mode 100644
index 00000000000..13198189e57
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest/schema.sql
@@ -0,0 +1,41 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_PARAMETERS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "NAME" VARCHAR(128) NOT NULL,
+ "DESCRIPTION" VARCHAR(4000),
+ "PARAM_TYPE" VARCHAR(512) NOT NULL,
+ "DEFAULT_VALUE" VARCHAR(4000),
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest/schema.sql
new file mode 100644
index 00000000000..88e9e77a4e3
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest/schema.sql
@@ -0,0 +1,42 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_PARAMETERS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "NAME" VARCHAR(128) NOT NULL,
+ "DESCRIPTION" VARCHAR(4000),
+ "PARAM_TYPE" VARCHAR(512) NOT NULL,
+ "DEFAULT_VALUE" VARCHAR(4000)
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID");
+CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest/schema.sql
new file mode 100644
index 00000000000..81bbe5119c2
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest/schema.sql
@@ -0,0 +1,43 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_PARAMETERS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "NAME" VARCHAR(128) NOT NULL,
+ "DESCRIPTION" VARCHAR(4000),
+ "PARAM_TYPE" VARCHAR(512) NOT NULL,
+ "DEFAULT_VALUE" VARCHAR(4000),
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID");
+CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest/schema.sql
new file mode 100644
index 00000000000..eafb90192e1
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest/schema.sql
@@ -0,0 +1,43 @@
+create TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+alter table "RULES" add CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+create UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+create TABLE "RULES_PARAMETERS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "NAME" VARCHAR(128) NOT NULL,
+ "DESCRIPTION" VARCHAR(4000),
+ "PARAM_TYPE" VARCHAR(512) NOT NULL,
+ "DEFAULT_VALUE" VARCHAR(4000),
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+alter table "RULES_PARAMETERS" add CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID");
+create INDEX "RULES_PARAMETERS_RULE_UUID" ON "RULES_PARAMETERS"("RULE_UUID");
+create UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_UUID", "NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest/schema.sql
new file mode 100644
index 00000000000..9fdc54dfb08
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest/schema.sql
@@ -0,0 +1,43 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_PARAMETERS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "NAME" VARCHAR(128) NOT NULL,
+ "DESCRIPTION" VARCHAR(4000),
+ "PARAM_TYPE" VARCHAR(512) NOT NULL,
+ "DEFAULT_VALUE" VARCHAR(4000),
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID");
+CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest/schema.sql
new file mode 100644
index 00000000000..9fdc54dfb08
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest/schema.sql
@@ -0,0 +1,43 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_PARAMETERS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "NAME" VARCHAR(128) NOT NULL,
+ "DESCRIPTION" VARCHAR(4000),
+ "PARAM_TYPE" VARCHAR(512) NOT NULL,
+ "DEFAULT_VALUE" VARCHAR(4000),
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID");
+CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");