Class | ActiveRecord::ConnectionAdapters::TableDefinition
In: | lib/active_record/connection_adapters/abstract/schema_definitions.rb
Parent: | Object

Represents a SQL table in an abstract way. Columns are stored as ColumnDefinition in the columns attribute.

### Methods

[] column new primary_key to_sql

### Attributes

columns | [RW] |

### Public Class methods

new(base)

### Public Instance methods

[](name)

Returns a ColumnDefinition for the column with name `name`.

column(name, type, options = {})

Instantiates a new column for the table. The `type` parameter must be one of the following values: `:primary_key`, `:string`, `:text`, `:integer`, `:float`, `:datetime`, `:timestamp`, `:time`, `:date`, `:binary`, `:boolean`.

Available options are (none of these exists by default):

- `:limit`: Requests a maximum column length (`:string`, `:text`, `:binary` or `:integer` columns only)
- `:default`: The column‘s default value. You cannot explicitely set the default value to `NULL`. Simply leave off this option if you want a `NULL` default value.
- `:null`: Allows or disallows `NULL` values in the column. This option could have been named `:null_allowed`.

This method returns `self`.

##### Examples

     # Assuming def is an instance of TableDefinition
     def.column(:granted, :boolean)
       #=> granted BOOLEAN

     def.column(:picture, :binary, :limit => 2.megabytes)
       #=> picture BLOB(2097152)

     def.column(:sales_stage, :string, :limit => 20, :default => 'new', :null => false)
       #=> sales_stage VARCHAR(20) DEFAULT 'new' NOT NULL

primary_key(name)

Appends a primary key definition to the table definition. Can be called multiple times, but this is probably not a good idea.

to_sql()

Returns a String whose contents are the column definitions concatenated together. This string can then be pre and appended to to generate the final SQL to create the table.

[Validate]