--- !ruby/object:RI::MethodDescription 
aliases: []

block_params: 
comment: 
- !ruby/struct:SM::Flow::P 
  body: "Instantiates a new column for the table. The <tt>type</tt> parameter is normally one of the migrations native types, which is one of the following: <tt>:primary_key</tt>, <tt>:string</tt>, <tt>:text</tt>, <tt>:integer</tt>, <tt>:float</tt>, <tt>:decimal</tt>, <tt>:datetime</tt>, <tt>:timestamp</tt>, <tt>:time</tt>, <tt>:date</tt>, <tt>:binary</tt>, <tt>:boolean</tt>."
- !ruby/struct:SM::Flow::P 
  body: You may use a type not in this list as long as it is supported by your database (for example, &quot;polygon&quot; in MySQL), but this will not be database agnostic and should usually be avoided.
- !ruby/struct:SM::Flow::P 
  body: "Available options are (none of these exists by default):"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:limit</tt> - Requests a maximum column length. This is number of characters for <tt>:string</tt> and <tt>:text</tt> columns and number of bytes for :binary and :integer columns.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:default</tt> - The column's default value. Use nil for NULL.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:null</tt> - Allows or disallows <tt>NULL</tt> values in the column. This option could have been named <tt>:null_allowed</tt>.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:precision</tt> - Specifies the precision for a <tt>:decimal</tt> column.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:scale</tt> - Specifies the scale for a <tt>:decimal</tt> column.
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: "For clarity's sake: the precision is the number of significant digits, while the scale is the number of digits that can be stored following the decimal point. For example, the number 123.45 has a precision of 5 and a scale of 2. A decimal with a precision of 5 and a scale of 2 can range from -999.99 to 999.99."
- !ruby/struct:SM::Flow::P 
  body: "Please be aware of different RDBMS implementations behavior with <tt>:decimal</tt> columns:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: The SQL standard says the default scale should be 0, <tt>:scale</tt> &lt;= <tt>:precision</tt>, and makes no comments about the requirements of <tt>:precision</tt>.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "MySQL: <tt>:precision</tt> [1..63], <tt>:scale</tt> [0..30]. Default is (10,0)."
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "PostgreSQL: <tt>:precision</tt> [1..infinity], <tt>:scale</tt> [0..infinity]. No default."
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "SQLite2: Any <tt>:precision</tt> and <tt>:scale</tt> may be used. Internal storage as strings. No default."
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "SQLite3: No restrictions on <tt>:precision</tt> and <tt>:scale</tt>, but the maximum supported <tt>:precision</tt> is 16. No default."
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "Oracle: <tt>:precision</tt> [1..38], <tt>:scale</tt> [-84..127]. Default is (38,0)."
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "DB2: <tt>:precision</tt> [1..63], <tt>:scale</tt> [0..62]. Default unknown."
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "Firebird: <tt>:precision</tt> [1..18], <tt>:scale</tt> [0..18]. Default (9,0). Internal types NUMERIC and DECIMAL have different storage rules, decimal being better."
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "FrontBase?: <tt>:precision</tt> [1..38], <tt>:scale</tt> [0..38]. Default (38,0). WARNING Max <tt>:precision</tt>/<tt>:scale</tt> for NUMERIC is 19, and DECIMAL is 38."
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "SqlServer?: <tt>:precision</tt> [1..38], <tt>:scale</tt> [0..38]. Default (38,0)."
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "Sybase: <tt>:precision</tt> [1..38], <tt>:scale</tt> [0..38]. Default (38,0)."
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "OpenBase?: Documentation unclear. Claims storage in <tt>double</tt>."
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: This method returns <tt>self</tt>.
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Examples
- !ruby/struct:SM::Flow::VERB 
  body: " # Assuming td is an instance of TableDefinition\n td.column(:granted, :boolean)\n # granted BOOLEAN\n\n td.column(:picture, :binary, :limit =&gt; 2.megabytes)\n # =&gt; picture BLOB(2097152)\n\n td.column(:sales_stage, :string, :limit =&gt; 20, :default =&gt; 'new', :null =&gt; false)\n # =&gt; sales_stage VARCHAR(20) DEFAULT 'new' NOT NULL\n\n td.column(:bill_gates_money, :decimal, :precision =&gt; 15, :scale =&gt; 2)\n # =&gt; bill_gates_money DECIMAL(15,2)\n\n td.column(:sensor_reading, :decimal, :precision =&gt; 30, :scale =&gt; 20)\n # =&gt; sensor_reading DECIMAL(30,20)\n\n # While <tt>:scale</tt> defaults to zero on most databases, it\n # probably wouldn't hurt to include it.\n td.column(:huge_integer, :decimal, :precision =&gt; 30)\n # =&gt; huge_integer DECIMAL(30)\n\n # Defines a column with a database-specific type.\n td.column(:foo, 'polygon')\n # =&gt; foo polygon\n"
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Short-hand examples
- !ruby/struct:SM::Flow::P 
  body: Instead of calling <tt>column</tt> directly, you can also work with the short-hand definitions for the default types. They use the type as the method name instead of as a parameter and allow for multiple columns to be defined in a single statement.
- !ruby/struct:SM::Flow::P 
  body: "What can be written like this with the regular calls to column:"
- !ruby/struct:SM::Flow::VERB 
  body: "  create_table &quot;products&quot;, :force =&gt; true do |t|\n    t.column &quot;shop_id&quot;,    :integer\n    t.column &quot;creator_id&quot;, :integer\n    t.column &quot;name&quot;,       :string,   :default =&gt; &quot;Untitled&quot;\n    t.column &quot;value&quot;,      :string,   :default =&gt; &quot;Untitled&quot;\n    t.column &quot;created_at&quot;, :datetime\n    t.column &quot;updated_at&quot;, :datetime\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: "Can also be written as follows using the short-hand:"
- !ruby/struct:SM::Flow::VERB 
  body: "  create_table :products do |t|\n    t.integer :shop_id, :creator_id\n    t.string  :name, :value, :default =&gt; &quot;Untitled&quot;\n    t.timestamps\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: There's a short-hand method for each of the type values declared at the top. And then there's TableDefinition#timestamps that'll add created_at and <tt>updated_at</tt> as datetimes.
- !ruby/struct:SM::Flow::P 
  body: "TableDefinition#references will add an appropriately-named _id column, plus a corresponding _type column if the <tt>:polymorphic</tt> option is supplied. If <tt>:polymorphic</tt> is a hash of options, these will be used when creating the <tt>_type</tt> column. So what can be written like this:"
- !ruby/struct:SM::Flow::VERB 
  body: "  create_table :taggings do |t|\n    t.integer :tag_id, :tagger_id, :taggable_id\n    t.string  :tagger_type\n    t.string  :taggable_type, :default =&gt; 'Photo'\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: "Can also be written as follows using references:"
- !ruby/struct:SM::Flow::VERB 
  body: "  create_table :taggings do |t|\n    t.references :tag\n    t.references :tagger, :polymorphic =&gt; true\n    t.references :taggable, :polymorphic =&gt; { :default =&gt; 'Photo' }\n  end\n"
full_name: ActiveRecord::ConnectionAdapters::TableDefinition#column
is_singleton: false
name: column
params: (name, type, options = {})
visibility: public
