class Jennifer::Migration::TableBuilder::ChangeTable
- Jennifer::Migration::TableBuilder::ChangeTable
- Jennifer::Migration::TableBuilder::Base
- Reference
- Object
Overview
Component responsible for altering existing table based on specified columns and properties.
change_table(:contacts) do |t|
t.rename_table :users
t.add_column :name, :string, {:size => 30}
t.drop_column :age
end
Defined in:
jennifer/migration/table_builder/change_table.crConstructors
Instance Method Summary
-
#add_column(name : String | Symbol, type : Symbol? = nil, options : Hash(Symbol, AAllowedTypes) = DbOptions.new)
Defines new column name of type with given options.
-
#add_foreign_key(to_table : String | Symbol, column = nil, primary_key = nil, name = nil, *, on_update : Symbol = DEFAULT_ON_EVENT_ACTION, on_delete : Symbol = DEFAULT_ON_EVENT_ACTION)
Creates a foreign key constraint to
to_table
table. -
#add_index(fields : Array(Symbol), type : Symbol? = nil, name : String? = nil, lengths : Hash(Symbol, Int32) = {} of Symbol => Int32, orders : Hash(Symbol, Symbol) = {} of Symbol => Symbol)
Adds new index.
- #add_index(field : Symbol, type : Symbol? = nil, name : String? = nil, length : Int32? = nil, order : Symbol? = nil)
-
#add_reference(name, type : Symbol = :integer, options : Hash(Symbol, AAllowedTypes) = DbOptions.new)
Adds a reference.
-
#add_timestamps(null : Bool = false)
Add
created_at
andupdated_at
timestamp columns. -
#change_column(name : String | Symbol, type : Symbol? = nil, options : Hash(Symbol, AAllowedTypes) = DbOptions.new)
Changes the column's definition according to the new options.
- #changed_columns : Hash(String, Hash(Symbol, Array(Bool | Float32 | Float64 | Int32 | Int64 | JSON::Any | String | Symbol | Nil) | Bool | Float32 | Float64 | Int32 | Int64 | JSON::Any | String | Symbol | Nil))
-
#drop_column(name : String | Symbol)
Drops column with given name.
- #drop_columns : Array(String)
-
#drop_foreign_key(to_table : String | Symbol, column = nil, name = nil)
Drops foreign key of to_table.
-
#drop_index(fields : Array(Symbol) = [] of Symbol, name : String? = nil)
Drops the index from the table.
- #drop_index(field : Symbol? = nil, name : String? = nil)
-
#drop_reference(name, options : Hash(Symbol, AAllowedTypes) = DbOptions.new)
Drops the reference.
-
#explain
Returns string presentation of invoked changes.
- #new_table_name : String
-
#process
Invokes current command.
-
#rename_table(new_name : String | Symbol)
Renames table to the given new_name.
Instance methods inherited from class Jennifer::Migration::TableBuilder::Base
adapter : Adapter::Base
adapter,
column_exists?(*args, **options)column_exists?(*args, **options, &) column_exists?, explain explain, index_exists?(*args, **options)
index_exists?(*args, **options, &) index_exists?, name : String name, process process, process_commands process_commands, schema_processor(*args, **options)
schema_processor(*args, **options, &) schema_processor, table_exists?(*args, **options)
table_exists?(*args, **options, &) table_exists?
Constructor methods inherited from class Jennifer::Migration::TableBuilder::Base
new(adapter, name : String | Symbol)
new
Constructor Detail
Instance Method Detail
Defines new column name of type with given options.
The type argument should be one of the following supported data types (see Jennifer::Adapter::TYPES).
You may use any type that isn't in this list as long as it is supported by your database by skipping type
and passing sql_type
option.
Available options are (none of these exists by default):
:array
- creates and array of given type;:serial
- makes columnSERIAL
;:sql_type
- allow to specify custom SQL data type;:size
- requests a maximum column length; e.g. this is a number of characters instring
column and number of bytes fortext
orinteger
;:null
- allows or disallowsNULL
values;:primary
- adds primary key constraint to the column; ATM only one field may be a primary key;:default
- the column's default value;:auto_increment
- add autoincrement to the column.
add_column :picture, :blob
add_column :status, :string, {:size => 20, :default => "draft", :null => false}
add_column :skills, :text, {:array => true}
Creates a foreign key constraint to to_table
table.
For more details see Migration::Base#add_foreign_key
.
Adds new index.
For more details see Migration::Base#add_index
Adds a reference.
The reference column is an integer
by default, type argument can be used to specify a different type.
If polymorphic option is true
- additional string field "#{name}_type"
is created and foreign key is
not added.
:to_table
, :column
, :primary_key
and :key_name
options are used to create a foreign key constraint.
See Migration::Base#add_foreign_key
for details.
add_reference :user
add_reference :order, :bigint
add_reference :taggable, {:polymorphic => true}
Add created_at
and updated_at
timestamp columns.
Argument null sets :null
option for both columns.
Changes the column's definition according to the new options.
See #add_column
for details of the options you can use.
Additional available options:
:new_name
- specifies a new name for the column;:default
-:none
value drops any default value specified before.
change_column :description, {:new_name => "information"}
change_column :price, {:default => :none}
Drops foreign key of to_table.
For more details see Migration::Base#drop_foreign_key
.
Drops the index from the table.
For more details see Migration::Base#drop_index
.
Drops the reference.
options can include :polymorphic
, :to_table
and :column
options. For more details see
#add_reference
.
Returns string presentation of invoked changes.
Invokes current command.
Renames table to the given new_name.
rename_table :users