Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit f9a1899

Browse files
committed
Merge pull request mbleigh#633 from rikettsie/master
mbleigh#623: updated README (added suggestion for manual column alteration).
2 parents 16dcb00 + c9171de commit f9a1899

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ Review the generated migrations then migrate :
5757
rake db:migrate
5858
```
5959

60+
MySql users should also run the following rake task to get special characters
61+
work correctly for tag names, see [issue #623](https://github.com/mbleigh/acts-as-taggable-on/issues/623):
62+
63+
```shell
64+
rake acts_as_taggable_on_engine:tag_names:collate
65+
```
66+
67+
or, alternatively, execute the following command in the MySql console:
68+
69+
```shell
70+
USE my_wonderful_app_db;
71+
ALTER TABLE tags MODIFY name VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin;
72+
```
73+
6074
#### Upgrading
6175

6276
see [UPGRADING](UPGRADING.md)

Rakefile

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require 'rubygems'
22
require 'bundler/setup'
33

4+
import "./lib/tasks/tags_collate_utf8.rake"
5+
46
desc 'Default: run specs'
57
task default: :spec
68

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This migration is added to circumvent issue #623 and have special characters
2+
# work properly
3+
class ChangeCollationForTagNames << ActiveRecord::Migration
4+
5+
def up
6+
if ActsAsTaggableOn::Utils.using_mysql?
7+
execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
8+
end
9+
end
10+
11+
def down
12+
13+
end
14+
15+
end

lib/tasks/tags_collate_utf8.rake

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This rake task is to be run by MySql users only, and fixes the management of
2+
# binary-encoded strings for tag 'names'. Issues:
3+
# https://github.com/mbleigh/acts-as-taggable-on/issues/623
4+
5+
namespace :acts_as_taggable_on_engine do
6+
7+
namespace :tag_names do
8+
9+
desc "Forcing collate of tag names to utf8_bin"
10+
task :collate => [:environment] do |t, args|
11+
puts "Changing collate for column 'name' of table 'tags'"
12+
ActiveRecord::Migration.execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
13+
end
14+
15+
end
16+
17+
end

0 commit comments

Comments
 (0)