forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generators should raise an error if a field has an invalid type
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'.
- Loading branch information
Showing
3 changed files
with
50 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters