Skip to content

Commit

Permalink
Do not refer to AbstractMysqlAdapter for checking the connection adap…
Browse files Browse the repository at this point in the history
…ter type.
  • Loading branch information
knu committed Feb 25, 2015
1 parent eaaf66b commit d21fb84
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions db/migrate/20140813110107_set_charset_for_mysql.rb
Expand Up @@ -15,10 +15,8 @@ def all_models
end

def change
conn = ActiveRecord::Base.connection

# This is migration is for MySQL only.
return unless conn.is_a?(ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter)
return unless mysql?

reversible do |dir|
dir.up do
Expand Down Expand Up @@ -63,12 +61,16 @@ def change
execute 'ALTER TABLE %s CHARACTER SET utf8 COLLATE utf8_unicode_ci' % table_name
}

execute 'ALTER DATABASE %s CHARACTER SET utf8 COLLATE utf8_unicode_ci' % conn.current_database
execute 'ALTER DATABASE %s CHARACTER SET utf8 COLLATE utf8_unicode_ci' % connection.current_database
end

dir.down do
# Do nada; no use to go back
end
end
end

def mysql?
ActiveRecord::Base.connection.adapter_name =~ /mysql/i
end
end

0 comments on commit d21fb84

Please sign in to comment.