column_exists?

column_exists?(table_name, column_name, type = nil, options = {}) Instance Public methods Checks to see if a column exists in a given table. # Check a column exists column_exists?(:suppliers, :name) # Check a column exists of a particular type column_exists?(:suppliers, :name, :string) # Check a column exists with a specific definition column_exists?(:suppliers, :name, :string, limit: 100) column_exists?(:suppliers, :name, :string, default: 'default') column_exists?(:suppliers, :

change_table

change_table(table_name, options = {}) Instance Public methods A block for changing columns in table. # change_table() yields a Table instance change_table(:suppliers) do |t| t.column :name, :string, limit: 60 # Other column alterations here end The options hash can include the following keys: :bulk Set this to true to make this a bulk alter query, such as ALTER TABLE `users` ADD COLUMN age INT(11), ADD COLUMN birthdate DATETIME ... Defaults to false. Add a column chan

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

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

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)

assume_migrated_upto_version

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

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)

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_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_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.