Changeset 4239
- Timestamp:
- 04/20/06 02:41:05 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb (modified) (5 diffs)
- trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb (modified) (1 diff)
- trunk/activerecord/test/migration_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r4238 r4239 1 1 *SVN* 2 3 * Properly quote index names in migrations (closes #4764) [John Long] 2 4 3 5 * Fix the HasManyAssociation#count method so it uses the new ActiveRecord::Base#count syntax, while maintaining backwards compatibility. [Rick] trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
r4039 r4239 120 120 # See TableDefinition#column for details of the options you can use. 121 121 def add_column(table_name, column_name, type, options = {}) 122 add_column_sql = "ALTER TABLE #{table_name} ADD #{ column_name} #{type_to_sql(type, options[:limit])}"122 add_column_sql = "ALTER TABLE #{table_name} ADD #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit])}" 123 123 add_column_options!(add_column_sql, options) 124 124 execute(add_column_sql) … … 129 129 # remove_column(:suppliers, :qualification) 130 130 def remove_column(table_name, column_name) 131 execute "ALTER TABLE #{table_name} DROP #{ column_name}"131 execute "ALTER TABLE #{table_name} DROP #{quote_column_name(column_name)}" 132 132 end 133 133 … … 185 185 # CREATE UNIQUE INDEX by_branch_party ON accounts(branch_id, party_id) 186 186 def add_index(table_name, column_name, options = {}) 187 index_name = "#{table_name}_#{Array(column_name).first}_index" 187 column_names = Array(column_name) 188 index_name = index_name(table_name, :column => column_names.first) 188 189 189 190 if Hash === options # legacy support, since this param was a string … … 193 194 index_type = options 194 195 end 195 196 execute "CREATE #{index_type} INDEX #{ index_name} ON #{table_name} (#{Array(column_name).join(", ")})"196 quoted_column_names = column_names.map { |e| quote_column_name(e) }.join(", ") 197 execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{table_name} (#{quoted_column_names})" 197 198 end 198 199 … … 210 211 # remove_index :accounts, :username 211 212 def remove_index(table_name, options = {}) 212 execute "DROP INDEX #{ index_name(table_name, options)} ON #{table_name}"213 execute "DROP INDEX #{quote_column_name(index_name(table_name, options))} ON #{table_name}" 213 214 end 214 215 trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
r4040 r4239 18 18 end 19 19 end 20 21 20 22 21 config = config.symbolize_keys trunk/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
r4156 r4239 338 338 def remove_index(table_name, options) #:nodoc: 339 339 execute "DROP INDEX #{index_name(table_name, options)}" 340 end 341 340 end 342 341 343 342 private trunk/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
r4032 r4239 214 214 215 215 def remove_index(table_name, options={}) #:nodoc: 216 if Hash === options 217 index_name = options[:name] 218 else 219 index_name = "#{table_name}_#{options}_index" 220 end 221 222 execute "DROP INDEX #{index_name}" 216 execute "DROP INDEX #{quote_column_name(index_name(table_name, options))}" 223 217 end 224 218 trunk/activerecord/test/migration_test.rb
r4152 r4239 35 35 36 36 Person.connection.remove_column("people", "last_name") rescue nil 37 Person.connection.remove_column("people", "key") rescue nil 37 38 Person.connection.remove_column("people", "bio") rescue nil 38 39 Person.connection.remove_column("people", "age") rescue nil … … 48 49 Person.connection.add_column "people", "last_name", :string 49 50 Person.connection.add_column "people", "administrator", :boolean 51 Person.connection.add_column "people", "key", :string 50 52 51 53 assert_nothing_raised { Person.connection.add_index("people", "last_name") } … … 54 56 assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) } 55 57 assert_nothing_raised { Person.connection.remove_index("people", "last_name") } 58 59 # quoting 60 assert_nothing_raised { Person.connection.add_index("people", ["key"], :name => "key", :unique => true) } 61 assert_nothing_raised { Person.connection.remove_index("people", :name => "key") } 56 62 57 63 # Sybase adapter does not support indexes on :boolean columns