diff --git a/lib/generators/unread/migration/templates/migration.rb b/lib/generators/unread/migration/templates/migration.rb index 1e959f9..098a51c 100644 --- a/lib/generators/unread/migration/templates/migration.rb +++ b/lib/generators/unread/migration/templates/migration.rb @@ -1,6 +1,6 @@ class UnreadMigration < Unread::MIGRATION_BASE_CLASS def self.up - create_table ReadMark, force: true do |t| + create_table ReadMark, force: true, options: create_options do |t| t.references :readable, polymorphic: { null: false } t.references :reader, polymorphic: { null: false } t.datetime :timestamp @@ -12,4 +12,13 @@ def self.up def self.down drop_table ReadMark end + + def self.create_options + options = '' + if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) \ + && ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) + options = 'DEFAULT CHARSET=latin1' + end + options + end end