mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
d163fcd620
Generators can create invalid migrations when passing an invalid field type. For example, when mixing up the name and type: bin/rails g model post string:title This will generate a field for post with a column named `string` of the type `title`, instead of a column named `title` of the type `string`. Running the migration will result in an error as the type `title` is not known to the database. Instead of generating invalid files, the generator should raise an error if the type is invalid. We validate the type by checking if it's a default migration types like: string, integer, datetime, but also references, and rich_text. If the type isn't a default type, we can ask the database connection if the type is valid. This uses the `valid_type?` method defined on each database adapter, which returns true if the adapter supports the column type. This method is also used by the SchemaDumper. Some gems like 'postgis' add custom types. The 'postgis' gem adds these types by overriding the `native_database_types` method. That method is used by `valid_type?` method on the database adapter, making this change compatible with 'postgis'. |
||
---|---|---|
.. | ||
application | ||
command | ||
commands | ||
configuration | ||
engine | ||
fixtures | ||
generators | ||
isolation | ||
minitest | ||
railties | ||
test_unit | ||
abstract_unit.rb | ||
app_loader_test.rb | ||
backtrace_cleaner_test.rb | ||
code_statistics_calculator_test.rb | ||
code_statistics_test.rb | ||
console_helpers.rb | ||
engine_test.rb | ||
env_helpers.rb | ||
generators_test.rb | ||
initializable_test.rb | ||
json_params_parsing_test.rb | ||
path_generation_test.rb | ||
paths_test.rb | ||
rack_logger_test.rb | ||
rails_info_controller_test.rb | ||
rails_info_test.rb | ||
secrets_test.rb | ||
version_test.rb |