diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-02-18 13:12:16 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-02-18 13:14:14 +0100 |
commit | d5c2f872387c6a2a01d83edf8f259c1a73b4f80e (patch) | |
tree | 01faf058c8e771a1c947f98ee3a86ccbf373dae4 | |
parent | 7e5de20ded83bfba8598749f23703a9aaf074059 (diff) | |
download | sonarqube-d5c2f872387c6a2a01d83edf8f259c1a73b4f80e.tar.gz sonarqube-d5c2f872387c6a2a01d83edf8f259c1a73b4f80e.zip |
SONAR-4137 fix varchar indices on mysql 5.6
7 files changed, 81 insertions, 30 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/config/environment.rb b/sonar-server/src/main/webapp/WEB-INF/config/environment.rb index 310506ac2bc..7e146218751 100644 --- a/sonar-server/src/main/webapp/WEB-INF/config/environment.rb +++ b/sonar-server/src/main/webapp/WEB-INF/config/environment.rb @@ -96,12 +96,11 @@ 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 + super(table_name, column_name, options) end def self.alter_to_big_primary_key(tablename) - dialect = ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getDatabase().getDialect().getActiveRecordDialectCode() - case dialect + case dialect() when "postgre" execute "ALTER TABLE #{tablename} ALTER COLUMN id TYPE bigint" when "mysql" @@ -119,8 +118,7 @@ class ActiveRecord::Migration end def self.alter_to_big_integer(tablename, columnname, indexname=nil) - dialect = ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getDatabase().getDialect().getActiveRecordDialectCode() - case dialect + case dialect() when "sqlserver" execute "DROP INDEX #{indexname} on #{tablename}" if indexname change_column(tablename, columnname, :big_integer, :null => true) diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/062_add_project_kee_index.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/062_add_project_kee_index.rb index 56de55a1623..09c8c2cb881 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/062_add_project_kee_index.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/062_add_project_kee_index.rb @@ -1,26 +1,33 @@ - # - # Sonar, entreprise quality control tool. - # Copyright (C) 2008-2012 SonarSource - # mailto:contact AT sonarsource DOT com - # - # Sonar 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. - # - # Sonar 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 Sonar; if not, write to the Free Software - # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - # +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2012 SonarSource +# mailto:contact AT sonarsource DOT com +# +# Sonar 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. +# +# Sonar 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 Sonar; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 +# class AddProjectKeeIndex < ActiveRecord::Migration - + def self.up - add_index :projects, :kee, :name => 'projects_kee' + 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 end end
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/151_create_dashboards.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/151_create_dashboards.rb index 2cdd382a9dc..368a14c3c74 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/151_create_dashboards.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/151_create_dashboards.rb @@ -52,7 +52,14 @@ class CreateDashboards < ActiveRecord::Migration t.timestamps end add_index :widgets, [:dashboard_id], :name => 'widgets_dashboards' - add_index :widgets, [:widget_key], :name => 'widgets_widgetkey' + 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 create_table :widget_properties do |t| t.column :widget_id, :integer, :null => false diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/237_create_table_resource_index.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/237_create_table_resource_index.rb index e2219fec579..830637e45a7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/237_create_table_resource_index.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/237_create_table_resource_index.rb @@ -32,7 +32,15 @@ class CreateTableResourceIndex < ActiveRecord::Migration t.column 'root_project_id', :integer, :null => false t.column 'qualifier', :string, :limit => 10, :null => false end - add_index 'resource_index', 'kee', :name => 'resource_index_key' + + 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_index 'resource_index', 'resource_id', :name => 'resource_index_rid' end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/286_add_indices_to_resource_index.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/286_add_indices_to_resource_index.rb index e6c604f9852..80157f3e2eb 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/286_add_indices_to_resource_index.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/286_add_indices_to_resource_index.rb @@ -31,7 +31,14 @@ class AddIndicesToResourceIndex < ActiveRecord::Migration ResourceIndex.reset_column_information begin - add_index 'resource_index', 'kee', :name => 'resource_index_key' + 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 rescue #ignore, already exists end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/350_create_semaphores.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/350_create_semaphores.rb index ce710ccc8d9..fff0ef7d052 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/350_create_semaphores.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/350_create_semaphores.rb @@ -37,7 +37,15 @@ class CreateSemaphores < ActiveRecord::Migration t.timestamps end add_index :semaphores, :checksum, :unique => true, :name => 'uniq_semaphore_checksums' - add_index :semaphores, :name, :name => 'semaphore_names' + 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 + end end diff --git a/sonar-server/src/main/webapp/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/mysql/adapter.rb b/sonar-server/src/main/webapp/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/mysql/adapter.rb index 891d59ae89d..27d06ee7f54 100644 --- a/sonar-server/src/main/webapp/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/mysql/adapter.rb +++ b/sonar-server/src/main/webapp/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/mysql/adapter.rb @@ -366,6 +366,22 @@ module ::ArJdbc end end + # SONAR - support the length parameter when creating indices + # See http://jira.codehaus.org/browse/SONAR-4137 + def quoted_columns_for_index(column_names, options = {}) + length = options[:length] if options.is_a?(Hash) + + quoted_column_names = case length + when Hash + column_names.map {|name| length[name] ? "#{quote_column_name(name)}(#{length[name]})" : quote_column_name(name) } + when Fixnum + column_names.map {|name| "#{quote_column_name(name)}(#{length})"} + else + column_names.map {|name| quote_column_name(name) } + end + end + #/SONAR + private def column_for(table_name, column_name) unless column = columns(table_name).find { |c| c.name == column_name.to_s } |