tables

tables(name) Instance Public methods

add_belongs_to

add_belongs_to(table_name, ref_name, options = {}) Instance Public methods Alias for: add_reference

add_column

add_column(table_name, column_name, type, options = {}) Instance Public methods Adds a new column to the named table. See ActiveRecord::ConnectionAdapters::TableDefinition#column for details of the options you can use.

add_index

add_index(table_name, column_name, options = {}) Instance Public methods Adds a new index to the table. column_name can be a single Symbol, or an Array of Symbols. The index will be named after the table and the column name(s), unless you pass :name as an option. Creating a simple index add_index(:suppliers, :name) generates: CREATE INDEX suppliers_name_index ON suppliers(name) Creating a unique index add_index(:accounts, [:branch_id, :party_id], unique: true) generates: CREATE

add_reference

add_reference(table_name, ref_name, options = {}) Instance Public methods Adds a reference. Optionally adds a type column, if :polymorphic option is provided. add_reference and add_belongs_to are acceptable. Create a user_id column add_reference(:products, :user) Create a supplier_id and supplier_type columns add_belongs_to(:products, :supplier, polymorphic: true) Create a supplier_id, supplier_type columns and appropriate index add_reference(:products, :supplier, polymorphic: tr

add_timestamps

add_timestamps(table_name, options = {}) Instance Public methods Adds timestamps (created_at and updated_at) columns to the named table. add_timestamps(:suppliers)

assume_migrated_upto_version

assume_migrated_upto_version(version, migrations_paths = ActiveRecord::Migrator.migrations_paths) Instance Public methods

change_column

change_column(table_name, column_name, type, options = {}) Instance Public methods Changes the column's definition according to the new options. See ActiveRecord::ConnectionAdapters::TableDefinition#column for details of the options you can use. change_column(:suppliers, :name, :string, limit: 80) change_column(:accounts, :description, :text)

change_column_default

change_column_default(table_name, column_name, default) Instance Public methods Sets a new default value for a column: change_column_default(:suppliers, :qualification, 'new') change_column_default(:accounts, :authorized, 1) Setting the default to nil effectively drops the default: change_column_default(:users, :email, nil)

change_column_null

change_column_null(table_name, column_name, null, default = nil) Instance Public methods Sets or removes a +NOT NULL+ constraint on a column. The null flag indicates whether the value can be NULL. For example change_column_null(:users, :nickname, false) says nicknames cannot be NULL (adds the constraint), whereas change_column_null(:users, :nickname, true) allows them to be NULL (drops the constraint). The method accepts an optional fourth argument to replace existing +NULL+s wit