From eababa35cf5917c4ebd3f48cb29b9a2f6d1db404 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Sat, 8 May 2010 23:56:06 +0300 Subject: [PATCH] Revert "Add index length support for MySQL [#1852 state:resolved]" (breaks the build) This reverts commit 3616141fa2d2f35675d5962a1b329c8c51a5e9a3. --- activerecord/CHANGELOG | 10 -------- .../abstract/schema_definitions.rb | 2 +- .../abstract/schema_statements.rb | 23 +------------------ .../connection_adapters/mysql_adapter.rb | 17 +------------- .../lib/active_record/schema_dumper.rb | 1 - .../test/cases/active_schema_test_mysql.rb | 17 -------------- activerecord/test/cases/migration_test.rb | 8 ------- 7 files changed, 3 insertions(+), 75 deletions(-) diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 8726874face90..e9a19849d17df 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,15 +1,5 @@ *2.3.6 (pending)* -* Add index length support for MySQL. #1852 [Emili Parreno, Pratik Naik] - - Example: - - add_index(:accounts, :name, :name => 'by_name', :length => 10) - => CREATE INDEX by_name ON accounts(name(10)) - - add_index(:accounts, [:name, :surname], :name => 'by_name_surname', :length => {:name => 10, :surname => 15}) - => CREATE INDEX by_name_surname ON accounts(name(10), surname(15)) - * find_or_create_by_attr(value, ...) works when attr is protected. #4457 [Santiago Pastorino, Marc-André Lafortune] * JSON supports a custom root option: to_json(:root => 'custom') #4515 [Jatinder Singh] diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index 399a272117fd0..520f3c8c0c01b 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -256,7 +256,7 @@ def simplified_type(field_type) end end - class IndexDefinition < Struct.new(:table, :name, :unique, :columns, :lengths) #:nodoc: + class IndexDefinition < Struct.new(:table, :name, :unique, :columns) #:nodoc: end # Abstract representation of a column definition. Instances of this type diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 211cd7e6d12e9..d93cbc1a0560a 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -246,32 +246,18 @@ def rename_column(table_name, column_name, new_column_name) # name. # # ===== Examples - # # ====== Creating a simple index # add_index(:suppliers, :name) # generates # CREATE INDEX suppliers_name_index ON suppliers(name) - # # ====== Creating a unique index # add_index(:accounts, [:branch_id, :party_id], :unique => true) # generates # CREATE UNIQUE INDEX accounts_branch_id_party_id_index ON accounts(branch_id, party_id) - # # ====== Creating a named index # add_index(:accounts, [:branch_id, :party_id], :unique => true, :name => 'by_branch_party') # generates # CREATE UNIQUE INDEX by_branch_party ON accounts(branch_id, party_id) - # - # ====== Creating an index with specific key length - # add_index(:accounts, :name, :name => 'by_name', :length => 10) - # generates - # CREATE INDEX by_name ON accounts(name(10)) - # - # add_index(:accounts, [:name, :surname], :name => 'by_name_surname', :length => {:name => 10, :surname => 15}) - # generates - # CREATE INDEX by_name_surname ON accounts(name(10), surname(15)) - # - # Note: SQLite doesn't support index length def add_index(table_name, column_name, options = {}) column_names = Array(column_name) index_name = index_name(table_name, :column => column_names) @@ -282,9 +268,7 @@ def add_index(table_name, column_name, options = {}) else index_type = options end - - quoted_column_names = quoted_columns_for_index(column_names, options).join(", ") - + quoted_column_names = column_names.map { |e| quote_column_name(e) }.join(", ") execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} (#{quoted_column_names})" end @@ -442,11 +426,6 @@ def remove_timestamps(table_name) end protected - # Overridden by the mysql adapter for supporting index lengths - def quoted_columns_for_index(column_names, options = {}) - column_names.map {|name| quote_column_name(name) } - end - def options_include_default?(options) options.include?(:default) && !(options[:null] == false && options[:default].nil?) end diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 69e97b98175bc..a8aa16e4fa5a9 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -454,11 +454,10 @@ def indexes(table_name, name = nil)#:nodoc: if current_index != row[2] next if row[2] == "PRIMARY" # skip the primary key current_index = row[2] - indexes << IndexDefinition.new(row[0], row[2], row[1] == "0", [], []) + indexes << IndexDefinition.new(row[0], row[2], row[1] == "0", []) end indexes.last.columns << row[4] - indexes.last.lengths << row[7] end result.free indexes @@ -587,20 +586,6 @@ def limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key) where_sql end - protected - 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 - private def connect encoding = @config[:encoding] diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index 5f1207f9160d4..68a45a01bb3f6 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -170,7 +170,6 @@ def indexes(table, stream) statment_parts << index.columns.inspect statment_parts << (':name => ' + index.name.inspect) statment_parts << ':unique => true' if index.unique - statment_parts << (':length => ' + Hash[*index.columns.zip(index.lengths).flatten].inspect) if index.lengths.compact.present? ' ' + statment_parts.join(', ') end diff --git a/activerecord/test/cases/active_schema_test_mysql.rb b/activerecord/test/cases/active_schema_test_mysql.rb index f4d123be150c3..9aff538ce9026 100644 --- a/activerecord/test/cases/active_schema_test_mysql.rb +++ b/activerecord/test/cases/active_schema_test_mysql.rb @@ -15,23 +15,6 @@ def teardown end end - def test_add_index - expected = "CREATE INDEX `index_people_on_last_name` ON `people` (`last_name`)" - assert_equal expected, add_index(:people, :last_name, :length => nil) - - expected = "CREATE INDEX `index_people_on_last_name` ON `people` (`last_name`(10))" - assert_equal expected, add_index(:people, :last_name, :length => 10) - - expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`(15))" - assert_equal expected, add_index(:people, [:last_name, :first_name], :length => 15) - - expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`)" - assert_equal expected, add_index(:people, [:last_name, :first_name], :length => {:last_name => 15}) - - expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`(10))" - assert_equal expected, add_index(:people, [:last_name, :first_name], :length => {:last_name => 15, :first_name => 10}) - end - def test_drop_table assert_equal "DROP TABLE `people`", drop_table(:people) end diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index ea939ae95df3d..355279359af41 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -92,14 +92,6 @@ def test_add_index assert_nothing_raised { Person.connection.remove_index("people", "last_name_and_first_name") } assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) } assert_nothing_raised { Person.connection.remove_index("people", ["last_name", "first_name"]) } - assert_nothing_raised { Person.connection.add_index("people", ["last_name"], :length => 10) } - assert_nothing_raised { Person.connection.remove_index("people", "last_name") } - assert_nothing_raised { Person.connection.add_index("people", ["last_name"], :length => {:last_name => 10}) } - assert_nothing_raised { Person.connection.remove_index("people", ["last_name"]) } - assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"], :length => 10) } - assert_nothing_raised { Person.connection.remove_index("people", ["last_name", "first_name"]) } - assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"], :length => {:last_name => 10, :first_name => 20}) } - assert_nothing_raised { Person.connection.remove_index("people", ["last_name", "first_name"]) } end # quoting