Constants

LENGTH_TINY

LENGTH_TINY = 255 : integer

Column length when using a `tiny` column type

LENGTH_MEDIUM

LENGTH_MEDIUM = 16777215 : integer

Column length when using a `medium` column type

LENGTH_LONG

LENGTH_LONG = 4294967295 : integer

Column length when using a `long` column type

CONSTRAINT_PRIMARY

CONSTRAINT_PRIMARY = 'primary' : string

Primary constraint type

CONSTRAINT_UNIQUE

CONSTRAINT_UNIQUE = 'unique' : string

Unique constraint type

CONSTRAINT_FOREIGN

CONSTRAINT_FOREIGN = 'foreign' : string

Foreign constraint type

INDEX_INDEX

INDEX_INDEX = 'index' : string

Index - index type

INDEX_FULLTEXT

INDEX_FULLTEXT = 'fulltext' : string

Fulltext index type

ACTION_CASCADE

ACTION_CASCADE = 'cascade' : string

Foreign key cascade action

ACTION_SET_NULL

ACTION_SET_NULL = 'setNull' : string

Foreign key set null action

ACTION_NO_ACTION

ACTION_NO_ACTION = 'noAction' : string

Foreign key no action

ACTION_RESTRICT

ACTION_RESTRICT = 'restrict' : string

Foreign key restrict action

ACTION_SET_DEFAULT

ACTION_SET_DEFAULT = 'setDefault' : string

Foreign key restrict default

Properties

$columnLengths

$columnLengths : array

Valid column length that can be used with text type columns

Type

array

$_table

$_table : string

The name of the table

Type

string

$_columns

$_columns : array

Columns in the table.

Type

array

$_typeMap

$_typeMap : array

A map with columns to types

Type

array

$_indexes

$_indexes : array

Indexes in the table.

Type

array

$_constraints

$_constraints : array

Constraints in the table.

Type

array

$_options

$_options : array

Options for the table.

Type

array

$_temporary

$_temporary : boolean

Whether or not the table is temporary

Type

boolean

$_columnKeys

$_columnKeys : array

The valid keys that can be used in a column definition.

Type

array

$_columnExtras

$_columnExtras : array

Additional type specific properties.

Type

array

$_indexKeys

$_indexKeys : array

The valid keys that can be used in an index definition.

Type

array

$_validIndexTypes

$_validIndexTypes : array

Names of the valid index types.

Type

array

$_validConstraintTypes

$_validConstraintTypes : array

Names of the valid constraint types.

Type

array

$_validForeignKeyActions

$_validForeignKeyActions : array

Names of the valid foreign key actions.

Type

array

Methods

__construct()

__construct(string  $table, array  $columns = array()) 

Constructor.

Parameters

string $table

The table name.

array $columns

The list of columns for the schema.

name()

name() 

{@inheritDoc}

addColumn()

addColumn(  $name,   $attrs) 

{@inheritDoc}

Parameters

$name
$attrs

removeColumn()

removeColumn(  $name) 

{@inheritDoc}

Parameters

$name

columns()

columns() 

{@inheritDoc}

column()

column(string  $name) : array|null

Get column data in the table.

Parameters

string $name

The column name.

Returns

array|null —

Column data or null.

getColumn()

getColumn(  $name) 

{@inheritDoc}

Parameters

$name

columnType()

columnType(string  $name, string|null  $type = null) : string|null

Sets the type of a column, or returns its current type if none is passed.

Parameters

string $name

The column to get the type of.

string|null $type

The type to set the column to.

Returns

string|null —

Either the column type or null.

getColumnType()

getColumnType(  $name) 

{@inheritDoc}

Parameters

$name

setColumnType()

setColumnType(  $name,   $type) 

{@inheritDoc}

Parameters

$name
$type

hasColumn()

hasColumn(  $name) 

{@inheritDoc}

Parameters

$name

baseColumnType()

baseColumnType(  $column) 

{@inheritDoc}

Parameters

$column

typeMap()

typeMap() 

{@inheritDoc}

isNullable()

isNullable(  $name) 

{@inheritDoc}

Parameters

$name

defaultValues()

defaultValues() 

{@inheritDoc}

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.

Throws

\Cake\Database\Exception

Returns

$this

indexes()

indexes() : array<mixed,string>

Get the names of all the indexes in the table.

Returns

array<mixed,string>

index()

index(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

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

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.

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.

Throws

\Cake\Database\Exception

Returns

$this

dropConstraint()

dropConstraint(string  $name) : $this

Remove a constraint.

Parameters

string $name

Name of the constraint to remove

Returns

$this

hasAutoincrement()

hasAutoincrement() : boolean

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

Returns

boolean

constraints()

constraints() : array<mixed,string>

Get the names of all the constraints in the table.

Returns

array<mixed,string>

constraint()

constraint(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

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

setOptions()

setOptions(  $options) 

{@inheritDoc}

Parameters

$options

getOptions()

getOptions() 

{@inheritDoc}

options()

options(array|null  $options = null) : $this|array

Get/set 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|null $options

The options to set, or null to read options.

Returns

$this|array —

Either the TableSchema instance, or an array of options when reading.

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.

temporary()

temporary(boolean|null  $temporary = null) : $this|boolean

Get/Set whether the table is temporary in the database

Parameters

boolean|null $temporary

whether or not the table is to be temporary

Returns

$this|boolean —

Either the TableSchema instance, the current temporary setting

createSql()

createSql(\Cake\Database\Connection  $connection) : array

Generate the SQL to create the Table.

Uses the connection to access the schema dialect to generate platform specific SQL.

Parameters

\Cake\Database\Connection $connection

The connection to generate SQL for.

Returns

array —

List of SQL statements to create the table and the required indexes.

dropSql()

dropSql(\Cake\Database\Connection  $connection) : array

Generate the SQL to drop a table.

Uses the connection to access the schema dialect to generate platform specific SQL.

Parameters

\Cake\Database\Connection $connection

The connection to generate SQL for.

Returns

array —

SQL to drop a table.

truncateSql()

truncateSql(\Cake\Database\Connection  $connection) : array

Generate the SQL statements to truncate a table

Parameters

\Cake\Database\Connection $connection

The connection to generate SQL for.

Returns

array —

SQL to truncate a table.

addConstraintSql()

addConstraintSql(\Cake\Database\Connection  $connection) : array

Generate the SQL statements to add the constraints to the table

Parameters

\Cake\Database\Connection $connection

The connection to generate SQL for.

Returns

array —

SQL to add the constraints.

dropConstraintSql()

dropConstraintSql(\Cake\Database\Connection  $connection) : array

Generate the SQL statements to drop the constraints to the table

Parameters

\Cake\Database\Connection $connection

The connection to generate SQL for.

Returns

array —

SQL to drop a table.

__debugInfo()

__debugInfo() : array

Returns an array of the table schema.

Returns

array

_checkForeignKey()

_checkForeignKey(array  $attrs) : array

Helper method to check/validate foreign keys.

Parameters

array $attrs

Attributes to set.

Throws

\Cake\Database\Exception

When foreign key definition is not valid.

Returns

array