Skip to content

Commit

Permalink
added migration and rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
rikettsie committed Feb 26, 2015
1 parent 21a22e0 commit 65f0425
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ Review the generated migrations then migrate :
rake db:migrate
```

MySql users should also apply a column change to get special characters
work correctly for tag names, see [issue #623](https://github.com/mbleigh/acts-as-taggable-on/issues/623).
Execute the following command in the MySql console:
MySql users should also run the following rake task to get special characters
work correctly for tag names, see [issue #623](https://github.com/mbleigh/acts-as-taggable-on/issues/623):

```shell
rake acts_as_taggable_on_engine:tag_names:collate
```

or, alternatively, execute the following command in the MySql console:

```shell
USE my_wonderful_app_db;
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'rubygems'
require 'bundler/setup'

import "./lib/tasks/tags_collate_utf8.rake"

desc 'Default: run specs'
task default: :spec

Expand Down
15 changes: 15 additions & 0 deletions db/migrate/5_change_collation_for_tag_names.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This migration is added to circumvent issue #623 and have special characters
# work properly
class ChangeCollationForTagNames << ActiveRecord::Migration

def up
if ActsAsTaggableOn::Utils.using_mysql?
execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
end
end

def down

end

end
17 changes: 17 additions & 0 deletions lib/tasks/tags_collate_utf8.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This rake task is to be run by MySql users only, and fixes the management of
# binary-encoded strings for tag 'names'. Issues:
# https://github.com/mbleigh/acts-as-taggable-on/issues/623

namespace :acts_as_taggable_on_engine do

namespace :tag_names do

desc "Forcing collate of tag names to utf8_bin"
task :collate => [:environment] do |t, args|
puts "Changing collate for column 'name' of table 'tags'"
ActiveRecord::Migration.execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
end

end

end

0 comments on commit 65f0425

Please sign in to comment.