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.rename_index
t.index
t.column
change_table :table do |t|
Available transformations are:
Also see TableDefinition and SchemaStatements#create_table
Represents an SQL table in an abstract way for updating a table.
def change(column_name, type, options = {})
t.change(:name, :string, limit: 80)
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')
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
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 column_exists?(column_name, type = nil, options = {})
def column_exists?(column_name, type = nil, options = {}) @base.column_exists?(@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
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 index_exists?(column_name, options = {})
def index_exists?(column_name, options = {}) @base.index_exists?(@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.belongs_to(:supplier, polymorphic: true)
t.references(:user)
references and belongs_to are acceptable.
Adds a reference. Optionally adds a +type+ column, if :polymorphic option is provided.
def references(*args) options = args.extract_options! args.each do |ref_name| @base.add_reference(@table_name, ref_name, options) end end
def remove(*column_names)
t.remove(:qualification)
Removes the column(s) from the table definition.
def remove(*column_names) @base.remove_columns(@table_name, *column_names) end
def remove_index(options = {})
====== Remove the index named by_branch_party in the table_name table
t.remove_index column: [:branch_id, :party_id]
====== Remove the index named index_table_name_on_branch_id_and_party_id in the table_name table
t.remove_index column: :branch_id
====== Remove the index named index_table_name_on_branch_id in the table_name table
t.remove_index :column
====== Remove the index_table_name_on_column in the table_name table
Removes the given index from the table.
def remove_index(options = {}) @base.remove_index(@table_name, options) end
def remove_references(*args)
t.remove_belongs_to(:supplier, polymorphic: true)
t.remove_references(:user)
remove_references and remove_belongs_to are acceptable.
Removes a reference. Optionally removes a +type+ column.
def remove_references(*args) options = args.extract_options! args.each do |ref_name| @base.remove_reference(@table_name, ref_name, options) end end
def remove_timestamps
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)
Renames a column.
def rename(column_name, new_column_name) @base.rename_column(@table_name, column_name, new_column_name) end
def rename_index(index_name, new_index_name)
Renames the given index on the table.
def rename_index(index_name, new_index_name) @base.rename_index(@table_name, index_name, new_index_name) end
def timestamps
Adds timestamps (+created_at+ and +updated_at+) columns to the table. See SchemaStatements#add_timestamps
def timestamps @base.add_timestamps(@table_name) end