Any thoughts on how to avoid this problem? Already tried:
- Setting the charset and collation in migration 001 - no effect:
def self.up
db_name = ActiveRecord::Base::connection.current_database()
execute “ALTER DATABASE #{db_name} CHARACTER SET utf8 COLLATE
utf8_bin”
end
- Setting the charset and collation on each table individually - no
effect:
{:options=>“engine=InnoDB CHARACTER SET utf8 COLLATE utf8_bin”}
Note that development and production environments work fine with
database default, migration 001, or setting per each table. Only the
test db, specifically after a rake test:units run has this problem.
Repro:
-
Create DB (MySQL 5.0.24a)
CREATE DATABASE foobar CHARACTER SET utf8 COLLATE utf8_bin; -
Run migration (Rails 1.2)
-
Verify database and all tables have charset utf8 and collation of
utf_bin: yes.
select @@character_set_server, etc…
latin1 latin1_swedish_ci utf8
utf8_bin
-
Run rake test:units. Tests fail as side-effect of incorrect
collation. -
Verify database and all tables have charset utf8 and collation of
utf_bin: no - database still has correct settings but each table is now
latin1_swedish_ci.
Ideally I’d like to run the rake test:x’s without touching schema at
all - unless it’s going to mimic exactly what can happen to
production, i.e. never drop or create the DB and only alter schema
through migration files.
Short of that, any ideas on just getting past this would be great. My
next step will be to create a shell script that just runs every
*_test.rb file. Or maybe revert back to Ant.