From 342a9d6f63c3a41c786647b82bc4c7312fe46157 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 7 Dec 2016 14:02:14 +0100 Subject: [PATCH] SONAR-5471 move creation of 5.6+ indices to Java migrations --- ...2_remove_useless_indexes_on_group_roles.rb | 3 +- ...0_create_perm_templates_characteristics.rb | 10 +-- ...uuid_columns_not_null_on_resource_index.rb | 2 - ..._resource_index_rid_from_resource_index.rb | 6 +- .../1210_create_temporary_indices_for_1211.rb | 3 +- .../1212_drop_temporary_indices_of_1210.rb | 12 +--- ...nent_uuid_columns_not_null_on_snapshots.rb | 3 - ...drop_snapshot_project_id_from_snapshots.rb | 11 +--- ...add_index_on_component_uuid_of_measures.rb | 3 +- ..._drop_index_projects_uuid_from_projects.rb | 6 +- ..._make_uuid_columns_not_null_on_projects.rb | 2 - ...reate_index_projects_uuid_from_projects.rb | 2 +- ...op_index_projects_root_id_from_projects.rb | 6 +- ...5_add_unique_index_on_uuid_of_snapshots.rb | 2 +- ...sis_uuid_not_null_on_duplications_index.rb | 2 - ...tions_index_sid_from_duplications_index.rb | 6 +- ...2_make_analysis_uuid_not_null_on_events.rb | 2 - ...op_index_events_snapshot_id_from_events.rb | 6 +- ..._add_index_on_analysis_uuid_of_measures.rb | 3 +- ...drop_index_of_analysis_uuid_on_measures.rb | 4 +- ...gain_index_on_analysis_uuid_of_measures.rb | 2 +- ...op_indices_on_tree_columns_of_snapshots.rb | 13 +--- ...5_drop_index_on_snapshot_id_of_measures.rb | 6 +- .../migrate/1312_create_table_properties_2.rb | 1 - .../db/migrate/1314_drop_table_properties.rb | 3 +- .../db/migrate/1318_drop_table_activities.rb | 3 +- .../1400_create_table_organizations.rb | 1 - ...ion_uuid_in_unique_index_of_group_roles.rb | 4 +- .../1502_make_uuid_not_null_on_events.rb | 1 - .../sonar/db/version/MigrationStepModule.java | 40 +++++++++++ .../v56/RemoveUselessIndexesOnGroupRoles.java | 50 ++++++++++++++ .../v60/AddIndexOnAnalysisUuidOfMeasures.java | 46 +++++++++++++ .../AddIndexOnComponentUuidOfMeasures.java | 44 +++++++++++++ .../v60/AddUniqueIndexOnUuidOfSnapshots.java | 47 +++++++++++++ .../CreatePermTemplatesCharacteristics.java | 66 +++++++++++++++++++ .../v60/CreateTemporaryIndicesFor1211.java | 51 ++++++++++++++ ...icationsIndexSidFromDuplicationsIndex.java | 39 +++++++++++ .../DropIndexEventsSnapshotIdFromEvents.java | 40 +++++++++++ .../v60/DropIndexOnSnapshotIdOfMeasures.java | 39 +++++++++++ .../DropIndexProjectsRootIdFromProjects.java | 39 +++++++++++ .../DropIndexProjectsUuidFromProjects.java | 39 +++++++++++ .../DropIndicesOnTreeColumnsOfSnapshots.java | 46 +++++++++++++ ...DropResourceIndexRidFromResourceIndex.java | 41 ++++++++++++ .../DropSnapshotProjectIdFromSnapshots.java | 46 +++++++++++++ .../v60/DropTemporaryIndicesOf1210.java | 46 +++++++++++++ .../v60/MakeAnalysisUuidNotNullOnEvents.java | 11 +++- ...nalysisUuidNotNullOnDuplicationsIndex.java | 15 ++++- ...omponentUuidColumnsNotNullOnSnapshots.java | 19 +++++- .../v60/MakeUuidColumnsNotNullOnProjects.java | 11 +++- ...MakeUuidColumnsNotNullOnResourceIndex.java | 11 +++- ...RecreateIndexProjectsUuidFromProjects.java | 43 ++++++++++++ ...rilyDropIndexOfAnalysisUuidOnMeasures.java | 44 +++++++++++++ .../version/v61/CreateTableProperties2.java | 36 ++++++---- .../db/version/v61/DropTableActivities.java | 46 +++++++++++++ .../db/version/v61/DropTableProperties.java | 46 +++++++++++++ .../version/v62/CreateTableOrganizations.java | 16 ++++- ...nizationUuidInUniqueIndexOfGroupRoles.java | 56 ++++++++++++++++ .../version/v63/MakeUuidNotNullOnEvents.java | 13 +++- .../db/version/MigrationStepModuleTest.java | 2 +- 59 files changed, 1086 insertions(+), 130 deletions(-) create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v56/RemoveUselessIndexesOnGroupRoles.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/AddIndexOnAnalysisUuidOfMeasures.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/AddIndexOnComponentUuidOfMeasures.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/AddUniqueIndexOnUuidOfSnapshots.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/CreatePermTemplatesCharacteristics.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/CreateTemporaryIndicesFor1211.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexDuplicationsIndexSidFromDuplicationsIndex.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexEventsSnapshotIdFromEvents.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexOnSnapshotIdOfMeasures.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexProjectsRootIdFromProjects.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexProjectsUuidFromProjects.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/DropIndicesOnTreeColumnsOfSnapshots.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/DropResourceIndexRidFromResourceIndex.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/DropSnapshotProjectIdFromSnapshots.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/DropTemporaryIndicesOf1210.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/RecreateIndexProjectsUuidFromProjects.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/TemporarilyDropIndexOfAnalysisUuidOnMeasures.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v61/DropTableActivities.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v61/DropTableProperties.java create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v62/IncludeOrganizationUuidInUniqueIndexOfGroupRoles.java diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1152_remove_useless_indexes_on_group_roles.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1152_remove_useless_indexes_on_group_roles.rb index fb0d14e3965..47f831048f3 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1152_remove_useless_indexes_on_group_roles.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1152_remove_useless_indexes_on_group_roles.rb @@ -25,8 +25,7 @@ class RemoveUselessIndexesOnGroupRoles < ActiveRecord::Migration def self.up - remove_index :group_roles, :name => 'group_roles_group' - remove_index :group_roles, :name => 'group_roles_role' + execute_java_migration('org.sonar.db.version.v56.RemoveUselessIndexesOnGroupRoles') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1200_create_perm_templates_characteristics.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1200_create_perm_templates_characteristics.rb index d84fc3e034a..4ea89cdb1f3 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1200_create_perm_templates_characteristics.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1200_create_perm_templates_characteristics.rb @@ -23,15 +23,7 @@ class CreatePermTemplatesCharacteristics < ActiveRecord::Migration def self.up - create_table 'perm_tpl_characteristics' do |t| - t.column :template_id, :integer, :null => false - t.column :permission_key, :string, :null => false, :limit => 64 - t.column :with_project_creator, :boolean, :null => false, :default => false - t.column :created_at, :big_integer, :null => false - t.column :updated_at, :big_integer, :null => false - end - - add_index 'perm_tpl_characteristics', ['template_id','permission_key'], :name => 'uniq_perm_tpl_charac', :unique => true + execute_java_migration('org.sonar.db.version.v60.CreatePermTemplatesCharacteristics') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1204_make_uuid_columns_not_null_on_resource_index.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1204_make_uuid_columns_not_null_on_resource_index.rb index f9e37e03d79..915966315b5 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1204_make_uuid_columns_not_null_on_resource_index.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1204_make_uuid_columns_not_null_on_resource_index.rb @@ -25,7 +25,5 @@ class MakeUuidColumnsNotNullOnResourceIndex < ActiveRecord::Migration def self.up execute_java_migration('org.sonar.db.version.v60.MakeUuidColumnsNotNullOnResourceIndex') - - add_index :resource_index, :component_uuid, :name => 'resource_index_component' end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1205_drop_resource_index_rid_from_resource_index.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1205_drop_resource_index_rid_from_resource_index.rb index 301bc54182c..b41df473bdb 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1205_drop_resource_index_rid_from_resource_index.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1205_drop_resource_index_rid_from_resource_index.rb @@ -24,10 +24,6 @@ class DropResourceIndexRidFromResourceIndex < ActiveRecord::Migration def self.up - begin - remove_index :resource_index, :name => 'resource_index_rid' - rescue - #ignore - end + execute_java_migration('org.sonar.db.version.v60.DropResourceIndexRidFromResourceIndex') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1210_create_temporary_indices_for_1211.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1210_create_temporary_indices_for_1211.rb index 736441e04e7..adaa6baf1c8 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1210_create_temporary_indices_for_1211.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1210_create_temporary_indices_for_1211.rb @@ -24,7 +24,6 @@ class CreateTemporaryIndicesFor1211 < ActiveRecord::Migration def self.up - add_index :ce_activity, :snapshot_id, :name => 'ce_activity_snapshot_id' - add_index :duplications_index, :project_snapshot_id, :name => 'dup_index_psid' + execute_java_migration('org.sonar.db.version.v60.CreateTemporaryIndicesFor1211') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1212_drop_temporary_indices_of_1210.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1212_drop_temporary_indices_of_1210.rb index 8144ec86e45..c5193f927b7 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1212_drop_temporary_indices_of_1210.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1212_drop_temporary_indices_of_1210.rb @@ -24,17 +24,7 @@ class DropTemporaryIndicesOf1210 < ActiveRecord::Migration def self.up - drop_index_quietly :ce_activity, 'ce_activity_snapshot_id' - drop_index_quietly :duplications_index, 'dup_index_psid' + execute_java_migration('org.sonar.db.version.v60.DropTemporaryIndicesOf1210') end - private - - def self.drop_index_quietly(table, index) - begin - remove_index table, :name => index - rescue - #ignore - end - end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1213_make_component_uuid_columns_not_null_on_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1213_make_component_uuid_columns_not_null_on_snapshots.rb index 2991af91b88..cec3b032a2b 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1213_make_component_uuid_columns_not_null_on_snapshots.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1213_make_component_uuid_columns_not_null_on_snapshots.rb @@ -25,8 +25,5 @@ class MakeComponentUuidColumnsNotNullOnSnapshots < ActiveRecord::Migration def self.up execute_java_migration('org.sonar.db.version.v60.MakeComponentUuidColumnsNotNullOnSnapshots') - - add_index :snapshots, :component_uuid, :name => 'snapshot_component' - add_index :snapshots, :root_component_uuid, :name => 'snapshot_root_component' end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1214_drop_snapshot_project_id_from_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1214_drop_snapshot_project_id_from_snapshots.rb index 0d3854fe88c..bb9ddc23aab 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1214_drop_snapshot_project_id_from_snapshots.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1214_drop_snapshot_project_id_from_snapshots.rb @@ -24,15 +24,6 @@ class DropSnapshotProjectIdFromSnapshots < ActiveRecord::Migration def self.up - begin - remove_index :snapshots, :name => 'snapshot_project_id' - rescue - #ignore - end - begin - remove_index :snapshots, :name => 'snapshots_root_project_id' - rescue - #ignore - end + execute_java_migration('org.sonar.db.version.v60.DropSnapshotProjectIdFromSnapshots') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1221_add_index_on_component_uuid_of_measures.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1221_add_index_on_component_uuid_of_measures.rb index 764a32f8fae..17273925c3e 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1221_add_index_on_component_uuid_of_measures.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1221_add_index_on_component_uuid_of_measures.rb @@ -24,6 +24,7 @@ class AddIndexOnComponentUuidOfMeasures < ActiveRecord::Migration def self.up - add_index :project_measures, :component_uuid, :name => 'measures_component_uuid' + execute_java_migration('org.sonar.db.version.v60.AddIndexOnComponentUuidOfMeasures') end + end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1227_drop_index_projects_uuid_from_projects.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1227_drop_index_projects_uuid_from_projects.rb index a454b714deb..ab2419fb634 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1227_drop_index_projects_uuid_from_projects.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1227_drop_index_projects_uuid_from_projects.rb @@ -25,10 +25,6 @@ class DropIndexProjectsUuidFromProjects < ActiveRecord::Migration def self.up - begin - remove_index :projects, :name => 'projects_uuid' - rescue - #ignore - end + execute_java_migration('org.sonar.db.version.v60.DropIndexProjectsUuidFromProjects') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1228_make_uuid_columns_not_null_on_projects.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1228_make_uuid_columns_not_null_on_projects.rb index ae98cc7a0d5..684ca3d7a15 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1228_make_uuid_columns_not_null_on_projects.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1228_make_uuid_columns_not_null_on_projects.rb @@ -25,7 +25,5 @@ class MakeUuidColumnsNotNullOnProjects < ActiveRecord::Migration def self.up execute_java_migration('org.sonar.db.version.v60.MakeUuidColumnsNotNullOnProjects') - - add_index :projects, :root_uuid, :name => 'projects_root_uuid' end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1229_recreate_index_projects_uuid_from_projects.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1229_recreate_index_projects_uuid_from_projects.rb index 35687314ab2..52deb046223 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1229_recreate_index_projects_uuid_from_projects.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1229_recreate_index_projects_uuid_from_projects.rb @@ -25,6 +25,6 @@ class RecreateIndexProjectsUuidFromProjects < ActiveRecord::Migration def self.up - add_index :projects, :uuid, :name => 'projects_uuid' + execute_java_migration('org.sonar.db.version.v60.RecreateIndexProjectsUuidFromProjects') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1230_drop_index_projects_root_id_from_projects.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1230_drop_index_projects_root_id_from_projects.rb index 21209cb48cf..1e0b606af0b 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1230_drop_index_projects_root_id_from_projects.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1230_drop_index_projects_root_id_from_projects.rb @@ -24,10 +24,6 @@ class DropIndexProjectsRootIdFromProjects < ActiveRecord::Migration def self.up - begin - remove_index :projects, :name => 'projects_root_id' - rescue - #ignore - end + execute_java_migration('org.sonar.db.version.v60.DropIndexProjectsRootIdFromProjects') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1235_add_unique_index_on_uuid_of_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1235_add_unique_index_on_uuid_of_snapshots.rb index 973add64ea6..498397fcd6d 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1235_add_unique_index_on_uuid_of_snapshots.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1235_add_unique_index_on_uuid_of_snapshots.rb @@ -24,6 +24,6 @@ class AddUniqueIndexOnUuidOfSnapshots < ActiveRecord::Migration def self.up - add_index :snapshots, :uuid, :name => 'analyses_uuid', :unique => true + execute_java_migration('org.sonar.db.version.v60.AddUniqueIndexOnUuidOfSnapshots') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1242_make_component_uuid_and_analysis_uuid_not_null_on_duplications_index.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1242_make_component_uuid_and_analysis_uuid_not_null_on_duplications_index.rb index 72e090fe509..171d3750870 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1242_make_component_uuid_and_analysis_uuid_not_null_on_duplications_index.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1242_make_component_uuid_and_analysis_uuid_not_null_on_duplications_index.rb @@ -25,7 +25,5 @@ class MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex < ActiveRecord: def self.up execute_java_migration('org.sonar.db.version.v60.MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex') - - add_index :duplications_index, [:analysis_uuid, :component_uuid], :name => 'duplication_analysis_component' end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1243_drop_index_duplications_index_sid_from_duplications_index.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1243_drop_index_duplications_index_sid_from_duplications_index.rb index a2e53fef318..69f4ed2404f 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1243_drop_index_duplications_index_sid_from_duplications_index.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1243_drop_index_duplications_index_sid_from_duplications_index.rb @@ -24,10 +24,6 @@ class DropIndexDuplicationsIndexSidFromDuplicationsIndex < ActiveRecord::Migration def self.up - begin - remove_index :duplications_index, :name => 'duplications_index_sid' - rescue - #ignore - end + execute_java_migration('org.sonar.db.version.v60.DropIndexDuplicationsIndexSidFromDuplicationsIndex') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1252_make_analysis_uuid_not_null_on_events.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1252_make_analysis_uuid_not_null_on_events.rb index 294714a6b80..e9d5bf66abf 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1252_make_analysis_uuid_not_null_on_events.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1252_make_analysis_uuid_not_null_on_events.rb @@ -25,7 +25,5 @@ class MakeAnalysisUuidNotNullOnEvents < ActiveRecord::Migration def self.up execute_java_migration('org.sonar.db.version.v60.MakeAnalysisUuidNotNullOnEvents') - - add_index :events, :analysis_uuid, :name => 'events_analysis' end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1253_drop_index_events_snapshot_id_from_events.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1253_drop_index_events_snapshot_id_from_events.rb index fdadd1aebee..4c6206651ca 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1253_drop_index_events_snapshot_id_from_events.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1253_drop_index_events_snapshot_id_from_events.rb @@ -24,10 +24,6 @@ class DropIndexEventsSnapshotIdFromEvents < ActiveRecord::Migration def self.up - begin - remove_index :events, :name => 'events_snapshot_id' - rescue - #ignore - end + execute_java_migration('org.sonar.db.version.v60.DropIndexEventsSnapshotIdFromEvents') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1266_add_index_on_analysis_uuid_of_measures.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1266_add_index_on_analysis_uuid_of_measures.rb index 02b6a22bccf..afee48952a5 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1266_add_index_on_analysis_uuid_of_measures.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1266_add_index_on_analysis_uuid_of_measures.rb @@ -24,7 +24,6 @@ class AddIndexOnAnalysisUuidOfMeasures < ActiveRecord::Migration def self.up - # this index must be present for the performance of next migration - add_index :project_measures, [:analysis_uuid, :metric_id], :name => 'measures_analysis_metric' + execute_java_migration('org.sonar.db.version.v60.AddIndexOnAnalysisUuidOfMeasures') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1269_temporarily_drop_index_of_analysis_uuid_on_measures.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1269_temporarily_drop_index_of_analysis_uuid_on_measures.rb index 99c59a3d35f..1ecbdf3e392 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1269_temporarily_drop_index_of_analysis_uuid_on_measures.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1269_temporarily_drop_index_of_analysis_uuid_on_measures.rb @@ -24,8 +24,6 @@ class TemporarilyDropIndexOfAnalysisUuidOnMeasures < ActiveRecord::Migration def self.up - # the index must be dropped for the compatibility of migration 1270 - # with MSSQL - remove_index :project_measures, :name => 'measures_analysis_metric' + execute_java_migration('org.sonar.db.version.v60.TemporarilyDropIndexOfAnalysisUuidOnMeasures') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1271_add_again_index_on_analysis_uuid_of_measures.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1271_add_again_index_on_analysis_uuid_of_measures.rb index 7f70785815b..71d768a2193 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1271_add_again_index_on_analysis_uuid_of_measures.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1271_add_again_index_on_analysis_uuid_of_measures.rb @@ -24,6 +24,6 @@ class AddAgainIndexOnAnalysisUuidOfMeasures < ActiveRecord::Migration def self.up - add_index :project_measures, [:analysis_uuid, :metric_id], :name => 'measures_analysis_metric' + execute_java_migration('org.sonar.db.version.v60.AddIndexOnAnalysisUuidOfMeasures') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1273_drop_indices_on_tree_columns_of_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1273_drop_indices_on_tree_columns_of_snapshots.rb index 343ca0e5983..553e29a45e2 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1273_drop_indices_on_tree_columns_of_snapshots.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1273_drop_indices_on_tree_columns_of_snapshots.rb @@ -24,18 +24,7 @@ class DropIndicesOnTreeColumnsOfSnapshots < ActiveRecord::Migration def self.up - remove_index_quietly 'snapshots_qualifier' - remove_index_quietly 'snapshots_root' - remove_index_quietly 'snapshots_parent' - remove_index_quietly 'snapshot_root_component' + execute_java_migration('org.sonar.db.version.v60.DropIndicesOnTreeColumnsOfSnapshots') end - private - def self.remove_index_quietly(index_name) - begin - remove_index :snapshots, :name => index_name - rescue - #ignore - end - end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1275_drop_index_on_snapshot_id_of_measures.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1275_drop_index_on_snapshot_id_of_measures.rb index 79ce1df6e27..4f494796782 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1275_drop_index_on_snapshot_id_of_measures.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1275_drop_index_on_snapshot_id_of_measures.rb @@ -24,11 +24,7 @@ class DropIndexOnSnapshotIdOfMeasures < ActiveRecord::Migration def self.up - begin - remove_index :project_measures, :name => 'measures_sid_metric' - rescue - #ignore - end + execute_java_migration('org.sonar.db.version.v60.DropIndexOnSnapshotIdOfMeasures') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1312_create_table_properties_2.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1312_create_table_properties_2.rb index 075cad0d511..fe4686c17e5 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1312_create_table_properties_2.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1312_create_table_properties_2.rb @@ -25,6 +25,5 @@ class CreateTableProperties2 < ActiveRecord::Migration def self.up execute_java_migration('org.sonar.db.version.v61.CreateTableProperties2') - add_varchar_index :properties2, :prop_key, :name => 'properties2_key' end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1314_drop_table_properties.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1314_drop_table_properties.rb index 2815d353676..bef5d32ffa4 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1314_drop_table_properties.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1314_drop_table_properties.rb @@ -24,8 +24,7 @@ class DropTableProperties < ActiveRecord::Migration def self.up - drop_index_quietly :properties, :properties_key - drop_table :properties + execute_java_migration('org.sonar.db.version.v61.DropTableProperties') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1318_drop_table_activities.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1318_drop_table_activities.rb index 988b0336ce5..9e7cc271af0 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1318_drop_table_activities.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1318_drop_table_activities.rb @@ -24,8 +24,7 @@ class DropTableActivities < ActiveRecord::Migration def self.up - drop_index_quietly 'activities', 'activities_log_key' - drop_table 'activities' + execute_java_migration('org.sonar.db.version.v61.DropTableActivities') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1400_create_table_organizations.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1400_create_table_organizations.rb index 0c2105aabd6..61aa3c0fcd4 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1400_create_table_organizations.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1400_create_table_organizations.rb @@ -25,6 +25,5 @@ class CreateTableOrganizations < ActiveRecord::Migration def self.up execute_java_migration('org.sonar.db.version.v62.CreateTableOrganizations') - add_index :organizations, :kee, :name => 'organization_key' end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1418_include_organization_uuid_in_unique_index_of_group_roles.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1418_include_organization_uuid_in_unique_index_of_group_roles.rb index dc7b15aaffe..5aa3a844625 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1418_include_organization_uuid_in_unique_index_of_group_roles.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1418_include_organization_uuid_in_unique_index_of_group_roles.rb @@ -24,8 +24,6 @@ class IncludeOrganizationUuidInUniqueIndexOfGroupRoles < ActiveRecord::Migration def self.up - drop_index_quietly :group_roles, :uniq_group_roles - - add_index 'group_roles', ['organization_uuid', 'group_id', 'resource_id', 'role'], :unique => true, :name => 'uniq_group_roles' + execute_java_migration('org.sonar.db.version.v62.IncludeOrganizationUuidInUniqueIndexOfGroupRoles') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1502_make_uuid_not_null_on_events.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1502_make_uuid_not_null_on_events.rb index 02110478a03..8aee750daf7 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1502_make_uuid_not_null_on_events.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1502_make_uuid_not_null_on_events.rb @@ -25,6 +25,5 @@ class MakeUuidNotNullOnEvents < ActiveRecord::Migration def self.up execute_java_migration('org.sonar.db.version.v63.MakeUuidNotNullOnEvents') - add_index 'events', :uuid, :name => 'events_uuid', :unique => true end end diff --git a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java index 6267b24e2e2..d687d760a97 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java +++ b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java @@ -83,6 +83,7 @@ import org.sonar.db.version.v55.FeedRulesLongDateColumns; import org.sonar.db.version.v55.FeedRulesTypes; import org.sonar.db.version.v56.FixLengthOfIssuesMessageOnOracle; import org.sonar.db.version.v56.FixTypeOfRuleTypeOnMysql; +import org.sonar.db.version.v56.RemoveUselessIndexesOnGroupRoles; import org.sonar.db.version.v56.UpdateUsersExternalIdentityWhenEmpty; import org.sonar.db.version.v60.AddAnalysisUuidColumnToCeActivity; import org.sonar.db.version.v60.AddAnalysisUuidColumnToEvents; @@ -91,8 +92,11 @@ import org.sonar.db.version.v60.AddBColumnsToProjects; import org.sonar.db.version.v60.AddComponentUuidAndAnalysisUuidColumnToDuplicationsIndex; import org.sonar.db.version.v60.AddComponentUuidColumnToMeasures; import org.sonar.db.version.v60.AddComponentUuidColumnsToSnapshots; +import org.sonar.db.version.v60.AddIndexOnAnalysisUuidOfMeasures; +import org.sonar.db.version.v60.AddIndexOnComponentUuidOfMeasures; import org.sonar.db.version.v60.AddLastUsedColumnToRulesProfiles; import org.sonar.db.version.v60.AddProfileKeyToActivities; +import org.sonar.db.version.v60.AddUniqueIndexOnUuidOfSnapshots; import org.sonar.db.version.v60.AddUserUpdatedAtToRulesProfiles; import org.sonar.db.version.v60.AddUuidColumnToSnapshots; import org.sonar.db.version.v60.AddUuidColumnsToProjects; @@ -105,17 +109,28 @@ import org.sonar.db.version.v60.CleanOrphanRowsInProjects; import org.sonar.db.version.v60.CleanOrphanRowsInResourceIndex; import org.sonar.db.version.v60.CleanOrphanRowsInSnapshots; import org.sonar.db.version.v60.CleanUsurperRootComponents; +import org.sonar.db.version.v60.CreatePermTemplatesCharacteristics; +import org.sonar.db.version.v60.CreateTemporaryIndicesFor1211; import org.sonar.db.version.v60.DeleteOrphanDuplicationsIndexRowsWithoutComponentOrAnalysis; import org.sonar.db.version.v60.DeleteOrphanMeasuresWithoutComponent; import org.sonar.db.version.v60.DropIdColumnsFromProjects; import org.sonar.db.version.v60.DropIdColumnsFromResourceIndex; import org.sonar.db.version.v60.DropIdColumnsFromSnapshots; +import org.sonar.db.version.v60.DropIndexDuplicationsIndexSidFromDuplicationsIndex; +import org.sonar.db.version.v60.DropIndexEventsSnapshotIdFromEvents; +import org.sonar.db.version.v60.DropIndexOnSnapshotIdOfMeasures; +import org.sonar.db.version.v60.DropIndexProjectsRootIdFromProjects; +import org.sonar.db.version.v60.DropIndexProjectsUuidFromProjects; +import org.sonar.db.version.v60.DropIndicesOnTreeColumnsOfSnapshots; import org.sonar.db.version.v60.DropProjectIdColumnFromMeasures; import org.sonar.db.version.v60.DropRememberMeColumnsFromUsers; +import org.sonar.db.version.v60.DropResourceIndexRidFromResourceIndex; import org.sonar.db.version.v60.DropSnapshotIdColumnFromCeActivity; import org.sonar.db.version.v60.DropSnapshotIdColumnFromEvents; import org.sonar.db.version.v60.DropSnapshotIdColumnFromMeasures; import org.sonar.db.version.v60.DropSnapshotIdColumnsFromDuplicationsIndex; +import org.sonar.db.version.v60.DropSnapshotProjectIdFromSnapshots; +import org.sonar.db.version.v60.DropTemporaryIndicesOf1210; import org.sonar.db.version.v60.DropTreeColumnsFromSnapshots; import org.sonar.db.version.v60.DropTreesOfSnapshots; import org.sonar.db.version.v60.DropUnusedMeasuresColumns; @@ -143,7 +158,9 @@ import org.sonar.db.version.v60.PopulateUuidColumnOnSnapshots; import org.sonar.db.version.v60.PopulateUuidColumnsOfProjects; import org.sonar.db.version.v60.PopulateUuidColumnsOfResourceIndex; import org.sonar.db.version.v60.PopulateUuidPathColumnOnProjects; +import org.sonar.db.version.v60.RecreateIndexProjectsUuidFromProjects; import org.sonar.db.version.v60.RemoveUsersPasswordWhenNotLocal; +import org.sonar.db.version.v60.TemporarilyDropIndexOfAnalysisUuidOnMeasures; import org.sonar.db.version.v61.AddBUuidPathToProjects; import org.sonar.db.version.v61.AddErrorColumnsToCeActivity; import org.sonar.db.version.v61.CopyActivitiesToQprofileChanges; @@ -156,6 +173,8 @@ import org.sonar.db.version.v61.CreateTableScannerContext; import org.sonar.db.version.v61.DeleteProjectDashboards; import org.sonar.db.version.v61.DeleteReportsFromCeQueue; import org.sonar.db.version.v61.DropIsGlobalFromDashboards; +import org.sonar.db.version.v61.DropTableActivities; +import org.sonar.db.version.v61.DropTableProperties; import org.sonar.db.version.v61.PopulateTableProperties2; import org.sonar.db.version.v61.RemoveViewsDefinitionFromProperties; import org.sonar.db.version.v61.ShrinkModuleUuidPathOfProjects; @@ -171,6 +190,7 @@ import org.sonar.db.version.v62.DeletePermissionShareDashboard; import org.sonar.db.version.v62.DropIssueFiltersTables; import org.sonar.db.version.v62.DropMeasureFiltersTables; import org.sonar.db.version.v62.DropRelatedDashboardTables; +import org.sonar.db.version.v62.IncludeOrganizationUuidInUniqueIndexOfGroupRoles; import org.sonar.db.version.v62.MakeOrganizationUuidNotNullOnGroupRoles; import org.sonar.db.version.v62.MakeOrganizationUuidNotNullOnGroups; import org.sonar.db.version.v62.MakeOrganizationUuidNotNullOnPermissionTemplates; @@ -266,6 +286,7 @@ public class MigrationStepModule extends Module { DeleteManualRules.class, // 5.6 + RemoveUselessIndexesOnGroupRoles.class, FixTypeOfRuleTypeOnMysql.class, FixLengthOfIssuesMessageOnOracle.class, UpdateUsersExternalIdentityWhenEmpty.class, @@ -300,6 +321,11 @@ public class MigrationStepModule extends Module { MakeProfileKeyNotNullOnActivities.class, AddUserUpdatedAtToRulesProfiles.class, PopulateUserUpdatedAtOfRulesProfiles.class, + CreateTemporaryIndicesFor1211.class, + AddIndexOnComponentUuidOfMeasures.class, + RecreateIndexProjectsUuidFromProjects.class, + AddUniqueIndexOnUuidOfSnapshots.class, + AddIndexOnAnalysisUuidOfMeasures.class, // SNAPSHOTS.UUID AddUuidColumnToSnapshots.class, @@ -346,6 +372,17 @@ public class MigrationStepModule extends Module { DropTreeColumnsFromSnapshots.class, DropSnapshotIdColumnFromMeasures.class, AddBColumnsToProjects.class, + CreatePermTemplatesCharacteristics.class, + DropTemporaryIndicesOf1210.class, + DropResourceIndexRidFromResourceIndex.class, + DropSnapshotProjectIdFromSnapshots.class, + DropIndexProjectsUuidFromProjects.class, + DropIndexProjectsRootIdFromProjects.class, + DropIndexDuplicationsIndexSidFromDuplicationsIndex.class, + DropIndexEventsSnapshotIdFromEvents.class, + TemporarilyDropIndexOfAnalysisUuidOnMeasures.class, + DropIndexOnSnapshotIdOfMeasures.class, + DropIndicesOnTreeColumnsOfSnapshots.class, // 6.1 DeleteProjectDashboards.class, @@ -363,6 +400,8 @@ public class MigrationStepModule extends Module { CreateTableQprofileChanges.class, CopyActivitiesToQprofileChanges.class, CreateTableRuleRepositories.class, + DropTableActivities.class, + DropTableProperties.class, // 6.2 CreateTableOrganizations.class, @@ -388,6 +427,7 @@ public class MigrationStepModule extends Module { DropMeasureFiltersTables.class, DropIssueFiltersTables.class, CreateTableWebhookDeliveries.class, + IncludeOrganizationUuidInUniqueIndexOfGroupRoles.class, // 6.3 AddUuidToEvents.class, diff --git a/sonar-db/src/main/java/org/sonar/db/version/v56/RemoveUselessIndexesOnGroupRoles.java b/sonar-db/src/main/java/org/sonar/db/version/v56/RemoveUselessIndexesOnGroupRoles.java new file mode 100644 index 00000000000..36f1663aec3 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v56/RemoveUselessIndexesOnGroupRoles.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v56; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropIndexBuilder; + +/** + * SONAR-6613 + */ +public class RemoveUselessIndexesOnGroupRoles extends DdlChange { + + private static final String TABLE_NAME = "group_roles"; + + public RemoveUselessIndexesOnGroupRoles(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable(TABLE_NAME) + .setName("group_roles_group") + .build()); + + context.execute(new DropIndexBuilder(getDialect()) + .setTable(TABLE_NAME) + .setName("group_roles_role") + .build()); + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/AddIndexOnAnalysisUuidOfMeasures.java b/sonar-db/src/main/java/org/sonar/db/version/v60/AddIndexOnAnalysisUuidOfMeasures.java new file mode 100644 index 00000000000..b1dc968b876 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/AddIndexOnAnalysisUuidOfMeasures.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.CreateIndexBuilder; +import org.sonar.db.version.DdlChange; + +import static org.sonar.db.version.IntegerColumnDef.newIntegerColumnDefBuilder; +import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class AddIndexOnAnalysisUuidOfMeasures extends DdlChange { + + public AddIndexOnAnalysisUuidOfMeasures(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + // this index must be present for the performance of next migration + context.execute(new CreateIndexBuilder(getDialect()) + .setTable("project_measures") + .setName("measures_analysis_metric") + .addColumn(newVarcharColumnDefBuilder().setColumnName("analysis_uuid").setLimit(50).build()) + .addColumn(newIntegerColumnDefBuilder().setColumnName("metric_id").build()) + .build()); + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/AddIndexOnComponentUuidOfMeasures.java b/sonar-db/src/main/java/org/sonar/db/version/v60/AddIndexOnComponentUuidOfMeasures.java new file mode 100644 index 00000000000..7f408c87f91 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/AddIndexOnComponentUuidOfMeasures.java @@ -0,0 +1,44 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.CreateIndexBuilder; +import org.sonar.db.version.DdlChange; + +import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class AddIndexOnComponentUuidOfMeasures extends DdlChange { + + public AddIndexOnComponentUuidOfMeasures(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new CreateIndexBuilder(getDialect()) + .setTable("project_measures") + .setName("measures_component_uuid") + .addColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(50).build()) + .build()); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/AddUniqueIndexOnUuidOfSnapshots.java b/sonar-db/src/main/java/org/sonar/db/version/v60/AddUniqueIndexOnUuidOfSnapshots.java new file mode 100644 index 00000000000..a3ac5a83cd4 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/AddUniqueIndexOnUuidOfSnapshots.java @@ -0,0 +1,47 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.CreateIndexBuilder; +import org.sonar.db.version.DdlChange; + +import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class AddUniqueIndexOnUuidOfSnapshots extends DdlChange { + + public AddUniqueIndexOnUuidOfSnapshots(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new CreateIndexBuilder(getDialect()) + .setTable("snapshots") + .setName("analyses_uuid") + .addColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(50).build()) + .setUnique(true) + .build()); + } +} + + + diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/CreatePermTemplatesCharacteristics.java b/sonar-db/src/main/java/org/sonar/db/version/v60/CreatePermTemplatesCharacteristics.java new file mode 100644 index 00000000000..63ef5ddb9ec --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/CreatePermTemplatesCharacteristics.java @@ -0,0 +1,66 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.CreateIndexBuilder; +import org.sonar.db.version.CreateTableBuilder; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.IntegerColumnDef; +import org.sonar.db.version.VarcharColumnDef; + +import static org.sonar.db.version.BigIntegerColumnDef.newBigIntegerColumnDefBuilder; +import static org.sonar.db.version.BooleanColumnDef.newBooleanColumnDefBuilder; +import static org.sonar.db.version.CreateTableBuilder.ColumnFlag.AUTO_INCREMENT; +import static org.sonar.db.version.IntegerColumnDef.newIntegerColumnDefBuilder; +import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class CreatePermTemplatesCharacteristics extends DdlChange { + + private static final String TABLE_NAME = "perm_tpl_characteristics"; + + public CreatePermTemplatesCharacteristics(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + IntegerColumnDef templateIdColumn = newIntegerColumnDefBuilder().setColumnName("template_id").setIsNullable(false).build(); + VarcharColumnDef permissionKeyColumn = newVarcharColumnDefBuilder().setColumnName("permission_key").setLimit(64).setIsNullable(false).build(); + context.execute( + new CreateTableBuilder(getDialect(), TABLE_NAME) + .addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT) + .addColumn(templateIdColumn) + .addColumn(permissionKeyColumn) + .addColumn(newBooleanColumnDefBuilder().setColumnName("with_project_creator").setIsNullable(false).setDefaultValue(false).build()) + .addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build()) + .addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").setIsNullable(false).build()) + .build()); + + context.execute(new CreateIndexBuilder(getDialect()) + .setTable(TABLE_NAME) + .setName("uniq_perm_tpl_charac") + .setUnique(true) + .addColumn(templateIdColumn) + .addColumn(permissionKeyColumn) + .build()); + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/CreateTemporaryIndicesFor1211.java b/sonar-db/src/main/java/org/sonar/db/version/v60/CreateTemporaryIndicesFor1211.java new file mode 100644 index 00000000000..b1e561fee51 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/CreateTemporaryIndicesFor1211.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.CreateIndexBuilder; +import org.sonar.db.version.DdlChange; + +import static org.sonar.db.version.IntegerColumnDef.newIntegerColumnDefBuilder; + +public class CreateTemporaryIndicesFor1211 extends DdlChange { + + public static final String INDEX_ON_CE_ACTIVITY = "ce_activity_snapshot_id"; + public static final String INDEX_ON_DUPLICATIONS_INDEX = "dup_index_psid"; + + public CreateTemporaryIndicesFor1211(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new CreateIndexBuilder(getDialect()) + .setTable("ce_activity") + .setName(INDEX_ON_CE_ACTIVITY) + .addColumn(newIntegerColumnDefBuilder().setColumnName("snapshot_id").build()) + .build()); + context.execute(new CreateIndexBuilder(getDialect()) + .setTable("duplications_index") + .setName(INDEX_ON_DUPLICATIONS_INDEX) + .addColumn(newIntegerColumnDefBuilder().setColumnName("project_snapshot_id").build()) + .build()); + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexDuplicationsIndexSidFromDuplicationsIndex.java b/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexDuplicationsIndexSidFromDuplicationsIndex.java new file mode 100644 index 00000000000..0c1a8a0a285 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexDuplicationsIndexSidFromDuplicationsIndex.java @@ -0,0 +1,39 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropIndexBuilder; + +public class DropIndexDuplicationsIndexSidFromDuplicationsIndex extends DdlChange { + public DropIndexDuplicationsIndexSidFromDuplicationsIndex(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable("duplications_index") + .setName("duplications_index_sid") + .build()); + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexEventsSnapshotIdFromEvents.java b/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexEventsSnapshotIdFromEvents.java new file mode 100644 index 00000000000..f6a6129400e --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexEventsSnapshotIdFromEvents.java @@ -0,0 +1,40 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropIndexBuilder; + +public class DropIndexEventsSnapshotIdFromEvents extends DdlChange { + public DropIndexEventsSnapshotIdFromEvents(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable("events") + .setName("events_snapshot_id") + .build()); + } +} + diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexOnSnapshotIdOfMeasures.java b/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexOnSnapshotIdOfMeasures.java new file mode 100644 index 00000000000..24ba93d32e1 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexOnSnapshotIdOfMeasures.java @@ -0,0 +1,39 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropIndexBuilder; + +public class DropIndexOnSnapshotIdOfMeasures extends DdlChange { + public DropIndexOnSnapshotIdOfMeasures(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable("project_measures") + .setName("measures_sid_metric") + .build()); + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexProjectsRootIdFromProjects.java b/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexProjectsRootIdFromProjects.java new file mode 100644 index 00000000000..c04bdf2d143 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexProjectsRootIdFromProjects.java @@ -0,0 +1,39 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropIndexBuilder; + +public class DropIndexProjectsRootIdFromProjects extends DdlChange { + public DropIndexProjectsRootIdFromProjects(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable("projects") + .setName("projects_root_id") + .build()); + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexProjectsUuidFromProjects.java b/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexProjectsUuidFromProjects.java new file mode 100644 index 00000000000..cf6b154c5a3 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndexProjectsUuidFromProjects.java @@ -0,0 +1,39 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropIndexBuilder; + +public class DropIndexProjectsUuidFromProjects extends DdlChange { + public DropIndexProjectsUuidFromProjects(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable("projects") + .setName("projects_uuid") + .build()); + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndicesOnTreeColumnsOfSnapshots.java b/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndicesOnTreeColumnsOfSnapshots.java new file mode 100644 index 00000000000..266433a4bda --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/DropIndicesOnTreeColumnsOfSnapshots.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropIndexBuilder; + +public class DropIndicesOnTreeColumnsOfSnapshots extends DdlChange { + public DropIndicesOnTreeColumnsOfSnapshots(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + dropIndex(context, "snapshots_qualifier"); + dropIndex(context, "snapshots_root"); + dropIndex(context, "snapshots_parent"); + dropIndex(context, "snapshot_root_component"); + } + + private void dropIndex(Context context, String index) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable("snapshots") + .setName(index) + .build()); + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/DropResourceIndexRidFromResourceIndex.java b/sonar-db/src/main/java/org/sonar/db/version/v60/DropResourceIndexRidFromResourceIndex.java new file mode 100644 index 00000000000..8668ec92c28 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/DropResourceIndexRidFromResourceIndex.java @@ -0,0 +1,41 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropIndexBuilder; + +public class DropResourceIndexRidFromResourceIndex extends DdlChange { + + public DropResourceIndexRidFromResourceIndex(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable("resource_index") + .setName("resource_index_rid") + .build()); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/DropSnapshotProjectIdFromSnapshots.java b/sonar-db/src/main/java/org/sonar/db/version/v60/DropSnapshotProjectIdFromSnapshots.java new file mode 100644 index 00000000000..23d54c073cc --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/DropSnapshotProjectIdFromSnapshots.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropIndexBuilder; + +public class DropSnapshotProjectIdFromSnapshots extends DdlChange { + + private static final String TABLE_SNAPSHOTS = "snapshots"; + + public DropSnapshotProjectIdFromSnapshots(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable(TABLE_SNAPSHOTS) + .setName("snapshot_project_id") + .build()); + context.execute(new DropIndexBuilder(getDialect()) + .setTable(TABLE_SNAPSHOTS) + .setName("snapshots_root_project_id") + .build()); + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/DropTemporaryIndicesOf1210.java b/sonar-db/src/main/java/org/sonar/db/version/v60/DropTemporaryIndicesOf1210.java new file mode 100644 index 00000000000..45043bd7aa1 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/DropTemporaryIndicesOf1210.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropIndexBuilder; + +public class DropTemporaryIndicesOf1210 extends DdlChange { + + public DropTemporaryIndicesOf1210(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable("ce_activity") + .setName(CreateTemporaryIndicesFor1211.INDEX_ON_CE_ACTIVITY) + .build()); + + context.execute(new DropIndexBuilder(getDialect()) + .setTable("duplications_index") + .setName(CreateTemporaryIndicesFor1211.INDEX_ON_DUPLICATIONS_INDEX) + .build()); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeAnalysisUuidNotNullOnEvents.java b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeAnalysisUuidNotNullOnEvents.java index 97f82f3854f..eb299e065fb 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeAnalysisUuidNotNullOnEvents.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeAnalysisUuidNotNullOnEvents.java @@ -22,7 +22,9 @@ package org.sonar.db.version.v60; import java.sql.SQLException; import org.sonar.db.Database; import org.sonar.db.version.AlterColumnsBuilder; +import org.sonar.db.version.CreateIndexBuilder; import org.sonar.db.version.DdlChange; +import org.sonar.db.version.VarcharColumnDef; import static org.sonar.db.version.VarcharColumnDef.UUID_VARCHAR_SIZE; import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; @@ -37,8 +39,15 @@ public class MakeAnalysisUuidNotNullOnEvents extends DdlChange { @Override public void execute(Context context) throws SQLException { + VarcharColumnDef analysisUuidColumn = newVarcharColumnDefBuilder().setColumnName("analysis_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build(); context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE_EVENTS) - .updateColumn(newVarcharColumnDefBuilder().setColumnName("analysis_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) + .updateColumn(analysisUuidColumn) + .build()); + + context.execute(new CreateIndexBuilder(getDialect()) + .setTable(TABLE_EVENTS) + .setName("events_analysis") + .addColumn(analysisUuidColumn) .build()); } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex.java b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex.java index 8d486634406..e9f3a368e06 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex.java @@ -22,7 +22,9 @@ package org.sonar.db.version.v60; import java.sql.SQLException; import org.sonar.db.Database; import org.sonar.db.version.AlterColumnsBuilder; +import org.sonar.db.version.CreateIndexBuilder; import org.sonar.db.version.DdlChange; +import org.sonar.db.version.VarcharColumnDef; import static org.sonar.db.version.VarcharColumnDef.UUID_VARCHAR_SIZE; import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; @@ -37,9 +39,18 @@ public class MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex extends @Override public void execute(Context context) throws SQLException { + VarcharColumnDef analysisUuid = newVarcharColumnDefBuilder().setColumnName("analysis_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build(); + VarcharColumnDef componentUuid = newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build(); context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE_DUPLICATIONS_INDEX) - .updateColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) - .updateColumn(newVarcharColumnDefBuilder().setColumnName("analysis_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) + .updateColumn(componentUuid) + .updateColumn(analysisUuid) + .build()); + + context.execute(new CreateIndexBuilder(getDialect()) + .setTable(TABLE_DUPLICATIONS_INDEX) + .setName("duplication_analysis_component") + .addColumn(analysisUuid) + .addColumn(componentUuid) .build()); } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeComponentUuidColumnsNotNullOnSnapshots.java b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeComponentUuidColumnsNotNullOnSnapshots.java index 40c2c55bf55..cc18a42a61d 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeComponentUuidColumnsNotNullOnSnapshots.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeComponentUuidColumnsNotNullOnSnapshots.java @@ -22,7 +22,9 @@ package org.sonar.db.version.v60; import java.sql.SQLException; import org.sonar.db.Database; import org.sonar.db.version.AlterColumnsBuilder; +import org.sonar.db.version.CreateIndexBuilder; import org.sonar.db.version.DdlChange; +import org.sonar.db.version.VarcharColumnDef; import static org.sonar.db.version.VarcharColumnDef.UUID_VARCHAR_SIZE; import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; @@ -37,9 +39,22 @@ public class MakeComponentUuidColumnsNotNullOnSnapshots extends DdlChange { @Override public void execute(Context context) throws SQLException { + VarcharColumnDef componentUuid = newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build(); + VarcharColumnDef rootComponentUuid = newVarcharColumnDefBuilder().setColumnName("root_component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build(); context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE_SNAPSHOTS) - .updateColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) - .updateColumn(newVarcharColumnDefBuilder().setColumnName("root_component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) + .updateColumn(componentUuid) + .updateColumn(rootComponentUuid) + .build()); + + context.execute(new CreateIndexBuilder(getDialect()) + .setTable(TABLE_SNAPSHOTS) + .setName("snapshot_component") + .addColumn(componentUuid) + .build()); + context.execute(new CreateIndexBuilder(getDialect()) + .setTable(TABLE_SNAPSHOTS) + .setName("snapshot_root_component") + .addColumn(rootComponentUuid) .build()); } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnProjects.java b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnProjects.java index 2a6c87a1e2d..722e9498189 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnProjects.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnProjects.java @@ -22,7 +22,9 @@ package org.sonar.db.version.v60; import java.sql.SQLException; import org.sonar.db.Database; import org.sonar.db.version.AlterColumnsBuilder; +import org.sonar.db.version.CreateIndexBuilder; import org.sonar.db.version.DdlChange; +import org.sonar.db.version.VarcharColumnDef; import static org.sonar.db.version.VarcharColumnDef.UUID_VARCHAR_SIZE; import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; @@ -37,9 +39,16 @@ public class MakeUuidColumnsNotNullOnProjects extends DdlChange { @Override public void execute(Context context) throws SQLException { + VarcharColumnDef rootUuid = newVarcharColumnDefBuilder().setColumnName("root_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build(); context.execute(new AlterColumnsBuilder(getDialect(), TABLE_PROJECTS) .updateColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) - .updateColumn(newVarcharColumnDefBuilder().setColumnName("root_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) + .updateColumn(rootUuid) + .build()); + + context.execute(new CreateIndexBuilder(getDialect()) + .setTable(TABLE_PROJECTS) + .setName("projects_root_uuid") + .addColumn(rootUuid) .build()); } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnResourceIndex.java b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnResourceIndex.java index 0124ff4b135..711a55f6331 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnResourceIndex.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnResourceIndex.java @@ -22,7 +22,9 @@ package org.sonar.db.version.v60; import java.sql.SQLException; import org.sonar.db.Database; import org.sonar.db.version.AlterColumnsBuilder; +import org.sonar.db.version.CreateIndexBuilder; import org.sonar.db.version.DdlChange; +import org.sonar.db.version.VarcharColumnDef; import static org.sonar.db.version.VarcharColumnDef.UUID_VARCHAR_SIZE; import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; @@ -37,10 +39,17 @@ public class MakeUuidColumnsNotNullOnResourceIndex extends DdlChange { @Override public void execute(Context context) throws SQLException { + VarcharColumnDef componentUuid = newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build(); context.execute(new AlterColumnsBuilder(getDialect(), TABLE_RESOURCE_INDEX) - .updateColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) + .updateColumn(componentUuid) .updateColumn(newVarcharColumnDefBuilder().setColumnName("root_component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) .build()); + + context.execute(new CreateIndexBuilder(getDialect()) + .setTable(TABLE_RESOURCE_INDEX) + .setName("resource_index_component") + .addColumn(componentUuid) + .build()); } } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/RecreateIndexProjectsUuidFromProjects.java b/sonar-db/src/main/java/org/sonar/db/version/v60/RecreateIndexProjectsUuidFromProjects.java new file mode 100644 index 00000000000..a617e0589de --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/RecreateIndexProjectsUuidFromProjects.java @@ -0,0 +1,43 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.CreateIndexBuilder; +import org.sonar.db.version.DdlChange; + +import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class RecreateIndexProjectsUuidFromProjects extends DdlChange { + + public RecreateIndexProjectsUuidFromProjects(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new CreateIndexBuilder(getDialect()) + .setTable("projects") + .setName("projects_uuid") + .addColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(50).build()) + .build()); + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/TemporarilyDropIndexOfAnalysisUuidOnMeasures.java b/sonar-db/src/main/java/org/sonar/db/version/v60/TemporarilyDropIndexOfAnalysisUuidOnMeasures.java new file mode 100644 index 00000000000..3e8a614f22f --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/TemporarilyDropIndexOfAnalysisUuidOnMeasures.java @@ -0,0 +1,44 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropIndexBuilder; + +/** + * the index must be dropped for the compatibility of migration 1270 + * with MSSQL + */ +public class TemporarilyDropIndexOfAnalysisUuidOnMeasures extends DdlChange { + + public TemporarilyDropIndexOfAnalysisUuidOnMeasures(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable("project_measures") + .setName("measures_analysis_metric") + .build()); + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v61/CreateTableProperties2.java b/sonar-db/src/main/java/org/sonar/db/version/v61/CreateTableProperties2.java index bd8a690ead1..c9b851e2ec9 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v61/CreateTableProperties2.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v61/CreateTableProperties2.java @@ -22,8 +22,10 @@ package org.sonar.db.version.v61; import java.sql.SQLException; import java.util.List; import org.sonar.db.Database; +import org.sonar.db.version.CreateIndexBuilder; import org.sonar.db.version.CreateTableBuilder; import org.sonar.db.version.DdlChange; +import org.sonar.db.version.VarcharColumnDef; import static org.sonar.db.version.BigIntegerColumnDef.newBigIntegerColumnDefBuilder; import static org.sonar.db.version.BooleanColumnDef.newBooleanColumnDefBuilder; @@ -34,24 +36,34 @@ import static org.sonar.db.version.VarcharColumnDef.MAX_SIZE; import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; public class CreateTableProperties2 extends DdlChange { + + private static final String TABLE_NAME = "properties2"; + public CreateTableProperties2(Database db) { super(db); } @Override public void execute(Context context) throws SQLException { - List stmts = new CreateTableBuilder(getDialect(), "properties2") - .addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT) - .addColumn(newVarcharColumnDefBuilder().setColumnName("prop_key").setLimit(512).setIsNullable(false).build()) - .addColumn(newBigIntegerColumnDefBuilder().setColumnName("resource_id").setIsNullable(true).build()) - .addColumn(newBigIntegerColumnDefBuilder().setColumnName("user_id").setIsNullable(true).build()) - .addColumn(newBooleanColumnDefBuilder().setColumnName("is_empty").setIsNullable(false).build()) - .addColumn(newVarcharColumnDefBuilder().setColumnName("text_value").setLimit(MAX_SIZE).setIsNullable(true).build()) - .addColumn(newClobColumnDefBuilder().setColumnName("clob_value").setIsNullable(true).build()) - .addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build()) - // table with be renamed to properties in following migration, use final constraint name right away - .withPkConstraintName("pk_properties") - .build(); + VarcharColumnDef propKey = newVarcharColumnDefBuilder().setColumnName("prop_key").setLimit(512).setIsNullable(false).build(); + List stmts = new CreateTableBuilder(getDialect(), TABLE_NAME) + .addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT) + .addColumn(propKey) + .addColumn(newBigIntegerColumnDefBuilder().setColumnName("resource_id").setIsNullable(true).build()) + .addColumn(newBigIntegerColumnDefBuilder().setColumnName("user_id").setIsNullable(true).build()) + .addColumn(newBooleanColumnDefBuilder().setColumnName("is_empty").setIsNullable(false).build()) + .addColumn(newVarcharColumnDefBuilder().setColumnName("text_value").setLimit(MAX_SIZE).setIsNullable(true).build()) + .addColumn(newClobColumnDefBuilder().setColumnName("clob_value").setIsNullable(true).build()) + .addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build()) + // table with be renamed to properties in following migration, use final constraint name right away + .withPkConstraintName("pk_properties") + .build(); context.execute(stmts); + + context.execute(new CreateIndexBuilder(getDialect()) + .setTable(TABLE_NAME) + .setName("properties2_key") + .addColumn(propKey) + .build()); } } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v61/DropTableActivities.java b/sonar-db/src/main/java/org/sonar/db/version/v61/DropTableActivities.java new file mode 100644 index 00000000000..8a009770694 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v61/DropTableActivities.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v61; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropIndexBuilder; +import org.sonar.db.version.DropTableBuilder; + +public class DropTableActivities extends DdlChange { + + private static final String TABLE_ACTIVITIES = "activities"; + + public DropTableActivities(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable(TABLE_ACTIVITIES) + .setName("activities_log_key") + .build()); + + context.execute(new DropTableBuilder(getDialect(), TABLE_ACTIVITIES).build()); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v61/DropTableProperties.java b/sonar-db/src/main/java/org/sonar/db/version/v61/DropTableProperties.java new file mode 100644 index 00000000000..32da55dab31 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v61/DropTableProperties.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v61; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropIndexBuilder; +import org.sonar.db.version.DropTableBuilder; + +public class DropTableProperties extends DdlChange { + + private static final String TABLE_PROPERTIES = "properties"; + + public DropTableProperties(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable(TABLE_PROPERTIES) + .setName("properties_key") + .build()); + + context.execute(new DropTableBuilder(getDialect(), TABLE_PROPERTIES).build()); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v62/CreateTableOrganizations.java b/sonar-db/src/main/java/org/sonar/db/version/v62/CreateTableOrganizations.java index 69047e4ab62..d25a0414ab3 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v62/CreateTableOrganizations.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v62/CreateTableOrganizations.java @@ -21,24 +21,30 @@ package org.sonar.db.version.v62; import java.sql.SQLException; import org.sonar.db.Database; +import org.sonar.db.version.CreateIndexBuilder; import org.sonar.db.version.CreateTableBuilder; import org.sonar.db.version.DdlChange; +import org.sonar.db.version.VarcharColumnDef; import static org.sonar.db.version.BigIntegerColumnDef.newBigIntegerColumnDefBuilder; import static org.sonar.db.version.VarcharColumnDef.UUID_SIZE; import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; public class CreateTableOrganizations extends DdlChange { + + private static final String TABLE_NAME = "organizations"; + public CreateTableOrganizations(Database db) { super(db); } @Override public void execute(Context context) throws SQLException { + VarcharColumnDef keeColumn = newVarcharColumnDefBuilder().setColumnName("kee").setLimit(32).setIsNullable(false).build(); context.execute( - new CreateTableBuilder(getDialect(), "organizations") + new CreateTableBuilder(getDialect(), TABLE_NAME) .addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(UUID_SIZE).setIsNullable(false).build()) - .addColumn(newVarcharColumnDefBuilder().setColumnName("kee").setLimit(32).setIsNullable(false).build()) + .addColumn(keeColumn) .addColumn(newVarcharColumnDefBuilder().setColumnName("name").setLimit(64).setIsNullable(false).build()) .addColumn(newVarcharColumnDefBuilder().setColumnName("description").setLimit(256).setIsNullable(true).build()) .addColumn(newVarcharColumnDefBuilder().setColumnName("url").setLimit(256).setIsNullable(true).build()) @@ -46,5 +52,11 @@ public class CreateTableOrganizations extends DdlChange { .addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build()) .addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").setIsNullable(false).build()) .build()); + + context.execute(new CreateIndexBuilder(getDialect()) + .setTable(TABLE_NAME) + .setName("organization_key") + .addColumn(keeColumn) + .build()); } } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v62/IncludeOrganizationUuidInUniqueIndexOfGroupRoles.java b/sonar-db/src/main/java/org/sonar/db/version/v62/IncludeOrganizationUuidInUniqueIndexOfGroupRoles.java new file mode 100644 index 00000000000..d2413ba7a0e --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v62/IncludeOrganizationUuidInUniqueIndexOfGroupRoles.java @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v62; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.CreateIndexBuilder; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropIndexBuilder; + +import static org.sonar.db.version.IntegerColumnDef.newIntegerColumnDefBuilder; +import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class IncludeOrganizationUuidInUniqueIndexOfGroupRoles extends DdlChange { + + private static final String TABLE_GROUP_ROLES = "group_roles"; + + public IncludeOrganizationUuidInUniqueIndexOfGroupRoles(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable(TABLE_GROUP_ROLES) + .setName("uniq_group_roles") + .build()); + + context.execute(new CreateIndexBuilder(getDialect()) + .setTable(TABLE_GROUP_ROLES) + .setName("uniq_group_roles") + .setUnique(true) + .addColumn(newVarcharColumnDefBuilder().setColumnName("organization_uuid").setLimit(40).build()) + .addColumn(newIntegerColumnDefBuilder().setColumnName("group_id").build()) + .addColumn(newIntegerColumnDefBuilder().setColumnName("resource_id").build()) + .addColumn(newVarcharColumnDefBuilder().setColumnName("role").setLimit(64).build()) + .build()); + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v63/MakeUuidNotNullOnEvents.java b/sonar-db/src/main/java/org/sonar/db/version/v63/MakeUuidNotNullOnEvents.java index 43b89391ec6..e8e3bc2db47 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v63/MakeUuidNotNullOnEvents.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v63/MakeUuidNotNullOnEvents.java @@ -17,13 +17,14 @@ * 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.db.version.v63; import java.sql.SQLException; import org.sonar.db.Database; import org.sonar.db.version.AlterColumnsBuilder; +import org.sonar.db.version.CreateIndexBuilder; import org.sonar.db.version.DdlChange; +import org.sonar.db.version.VarcharColumnDef; import static org.sonar.db.version.VarcharColumnDef.UUID_SIZE; import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; @@ -38,8 +39,16 @@ public class MakeUuidNotNullOnEvents extends DdlChange { @Override public void execute(Context context) throws SQLException { + VarcharColumnDef uuidColumn = newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(UUID_SIZE).setIsNullable(false).build(); context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE) - .updateColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(UUID_SIZE).setIsNullable(false).build()) + .updateColumn(uuidColumn) + .build()); + + context.execute(new CreateIndexBuilder(getDialect()) + .setTable(TABLE) + .setName("events_uuid") + .setUnique(true) + .addColumn(uuidColumn) .build()); } } diff --git a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java index 02056648d4b..615bade9e16 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java @@ -29,6 +29,6 @@ public class MigrationStepModuleTest { public void verify_count_of_added_MigrationStep_types() { ComponentContainer container = new ComponentContainer(); new MigrationStepModule().configure(container); - assertThat(container.size()).isEqualTo(167); + assertThat(container.size()).isEqualTo(187); } } -- 2.39.5