class Jennifer::Migration::TableBuilder::CreateTable
- Jennifer::Migration::TableBuilder::CreateTable
- Jennifer::Migration::TableBuilder::Base
- Reference
- Object
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.crInstance Method Summary
-
#bigint(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#bigintwith given options. -
#blchar(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#blcharwith given options. -
#blob(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#blobwith given options. -
#bool(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#boolwith given options. -
#box(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#boxwith given options. -
#bytea(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#byteawith given options. -
#char(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#charwith given options. -
#circle(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#circlewith given options. -
#column(name, type, options = DbOptions.new)
Alias for
#field. -
#date(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#datewith given options. -
#date_time(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#date_timewith given options. -
#decimal(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#decimalwith given options. -
#double(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#doublewith given options. -
#enum(name : String | Symbol, values : Array(String), options : Hash(Symbol, AAllowedTypes) = DbOptions.new)
Defines new enum column name with given options.
-
#explain
Returns string presentation of invoked changes.
-
#field(name : String | Symbol, type : Symbol | String, options : Hash(Symbol, AAllowedTypes) = DbOptions.new)
Defines field name of type type with with given options.
- #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))
-
#float(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#floatwith given options. -
#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_tabletable. -
#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.
-
#index(field : Symbol, type : Symbol? = nil, name : String? = nil, length : Int32? = nil, order : Symbol? = nil)
Adds index.
-
#integer(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#integerwith given options. -
#json(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#jsonwith given options. -
#jsonb(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#jsonbwith given options. -
#line(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#linewith given options. -
#lseg(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#lsegwith given options. -
#numeric(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#numericwith given options. -
#oid(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#oidwith given options. -
#path(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#pathwith given options. -
#point(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#pointwith given options. -
#polygon(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#polygonwith given options. -
#process
Invokes current command.
-
#reference(name, type : Symbol = :integer, options : Hash(Symbol, AAllowedTypes) = DbOptions.new)
Adds a reference.
-
#short(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#shortwith given options. -
#string(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#stringwith given options. -
#text(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#textwith given options. -
#timestamp(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#timestampwith given options. -
#timestamps(null : Bool = false)
Defines
created_atandupdated_attimestamp fields. -
#timestamptz(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#timestamptzwith given options. -
#tinyint(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#tinyintwith given options. -
#uuid(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#uuidwith given options. -
#varchar(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#varcharwith given options. -
#xml(name : String | Symbol, options = DbOptions.new)
Defines new column name of type
#xmlwith given options.
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
Defines new column name of type #bigint with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #blchar with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #blob with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #bool with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #box with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #bytea with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #char with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #circle with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #date with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #date_time with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #decimal with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #double with given options.
For more details see ChangeTable#add_column.
Defines new enum column name with given options.
values argument specified allowed enum values.
For more details see ChangeTable#add_column
Returns string presentation of invoked changes.
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.
Defines new column name of type #float with given options.
For more details see ChangeTable#add_column.
Creates a foreign key constraint to to_table table.
For more details see Migration::Base#add_foreign_key.
Adds index.
For more details see Migration::Base#add_index.
Adds index.
For more details see Migration::Base#add_index.
Defines new column name of type #integer with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #json with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #jsonb with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #line with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #lseg with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #numeric with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #oid with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #path with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #point with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #polygon with given options.
For more details see ChangeTable#add_column.
Invokes current command.
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}
Defines new column name of type #short with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #string with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #text with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #timestamp with given options.
For more details see ChangeTable#add_column.
Defines created_at and updated_at timestamp fields.
Argument null sets :null option for both fields.
Defines new column name of type #timestamptz with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #tinyint with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #uuid with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #varchar with given options.
For more details see ChangeTable#add_column.
Defines new column name of type #xml with given options.
For more details see ChangeTable#add_column.