lib/generators/declare_schema/migration/migrator.rb
# TODO: rewrite this method to use charset and collation variables rather than manipulating strings. -Colin
rewrite this method to use charset and collation variables rather than manipulating strings. -Colin
rewrite this method to use charset and collation variables rather than manipulating strings . - Colin
def fix_mysql_charset_and_collation(dumped_schema)
          if !dumped_schema['options: ']
            dumped_schema.sub!('",', "\", options: \"DEFAULT CHARSET=#{::DeclareSchema.default_charset} "+
              "COLLATE=#{::DeclareSchema.default_collation}\",")
          end
          default_charset   = dumped_schema[/CHARSET=(\w+)/, 1]   or raise "unable to find charset in #{dumped_schema.inspect}"
          default_collation = dumped_schema[/COLLATE=(\w+)/, 1] || default_collation_from_charset(default_charset) or
            raise "unable to find collation in #{dumped_schema.inspect} or charset #{default_charset.inspect}"
          dumped_schema.split("\n").map do |line|
            if line['t.text'] || line['t.string']
              if !line['charset: ']
                if line['collation: ']
                  line.sub!('collation: ', "charset: #{default_charset.inspect}, collation: ")
                else
                  line << ", charset: #{default_charset.inspect}"
                end
              end
              line['collation: '] or line << ", collation: #{default_collation.inspect}"
            end
            line
          end.join("\n")
        end
def fix_mysql_charset_and_collation ( dumped_schema ) if ! dumped_schema [ 'options: ' ] dumped_schema . sub! ( '",' , "\", options: \"DEFAULT CHARSET=#{::DeclareSchema.default_charset} " + "COLLATE=#{::DeclareSchema.default_collation}\"," ) end default_charset = dumped_schema [ / CHARSET=( \w +) / , 1 ] or raise "unable to find charset in #{dumped_schema.inspect}" default_collation = dumped_schema [ / COLLATE=( \w +) / , 1 ] || default_collation_from_charset ( default_charset ) or raise "unable to find collation in #{dumped_schema.inspect} or charset #{default_charset.inspect}" dumped_schema . split ( "\n" ) . map do | line | if line [ 't.text' ] || line [ 't.string' ] if ! line [ 'charset: ' ] if line [ 'collation: ' ] line . sub! ( 'collation: ' , "charset: #{default_charset.inspect}, collation: " ) else line << ", charset: #{default_charset.inspect}" end end line [ 'collation: ' ] or line << ", collation: #{default_collation.inspect}" end line end . join ( "\n" ) end
TODO: rewrite this method to use charset and collation variables rather than manipulating strings.
TODO : rewrite this method to use charset and collation variables rather than manipulating strings .
dumped_schema
<not_specific>