Yuri
2007-Jan-26 07:20 UTC
rake test:x recreates tables in MySQL with server (not database) charset and collation
Any thoughts on how to avoid this problem? Already tried: 1. 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 2. 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: 1. Create DB (MySQL 5.0.24a) CREATE DATABASE foobar CHARACTER SET utf8 COLLATE utf8_bin; 2. Run migration (Rails 1.2) 3. 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 4. Run rake test:units. Tests fail as side-effect of incorrect collation. 5. 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. ;) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yuri
2007-Jan-27 16:25 UTC
Re: rake test:x recreates tables in MySQL with server (not database) charset and collation
I''ve since realized that the rake test tasks probably use the schema dump mechanism - not migrations - to drop and recreate the DB; I''d surmise that http://dev.rubyonrails.org/ticket/4751 is at least related to this problem with test DB''s. For the moment, I shoved a hack into mysql_adapter to read and use character sets and collations when recreating DB''s. I suspect there probably needs to be a better long term solution (or at least a better coded and tested one.) The full diff for the above follows (there''s a couple obvious problems with this code and probably many non-obvious ones - don''t use this anywhere that counts): Index: activerecord/lib/active_record/connection_adapters/ mysql_adapter.rb ==================================================================--- activerecord/lib/active_record/connection_adapters/ mysql_adapter.rb (revision 6045) +++ activerecord/lib/active_record/connection_adapters/ mysql_adapter.rb (working copy) @@ -305,12 +305,14 @@ end def recreate_database(name) #:nodoc: + settings = select_one(''SELECT @@character_set_database AS charset, @@collation_database AS collation'') drop_database(name) - create_database(name) + create_database(name, settings) end def create_database(name) #:nodoc: - execute "CREATE DATABASE `#{name}`" + settings_sql = " CHARACTER SET #{settings[''charset'']} COLLATE #{settings[''collation'']}" if (settings) + execute "CREATE DATABASE `#{name}` #{settings_sql}" end def drop_database(name) #:nodoc: -- end diff --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Seemingly Similar Threads
- MySQL connection collation
- Creating a DB in the schema import process
- ActiveRecord::Base.connection.create_database defaults to latin1
- Mysql::Error: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE)
- Mysql collations error