From 3e1373a773085d5f19cb6a466ab2736cc1ca2713 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Tue, 10 Jun 2014 10:21:15 +0200 Subject: [PATCH] docs, refactor docs about column modifiers. [ci skip] [Matthew Draper & Yves Senn] This is a follow up to #15602 which rendered the guides in a weird state: > You can also specify some options just after the field type between curly braces. You can use the following modifiers: > `null` Allows or disallows `NULL` values in the column. > NOTE: `null` and `default` cannot be specified via command line. The modifiers are now moved into a separate section. The generator simply referes to that section. Related to #15583. /cc @JuanitoFatas Conflicts: guides/source/migrations.md --- guides/source/migrations.md | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/guides/source/migrations.md b/guides/source/migrations.md index d9b8c60404..9ba2a3f969 100644 --- a/guides/source/migrations.md +++ b/guides/source/migrations.md @@ -292,18 +292,10 @@ end You can append as many column name/type pairs as you want. -### Supported Type Modifiers +### Passing Modifiers -You can also specify some options just after the field type between curly -braces. You can use the following modifiers: - -* `limit` Sets the maximum size of the `string/text/binary/integer` fields. -* `precision` Defines the precision for the `decimal` fields, representing the total number of digits in the number. -* `scale` Defines the scale for the `decimal` fields, representing the number of digits after the decimal point. -* `polymorphic` Adds a `type` column for `belongs_to` associations. -* `null` Allows or disallows `NULL` values in the column. - -NOTE: `null` and `default` cannot be specified via command line. +Some commonly used [type modifiers](#column-modifiers) can be passed directly on +the command line. They are enclosed by curly braces and follow the field type: For instance, running: @@ -322,6 +314,8 @@ class AddDetailsToProducts < ActiveRecord::Migration end ``` +TIP: Have a look at the generators help output for further details. + Writing a Migration ------------------- @@ -416,6 +410,21 @@ end removes the `description` and `name` columns, creates a `part_number` string column and adds an index on it. Finally it renames the `upccode` column. +### Column Modifiers + +Column modifiers can be applied when creating or changing a column: + +* `limit` Sets the maximum size of the `string/text/binary/integer` fields. +* `precision` Defines the precision for the `decimal` fields, representing the total number of digits in the number. +* `scale` Defines the scale for the `decimal` fields, representing the number of digits after the decimal point. +* `polymorphic` Adds a `type` column for `belongs_to` associations. +* `null` Allows or disallows `NULL` values in the column. +* `default` Allows to set a default value on the column. NOTE: If using a dynamic value (such as date), the default will only be calculated the first time (e.g. on the date the migration is applied.) +* `index` Adds an index for the column. + +Some adapters may support additional options; see the adapter specific API docs +for further information. + ### When Helpers aren't Enough If the helpers provided by Active Record aren't enough you can use the `execute` -- GitLab