class ActiveRecord::ConnectionAdapters::Table
end
t.remove_timestamps
t.remove_index
t.remove_belongs_to
t.remove_references
t.remove
t.boolean
t.binary
t.date
t.time
t.timestamp
t.datetime
t.decimal
t.float
t.integer
t.text
t.string
t.belongs_to
t.references
t.rename
t.change_default
t.change
t.timestamps
t.index
t.column
change_table :table do |t|
Available transformations are:
Also see TableDefinition and SchemaStatements#create_table
Represents a SQL table in an abstract way for updating a table.
def change(column_name, type, options = {})
t.change(:name, :string, :limit => 80)
===== Examples
See TableDefinition#column for details of the options you can use.
Changes the column's definition according to the new options.
def change(column_name, type, options = {}) @base.change_column(@table_name, column_name, type, options) end
def change_default(column_name, default)
t.change_default(:qualification, 'new')
===== Examples
Sets a new default value for a column. See SchemaStatements#change_column_default
def change_default(column_name, default) @base.change_column_default(@table_name, column_name, default) end
def column(column_name, type, options = {})
====== Creating a simple column
===== Example
See TableDefinition#column for details of the options you can use.
Adds a new column to the named table.
def column(column_name, type, options = {}) @base.add_column(@table_name, column_name, type, options) end
def index(column_name, options = {})
====== Creating a named index
t.index([:branch_id, :party_id], :unique => true)
====== Creating a unique index
t.index(:name)
====== Creating a simple index
===== Examples
an Array of Symbols. See SchemaStatements#add_index
Adds a new index to the table. +column_name+ can be a single Symbol, or
def index(column_name, options = {}) @base.add_index(@table_name, column_name, options) end
def initialize(table_name, base)
def initialize(table_name, base) @table_name = table_name @base = base end
def native
def native @base.native_database_types end
def references(*args)
t.references(:goat, :polymorphic => true)
t.references(:goat)
===== Examples
references and belongs_to are acceptable.
Adds a reference. Optionally adds a +type+ column.
def references(*args) options = args.extract_options! polymorphic = options.delete(:polymorphic) args.each do |col| @base.add_column(@table_name, "#{col}_id", :integer, options) @base.add_column(@table_name, "#{col}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) unless polymorphic.nil? end end
def remove(*column_names)
t.remove(:qualification)
===== Examples
Removes the column(s) from the table definition.
def remove(*column_names) @base.remove_column(@table_name, column_names) end
def remove_index(options = {})
====== Remove the index named by_branch_party in the accounts table
t.remove_index :column => [:branch_id, :party_id]
====== Remove the index named accounts_branch_id_party_id_index in the accounts table
t.remove_index :column => :branch_id
====== Remove the index named accounts_branch_id_index in the accounts table
t.remove_index :name
====== Remove the suppliers_name_index in the suppliers table
===== Examples
Removes the given index from the table.
def remove_index(options = {}) @base.remove_index(@table_name, options) end
def remove_references(*args)
t.remove_references(:goat, :polymorphic => true)
t.remove_references(:goat)
===== Examples
remove_references and remove_belongs_to are acceptable.
Removes a reference. Optionally removes a +type+ column.
def remove_references(*args) options = args.extract_options! polymorphic = options.delete(:polymorphic) args.each do |col| @base.remove_column(@table_name, "#{col}_id") @base.remove_column(@table_name, "#{col}_type") unless polymorphic.nil? end end
def remove_timestamps
===== Example
Removes the timestamp columns (created_at and updated_at) from the table.
def remove_timestamps @base.remove_timestamps(@table_name) end
def rename(column_name, new_column_name)
===== Example
Renames a column.
def rename(column_name, new_column_name) @base.rename_column(@table_name, column_name, new_column_name) end
def timestamps
===== Example
Adds timestamps (created_at and updated_at) columns to the table. See SchemaStatements#add_timestamps
def timestamps @base.add_timestamps(@table_name) end