class Jennifer::Migration::TableBuilder::CreateTable

Overview

Component responsible for creating a new table based on specified columns and properties.

create_table(:contacts) do |t|
  t.string :name, {:size => 30}
  t.integer :age
  t.integer :tags, {:array => true}
  t.decimal :ballance
  t.field :gender, :gender_enum
  t.timestamps true
end

Defined in:

jennifer/migration/table_builder/create_table.cr

Instance Method Summary

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

Instance Method Detail

def bigint(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #bigint with given options.

For more details see ChangeTable#add_column.


[View source]
def blchar(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #blchar with given options.

For more details see ChangeTable#add_column.


[View source]
def blob(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #blob with given options.

For more details see ChangeTable#add_column.


[View source]
def bool(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #bool with given options.

For more details see ChangeTable#add_column.


[View source]
def box(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #box with given options.

For more details see ChangeTable#add_column.


[View source]
def bytea(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #bytea with given options.

For more details see ChangeTable#add_column.


[View source]
def char(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #char with given options.

For more details see ChangeTable#add_column.


[View source]
def circle(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #circle with given options.

For more details see ChangeTable#add_column.


[View source]
def column(name, type, options = DbOptions.new) #

Alias for #field.


[View source]
def date(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #date with given options.

For more details see ChangeTable#add_column.


[View source]
def date_time(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #date_time with given options.

For more details see ChangeTable#add_column.


[View source]
def decimal(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #decimal with given options.

For more details see ChangeTable#add_column.


[View source]
def double(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #double with given options.

For more details see ChangeTable#add_column.


[View source]
def enum(name : String | Symbol, values : Array(String), options : Hash(Symbol, AAllowedTypes) = DbOptions.new) #

Defines new enum column name with given options.

values argument specified allowed enum values.

For more details see ChangeTable#add_column


[View source]
def explain #
Description copied from class Jennifer::Migration::TableBuilder::Base

Returns string presentation of invoked changes.


[View source]
def field(name : String | Symbol, type : Symbol | String, options : Hash(Symbol, AAllowedTypes) = DbOptions.new) #

Defines field name of type type with with given options.

For more details see ChangeTable#add_column. The only difference is that type argument is treated as SQL datatype - it works same way as specifying :sql_type parameter.

create_enum :gender_enum, %w(unspecified female male)

create_table :users do |t|
  t.field :gender, :gender_enum
end

Migration above will create PostreSQL enum and a table with column of that type.


[View source]
def fields : 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)) #

[View source]
def float(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #float with given options.

For more details see ChangeTable#add_column.


[View source]
def 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.

For more details see Migration::Base#add_foreign_key.


[View source]
def 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 index.

For more details see Migration::Base#add_index.


[View source]
def index(field : Symbol, type : Symbol? = nil, name : String? = nil, length : Int32? = nil, order : Symbol? = nil) #

Adds index.

For more details see Migration::Base#add_index.


[View source]
def integer(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #integer with given options.

For more details see ChangeTable#add_column.


[View source]
def json(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #json with given options.

For more details see ChangeTable#add_column.


[View source]
def jsonb(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #jsonb with given options.

For more details see ChangeTable#add_column.


[View source]
def line(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #line with given options.

For more details see ChangeTable#add_column.


[View source]
def lseg(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #lseg with given options.

For more details see ChangeTable#add_column.


[View source]
def numeric(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #numeric with given options.

For more details see ChangeTable#add_column.


[View source]
def oid(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #oid with given options.

For more details see ChangeTable#add_column.


[View source]
def path(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #path with given options.

For more details see ChangeTable#add_column.


[View source]
def point(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #point with given options.

For more details see ChangeTable#add_column.


[View source]
def polygon(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #polygon with given options.

For more details see ChangeTable#add_column.


[View source]
def process #
Description copied from class Jennifer::Migration::TableBuilder::Base

Invokes current command.


[View source]
def reference(name, type : Symbol = :integer, options : Hash(Symbol, AAllowedTypes) = DbOptions.new) #

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.

reference :user
reference :order, :bigint
reference :taggable, {:polymorphic => true}

[View source]
def short(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #short with given options.

For more details see ChangeTable#add_column.


[View source]
def string(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #string with given options.

For more details see ChangeTable#add_column.


[View source]
def text(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #text with given options.

For more details see ChangeTable#add_column.


[View source]
def timestamp(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #timestamp with given options.

For more details see ChangeTable#add_column.


[View source]
def timestamps(null : Bool = false) #

Defines created_at and updated_at timestamp fields.

Argument null sets :null option for both fields.


[View source]
def timestamptz(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #timestamptz with given options.

For more details see ChangeTable#add_column.


[View source]
def tinyint(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #tinyint with given options.

For more details see ChangeTable#add_column.


[View source]
def uuid(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #uuid with given options.

For more details see ChangeTable#add_column.


[View source]
def varchar(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #varchar with given options.

For more details see ChangeTable#add_column.


[View source]
def xml(name : String | Symbol, options = DbOptions.new) #

Defines new column name of type #xml with given options.

For more details see ChangeTable#add_column.


[View source]