Constants

TYPE_BINARY

TYPE_BINARY = 'binary' : string

Binary column type

TYPE_BINARY_UUID

TYPE_BINARY_UUID = 'binaryuuid' : string

Binary UUID column type

TYPE_DATE

TYPE_DATE = 'date' : string

Date column type

TYPE_DATETIME

TYPE_DATETIME = 'datetime' : string

Datetime column type

TYPE_TIME

TYPE_TIME = 'time' : string

Time column type

TYPE_TIMESTAMP

TYPE_TIMESTAMP = 'timestamp' : string

Timestamp column type

TYPE_JSON

TYPE_JSON = 'json' : string

JSON column type

TYPE_STRING

TYPE_STRING = 'string' : string

String column type

TYPE_TEXT

TYPE_TEXT = 'text' : string

Text column type

TYPE_TINYINTEGER

TYPE_TINYINTEGER = 'tinyinteger' : string

Tiny Integer column type

TYPE_SMALLINTEGER

TYPE_SMALLINTEGER = 'smallinteger' : string

Small Integer column type

TYPE_INTEGER

TYPE_INTEGER = 'integer' : string

Integer column type

TYPE_BIGINTEGER

TYPE_BIGINTEGER = 'biginteger' : string

Big Integer column type

TYPE_FLOAT

TYPE_FLOAT = 'float' : string

Float column type

TYPE_DECIMAL

TYPE_DECIMAL = 'decimal' : string

Decimal column type

TYPE_BOOLEAN

TYPE_BOOLEAN = 'boolean' : string

Boolean column type

TYPE_UUID

TYPE_UUID = 'uuid' : string

UUID column type

Methods

name()

name() : string

Get the name of the table.

Returns

string

addColumn()

addColumn(string  $name, array|string  $attrs) : $this

Add a column to the table.

Attributes

Columns can have several attributes:

  • type The type of the column. This should be one of CakePHP's abstract types.
  • length The length of the column.
  • precision The number of decimal places to store for float and decimal types.
  • default The default value of the column.
  • null Whether or not the column can hold nulls.
  • fixed Whether or not the column is a fixed length column. This is only present/valid with string columns.
  • unsigned Whether or not the column is an unsigned column. This is only present/valid for integer, decimal, float columns.

In addition to the above keys, the following keys are implemented in some database dialects, but not all:

  • comment The comment for the column.

Parameters

string $name

The name of the column

array|string $attrs

The attributes for the column.

Returns

$this

getColumn()

getColumn(string  $name) : array|null

Get column data in the table.

Parameters

string $name

The column name.

Returns

array|null —

Column data or null.

hasColumn()

hasColumn(string  $name) : boolean

Returns true if a column exists in the schema.

Parameters

string $name

Column name.

Returns

boolean

removeColumn()

removeColumn(string  $name) : $this

Remove a column from the table schema.

If the column is not defined in the table, no error will be raised.

Parameters

string $name

The name of the column

Returns

$this

columns()

columns() : array<mixed,string>

Get the column names in the table.

Returns

array<mixed,string>

getColumnType()

getColumnType(string  $name) : string|null

Returns column type or null if a column does not exist.

Parameters

string $name

The column to get the type of.

Returns

string|null

setColumnType()

setColumnType(string  $name, string  $type) : $this

Sets the type of a column.

Parameters

string $name

The column to set the type of.

string $type

The type to set the column to.

Returns

$this

baseColumnType()

baseColumnType(string  $column) : string|null

Returns the base type name for the provided column.

This represent the database type a more complex class is based upon.

Parameters

string $column

The column name to get the base type from

Returns

string|null —

The base type name

isNullable()

isNullable(string  $name) : boolean

Check whether or not a field is nullable

Missing columns are nullable.

Parameters

string $name

The column to get the type of.

Returns

boolean —

Whether or not the field is nullable.

typeMap()

typeMap() : array

Returns an array where the keys are the column names in the schema and the values the database type they have.

Returns

array

defaultValues()

defaultValues() : array

Get a hash of columns and their default values.

Returns

array

setOptions()

setOptions(array  $options) : $this

Sets the options for a table.

Table options allow you to set platform specific table level options. For example the engine type in MySQL.

Parameters

array $options

The options to set, or null to read options.

Returns

$this

getOptions()

getOptions() : array

Gets the options for a table.

Table options allow you to set platform specific table level options. For example the engine type in MySQL.

Returns

array —

An array of options.

hasAutoincrement()

hasAutoincrement() : boolean

Check whether or not a table has an autoIncrement column defined.

Returns

boolean

setTemporary()

setTemporary(boolean  $temporary) : $this

Sets whether the table is temporary in the database.

Parameters

boolean $temporary

Whether or not the table is to be temporary.

Returns

$this

isTemporary()

isTemporary() : boolean

Gets whether the table is temporary in the database.

Returns

boolean —

The current temporary setting.

primaryKey()

primaryKey() : array

Get the column(s) used for the primary key.

Returns

array —

Column name(s) for the primary key. An empty list will be returned when the table has no primary key.

addIndex()

addIndex(string  $name, array  $attrs) : $this

Add an index.

Used to add indexes, and full text indexes in platforms that support them.

Attributes

  • type The type of index being added.
  • columns The columns in the index.

Parameters

string $name

The name of the index.

array $attrs

The attributes for the index.

Returns

$this

getIndex()

getIndex(string  $name) : array|null

Read information about an index based on name.

Parameters

string $name

The name of the index.

Returns

array|null —

Array of index data, or null

indexes()

indexes() : array<mixed,string>

Get the names of all the indexes in the table.

Returns

array<mixed,string>

addConstraint()

addConstraint(string  $name, array  $attrs) : $this

Add a constraint.

Used to add constraints to a table. For example primary keys, unique keys and foreign keys.

Attributes

  • type The type of constraint being added.
  • columns The columns in the index.
  • references The table, column a foreign key references.
  • update The behavior on update. Options are 'restrict', 'setNull', 'cascade', 'noAction'.
  • delete The behavior on delete. Options are 'restrict', 'setNull', 'cascade', 'noAction'.

The default for 'update' & 'delete' is 'cascade'.

Parameters

string $name

The name of the constraint.

array $attrs

The attributes for the constraint.

Returns

$this

getConstraint()

getConstraint(string  $name) : array|null

Read information about a constraint based on name.

Parameters

string $name

The name of the constraint.

Returns

array|null —

Array of constraint data, or null

dropConstraint()

dropConstraint(string  $name) : $this

Remove a constraint.

Parameters

string $name

Name of the constraint to remove

Returns

$this

constraints()

constraints() : array<mixed,string>

Get the names of all the constraints in the table.

Returns

array<mixed,string>