From 582c3f65221093d7bfbd1972da17fc2f0ee3b7b1 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 24 Sep 2014 21:15:56 +0200 Subject: [PATCH] SONAR-5623 fix index on mysql --- .../src/main/webapp/WEB-INF/config/environment.rb | 11 +++++++++++ .../WEB-INF/db/migrate/059_create_properties.rb | 9 +-------- .../WEB-INF/db/migrate/062_add_project_kee_index.rb | 9 +-------- .../WEB-INF/db/migrate/151_create_dashboards.rb | 9 +-------- .../db/migrate/237_create_table_resource_index.rb | 9 +-------- .../db/migrate/286_add_indices_to_resource_index.rb | 9 +-------- .../WEB-INF/db/migrate/350_create_semaphores.rb | 9 +-------- .../WEB-INF/db/migrate/702_create_analysis_reports.rb | 2 +- 8 files changed, 18 insertions(+), 49 deletions(-) diff --git a/server/sonar-web/src/main/webapp/WEB-INF/config/environment.rb b/server/sonar-web/src/main/webapp/WEB-INF/config/environment.rb index 12ea9ebd64a..986137d1976 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/config/environment.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/config/environment.rb @@ -121,9 +121,20 @@ class ActiveRecord::Migration # not supported by Oracle, the "Enterprise" database. # For this reason we force to set name of indexes. raise ArgumentError, 'Missing index name' unless options[:name] + super(table_name, column_name, options) end + def self.add_varchar_index(table_name, column_name, options = {}) + if dialect()=='mysql' && !options[:length] + # Index of varchar column is limited to 767 bytes on mysql (<= 255 UTF-8 characters) + # See http://jira.codehaus.org/browse/SONAR-4137 and + # http://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html + options[:length]=255 + end + add_index table_name, column_name, options + end + def self.execute_java_migration(classname) Java::OrgSonarServerUi::JRubyFacade.getInstance().databaseMigrator().executeMigration(classname) end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/059_create_properties.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/059_create_properties.rb index 40c0ec4d3e3..9b6b62f8073 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/059_create_properties.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/059_create_properties.rb @@ -27,14 +27,7 @@ class CreateProperties < ActiveRecord::Migration t.column :user_id, :integer, :null => true end - if dialect()=='mysql' - # Index of varchar column is limited to 767 bytes on mysql (<= 255 UTF-8 characters) - # See http://jira.codehaus.org/browse/SONAR-4137 and - # http://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html - add_index :properties, :prop_key, :name => 'properties_key', :length => 255 - else - add_index :properties, :prop_key, :name => 'properties_key' - end + add_varchar_index :properties, :prop_key, :name => 'properties_key' end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/062_add_project_kee_index.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/062_add_project_kee_index.rb index fc0db1619bf..95a8088bbb8 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/062_add_project_kee_index.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/062_add_project_kee_index.rb @@ -20,14 +20,7 @@ class AddProjectKeeIndex < ActiveRecord::Migration def self.up - if dialect=='mysql' - # Index of varchar column is limited to 767 bytes on mysql (<= 255 UTF-8 characters) - # See http://jira.codehaus.org/browse/SONAR-4137 and - # http://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html - add_index :projects, :kee, :name => 'projects_kee', :length => 255 - else - add_index :projects, :kee, :name => 'projects_kee' - end + add_varchar_index :projects, :kee, :name => 'projects_kee' end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/151_create_dashboards.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/151_create_dashboards.rb index b5e99db1685..ac3d842ed42 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/151_create_dashboards.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/151_create_dashboards.rb @@ -52,14 +52,7 @@ class CreateDashboards < ActiveRecord::Migration t.timestamps end add_index :widgets, [:dashboard_id], :name => 'widgets_dashboards' - if dialect=='mysql' - # Index of varchar column is limited to 767 bytes on mysql (<= 255 UTF-8 characters) - # See http://jira.codehaus.org/browse/SONAR-4137 and - # http://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html - add_index :widgets, [:widget_key], :name => 'widgets_widgetkey', :length => 255 - else - add_index :widgets, [:widget_key], :name => 'widgets_widgetkey' - end + add_varchar_index :widgets, [:widget_key], :name => 'widgets_widgetkey' create_table :widget_properties do |t| t.column :widget_id, :integer, :null => false diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/237_create_table_resource_index.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/237_create_table_resource_index.rb index 1b25c7df4b0..7be8227f485 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/237_create_table_resource_index.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/237_create_table_resource_index.rb @@ -33,14 +33,7 @@ class CreateTableResourceIndex < ActiveRecord::Migration t.column 'qualifier', :string, :limit => 10, :null => false end - if dialect=='mysql' - # Index of varchar column is limited to 767 bytes on mysql (<= 255 UTF-8 characters) - # See http://jira.codehaus.org/browse/SONAR-4137 and - # http://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html - add_index 'resource_index', 'kee', :name => 'resource_index_key', :length => 255 - else - add_index 'resource_index', 'kee', :name => 'resource_index_key' - end + add_varchar_index 'resource_index', 'kee', :name => 'resource_index_key' add_index 'resource_index', 'resource_id', :name => 'resource_index_rid' end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/286_add_indices_to_resource_index.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/286_add_indices_to_resource_index.rb index 64200bae9be..ad76facabb9 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/286_add_indices_to_resource_index.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/286_add_indices_to_resource_index.rb @@ -31,14 +31,7 @@ class AddIndicesToResourceIndex < ActiveRecord::Migration ResourceIndex.reset_column_information begin - if dialect=='mysql' - # Index of varchar column is limited to 767 bytes on mysql (<= 255 UTF-8 characters) - # See http://jira.codehaus.org/browse/SONAR-4137 and - # http://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html - add_index 'resource_index', 'kee', :name => 'resource_index_key', :length => 255 - else - add_index 'resource_index', 'kee', :name => 'resource_index_key' - end + add_varchar_index 'resource_index', 'kee', :name => 'resource_index_key' rescue #ignore, already exists end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/350_create_semaphores.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/350_create_semaphores.rb index a2271e91394..657955b35fe 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/350_create_semaphores.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/350_create_semaphores.rb @@ -37,14 +37,7 @@ class CreateSemaphores < ActiveRecord::Migration t.timestamps end add_index :semaphores, :checksum, :unique => true, :name => 'uniq_semaphore_checksums' - if dialect=='mysql' - # Index of varchar column is limited to 767 bytes on mysql (<= 255 UTF-8 characters) - # See http://jira.codehaus.org/browse/SONAR-4137 and - # http://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html - add_index :semaphores, :name, :name => 'semaphore_names', :length => 255 - else - add_index :semaphores, :name, :name => 'semaphore_names' - end + add_varchar_index :semaphores, :name, :name => 'semaphore_names' end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb index 424095738a5..dfc20677620 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb @@ -31,7 +31,7 @@ class CreateAnalysisReports < ActiveRecord::Migration t.column :created_at, :datetime, :null => false t.column :updated_at, :datetime, :null => false end - add_index :analysis_reports, ['project_key'], :name => 'analysis_reports_project_key', :unique => true + add_varchar_index :analysis_reports, 'project_key', :name => 'analysis_reports_project_key', :unique => true end end -- 2.39.5