rails/rails — Issue #5099: generated db/schema.rb can't be loaded using rake db:schema:load (Rails 3.2.1)
Author: jana4u
Created: 2012-02-20 15:19:30+00:00
State: open

Everything worked fine in Rails 3.1.3, but after upgrading to 3.2.1, it is not possible to load DB schema anymore.

Problem is caused by index created using execute in migration:

```ruby
execute "CREATE UNIQUE INDEX index_slugs_on_name_and_sluggable_type_and_scope_and_sequence ON slugs (name(250), sluggable_type, scope, sequence)"
```

This line is added to db/schema.rb (both Rails 3.1.3 and 3.2.1 generate the same):

```ruby
add_index "slugs", ["name", "sluggable_type", "scope", "sequence"], :name => "index_slugs_on_name_and_sluggable_type_and_scope_and_sequence", :unique => true, :length => {"name"=>250, "sluggable_type"=>nil, "scope"=>nil, "sequence"=>nil}
```

But when you run rake db:schema:load, invalid SQL is generated in Rails 3.2.1 and exception raised:

```
-- create_table("slugs", {:force=>true})
-> 0.4759s
-- add_index("slugs", ["name", "sluggable_type", "scope", "sequence"], {:name=>"index_slugs_on_name_and_sluggable_type_and_scope_and_sequence", :unique=>true, :length=>{"name"=>250, "sluggable_type"=>nil, "scope"=>nil, "sequence"=>nil}})
rake aborted!
Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '), `scope`(), `sequence`())' at line 1: CREATE UNIQUE INDEX `index_slugs_on_name_and_sluggable_type_and_scope_and_sequence` ON `slugs` (`name`(250), `sluggable_type`(), `scope`(), `sequence`())
```

I made new Rails 3.2.1 app, added migration and generated db/schema.rb - see https://github.com/jana4u/test_add_index

I am running it on ruby 1.9.3p0.