This project is archived and is in readonly mode.
Patch to add index length support
-
Carlos Júnior (xjunior)
Fine! but I would replace this:
add_index(:accounts, [:name, :surname], :name => 'by_name_surname', :limit => {:name => 10, :surname => 20})by:
add_index(:accounts, {:name => 10, :surname => 20}, :name => 'by_name_surname')which also cover the first situation (with a simple index):
add_index(:accounts, :name => 10, :name => 'by_name')With this, I don't think that the :limit option is really needed.
-
Emili Parreño
Hash doesn't preserve order, which is critical when declaring indices. Using limit parameter, I wanted to keep the syntax of the migrations when you specify a limit for a field.
-
Deleted User
Very good idea!
query_reviewer is always complaining about long indices in my apps, I guess this way I could solve this by defining shorter indices
-
Amos King
This is a great idea. Anything that can help speed things up a little is wonderful.
+1
-
José Valim
I'm posting +2 since it solve two problems, but you should also check #734. :)
Support to index length is really necessary. For example, let's suppose I want to slug a title. Since I don't want to index the whole title, I set it to 10 characters.
Nowadays, I have to execute SQL inside migrations. This would fix it, so +1.
But even if I say to myself "just add the index, forget the length", it wouldn't be possible because the title is probably bigger than the max index length in MySQL. This takes us to the second problem is solves:
If I insert an index with length inside my migrations using execute, when dumping the schema it dumps the index but not the length. So when I'm applying db:test:clone it will raise an SQL error, saying that the column can not be indexed because it's bigger than the max index length.
So +1 again.
I'm just doing this "essay", because Pratik refused the other ticket, which I hope not to happen again. :)
-
Emili Parreño
I updated the patch with schema dumper support, more tests and sqlite tests fixed.
Thanks for your comments.
-
Raul Murciano
+1, really nice patch
-
Deleted User
+1, very useful
-
Aitor García Rey
+1, needed improvement.
-
Luismi Cavallé
+1 tests passing
-
YoNoSoyTu
+1, works as described and test pass.
-
porras
+1, tests pass and create the indices as described
-
Fernando Guillen
Good implementation, very userfull. Althought too much mysql dependent.
Please review the schema_statements.rb documentation between lines 262 and 278.
I see things like:
# add_index(:accounts, [:name, :surname], :name => 'by_name_surname', :limit => {:name => 10, :surname => 15}) # generates # CREATE INDEX by_name_surname ON accounts(name(10), surname(20)) # CREATE INDEX by_name_surname ON accounts(name(10), surname(15))Regards
-
Deleted User
+1 this will be most welcome
-
Pratik
- Assigned user set to Pratik
-
Jonathan del Strother
Looks promising. However - am I right in thinking that mysql is the only database that handles index lengths?
Correct me if I'm wrong, but pretty much everything else in schema_statements is database-agnostic, right? Would it be feasible to push any of this patch into the mysql adapter? Failing that, we probably ought to at least note that :limit will only be supported on mysql.
-
José Valim
Any chance this making into core now? :)
-
Emili Parreño
@jonathan this patch is only for mysql adapter, and only modifies the schema if you works with this adapter
-
Michael Koziarski
- Milestone changed from 2.x to 2.3.4
-
Emili Parreño
I published a plugin with this feature for use while we wait the inclusion in the core.
http://github.com/eparreno/mysql_index_length/
I have to revise the patch to add more tests. In a few days I'll send a new patch.
-
Jeremy Kemper
- State changed from new to open
- Assigned user changed from Pratik to Jeremy Kemper
Emili, could you update a patch against latest master? I'd like to get this in, as well as a backport to 2-3-stable.
-
Emili Parreño
OK, I'll take a look this week.
-
Repository
- State changed from open to resolved
(from [3616141fa2d2f35675d5962a1b329c8c51a5e9a3]) Add index length support for MySQL [#1852 state:resolved]
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))
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/3616141fa2d2f35675d5962a1b329c... -
Repository
(from [5b95730edc33ee97f53da26a3868eb983305a771]) Add index length support for MySQL [#1852 state:resolved]
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))
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/5b95730edc33ee97f53da26a3868eb... -
Repository
- State changed from resolved to open
(from [6626833db13a69786f9f6cd56b9f53c4017c3e39]) Revert "Add index length support for MySQL [#1852 state:open]"
This commit breaks dumping a few tables, as the sessions table.
To reproduce, just create a new application and:rake db:sessions:create rake db:migrate rake db:test:prepare
And then look at the db/schema.rb file (ht: Sam Ruby).
This reverts commit 5b95730edc33ee97f53da26a3868eb983305a771.
http://github.com/rails/rails/commit/6626833db13a69786f9f6cd56b9f53... -
Repository
- State changed from open to resolved
(from [eababa35cf5917c4ebd3f48cb29b9a2f6d1db404]) Revert "Add index length support for MySQL [#1852 state:resolved]" (breaks the build)
This reverts commit 3616141fa2d2f35675d5962a1b329c8c51a5e9a3.
http://github.com/rails/rails/commit/eababa35cf5917c4ebd3f48cb29b9a... -
José Valim
- State changed from resolved to open
-
Repository
- State changed from open to resolved
(from [77adb4bc2019e3a5b64ae8678310d176e30834d0]) Revert "Revert "Add index length support for MySQL [#1852 state:resolved]" (breaks the build)"
This reverts commit eababa35cf5917c4ebd3f48cb29b9a2f6d1db404.
http://github.com/rails/rails/commit/77adb4bc2019e3a5b64ae8678310d1... -
Repository
- State changed from resolved to open
(from [8d2f6c16e381f5fff6d3f24f5c73a443577a1488]) Revert "Revert "Add index length support for MySQL [#1852 state:open]""
This reverts commit 6626833db13a69786f9f6cd56b9f53c4017c3e39.
http://github.com/rails/rails/commit/8d2f6c16e381f5fff6d3f24f5c73a4... -
Emili Parreño
wooooow! so , now what's exactly the situation? I tried length indexes in 2-3-stable vanilla app and seems to work properly (I see you've changed :limit for :length)
-
Rizwan Reza
- Tag changed from activerecord, migrations, patch, schema to activerecord, bugmash, migrations, patch, schema
-
rails
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails
- State changed from open to stale
