Skip to content

Commit

Permalink
Merge pull request #633 from rikettsie/master
Browse files Browse the repository at this point in the history
#623: updated README (added suggestion for manual column alteration).
  • Loading branch information
seuros committed Feb 26, 2015
2 parents a13c7a2 + 65f0425 commit 16908df
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ Review the generated migrations then migrate :
rake db:migrate
```

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;
ALTER TABLE tags MODIFY name VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin;
```

#### Upgrading

see [UPGRADING](UPGRADING.md)
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 16908df

Please sign in to comment.