oauth-plugin
oauth-plugin copied to clipboard
Index key length in migration
There is a problem running the migration, due to key length which is too long if the table use utf-8:
== CreateOauthConsumerTokens: migrating ======================================
-- create_table(:consumer_tokens)
-> 0.0780s
-- add_index(:consumer_tokens, :token, {:unique=>true})
rake aborted!
Mysql::Error: Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX index_consumer_tokens_on_token
ON consumer_tokens
(token
)
I don't know how to fix this in a ruby-way, but this sql does the trick:
execute("CREATE UNIQUE INDEX index_consumer_tokens_on_token
ON consumer_tokens
(token
(100))")
It uses only the 100 first chacracters instead of the whole field.
This is the way to do it in ruby (It maintains the token length as 1024 but restricts the index to 767.
create_table "consumer_tokens", :force => true do |t| t.integer "person_id" t.string "type", :limit => 30 t.string "token", :limit => 1024 t.string "secret" t.datetime "created_at" t.datetime "updated_at" t.string "account" end
add_index "consumer_tokens", ["token"], :name => "index_consumer_tokens_on_token", :length => {"token"=>"767"}
I know this is very old, but I came across issue while searching for the solution to the same problem.
I see this problem when I develop using SQLite and use MySQL in production. A schema dumped via the sqlite gem doesn't include the :length option but a schema dumped with the mysql gem does, so moving between the two shows this issue up.