Merge pull request #9120 from hone/db_migrate_with_database_url

fix rake db:migrate when used with ENV['DATABASE_URL']
make type_cast_value a class level method