TableSchemaInterface
extends
SchemaInterface
in
An interface used by database TableSchema objects.
Table of Contents
Constants
- TYPE_BIGINTEGER = 'biginteger'
- Big Integer column type
- TYPE_BINARY = 'binary'
- Binary column type
- TYPE_BINARY_UUID = 'binaryuuid'
- Binary UUID column type
- TYPE_BOOLEAN = 'boolean'
- Boolean column type
- TYPE_CHAR = 'char'
- Char column type
- TYPE_DATE = 'date'
- Date column type
- TYPE_DATETIME = 'datetime'
- Datetime column type
- TYPE_DATETIME_FRACTIONAL = 'datetimefractional'
- Datetime with fractional seconds column type
- TYPE_DECIMAL = 'decimal'
- Decimal column type
- TYPE_FLOAT = 'float'
- Float column type
- TYPE_INTEGER = 'integer'
- Integer column type
- TYPE_JSON = 'json'
- JSON column type
- TYPE_SMALLINTEGER = 'smallinteger'
- Small Integer column type
- TYPE_STRING = 'string'
- String column type
- TYPE_TEXT = 'text'
- Text column type
- TYPE_TIME = 'time'
- Time column type
- TYPE_TIMESTAMP = 'timestamp'
- Timestamp column type
- TYPE_TIMESTAMP_FRACTIONAL = 'timestampfractional'
- Timestamp with fractional seconds column type
- TYPE_TIMESTAMP_TIMEZONE = 'timestamptimezone'
- Timestamp with time zone column type
- TYPE_TINYINTEGER = 'tinyinteger'
- Tiny Integer column type
- TYPE_UUID = 'uuid'
- UUID column type
Methods
- addColumn() : $this
- Add a column to the table.
- addConstraint() : $this
- Add a constraint.
- addIndex() : $this
- Add an index.
- baseColumnType() : string|null
- Returns the base type name for the provided column.
- columns() : array<string|int, string>
- Get the column names in the table.
- constraints() : array<string|int, string>
- Get the names of all the constraints in the table.
- defaultValues() : array<string, mixed>
- Get a hash of columns and their default values.
- dropConstraint() : $this
- Remove a constraint.
- getColumn() : array<string, mixed>|null
- Get column data in the table.
- getColumnType() : string|null
- Returns column type or null if a column does not exist.
- getConstraint() : array<string, mixed>|null
- Read information about a constraint based on name.
- getIndex() : array<string, mixed>|null
- Read information about an index based on name.
- getOptions() : array<string, mixed>
- Gets the options for a table.
- getPrimaryKey() : array<string|int, string>
- Get the column(s) used for the primary key.
- hasAutoincrement() : bool
- Check whether a table has an autoIncrement column defined.
- hasColumn() : bool
- Returns true if a column exists in the schema.
- indexes() : array<string|int, string>
- Get the names of all the indexes in the table.
- isNullable() : bool
- Check whether a field is nullable
- isTemporary() : bool
- Gets whether the table is temporary in the database.
- name() : string
- Get the name of the table.
- removeColumn() : $this
- Remove a column from the table schema.
- setColumnType() : $this
- Sets the type of a column.
- setOptions() : $this
- Sets the options for a table.
- setTemporary() : $this
- Sets whether the table is temporary in the database.
- typeMap() : array<string, string>
- Returns an array where the keys are the column names in the schema and the values the database type they have.
Constants
TYPE_BIGINTEGER
Big Integer column type
public
string
TYPE_BIGINTEGER
= 'biginteger'
TYPE_BINARY
Binary column type
public
string
TYPE_BINARY
= 'binary'
TYPE_BINARY_UUID
Binary UUID column type
public
string
TYPE_BINARY_UUID
= 'binaryuuid'
TYPE_BOOLEAN
Boolean column type
public
string
TYPE_BOOLEAN
= 'boolean'
TYPE_CHAR
Char column type
public
string
TYPE_CHAR
= 'char'
TYPE_DATE
Date column type
public
string
TYPE_DATE
= 'date'
TYPE_DATETIME
Datetime column type
public
string
TYPE_DATETIME
= 'datetime'
TYPE_DATETIME_FRACTIONAL
Datetime with fractional seconds column type
public
string
TYPE_DATETIME_FRACTIONAL
= 'datetimefractional'
TYPE_DECIMAL
Decimal column type
public
string
TYPE_DECIMAL
= 'decimal'
TYPE_FLOAT
Float column type
public
string
TYPE_FLOAT
= 'float'
TYPE_INTEGER
Integer column type
public
string
TYPE_INTEGER
= 'integer'
TYPE_JSON
JSON column type
public
string
TYPE_JSON
= 'json'
TYPE_SMALLINTEGER
Small Integer column type
public
string
TYPE_SMALLINTEGER
= 'smallinteger'
TYPE_STRING
String column type
public
string
TYPE_STRING
= 'string'
TYPE_TEXT
Text column type
public
string
TYPE_TEXT
= 'text'
TYPE_TIME
Time column type
public
string
TYPE_TIME
= 'time'
TYPE_TIMESTAMP
Timestamp column type
public
string
TYPE_TIMESTAMP
= 'timestamp'
TYPE_TIMESTAMP_FRACTIONAL
Timestamp with fractional seconds column type
public
string
TYPE_TIMESTAMP_FRACTIONAL
= 'timestampfractional'
TYPE_TIMESTAMP_TIMEZONE
Timestamp with time zone column type
public
string
TYPE_TIMESTAMP_TIMEZONE
= 'timestamptimezone'
TYPE_TINYINTEGER
Tiny Integer column type
public
string
TYPE_TINYINTEGER
= 'tinyinteger'
TYPE_UUID
UUID column type
public
string
TYPE_UUID
= 'uuid'
Methods
addColumn()
Add a column to the table.
public
addColumn(string $name, array<string, mixed>|string $attrs) : $this
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 the column can hold nulls. -
fixed
Whether the column is a fixed length column. This is only present/valid with string columns. -
unsigned
Whether 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
- $name : string
-
The name of the column
- $attrs : array<string, mixed>|string
-
The attributes for the column or the type name.
Return values
$thisaddConstraint()
Add a constraint.
public
addConstraint(string $name, array<string, mixed>|string $attrs) : $this
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
- $name : string
-
The name of the constraint.
- $attrs : array<string, mixed>|string
-
The attributes for the constraint. If string it will be used as
type
.
Tags
Return values
$thisaddIndex()
Add an index.
public
addIndex(string $name, array<string, mixed>|string $attrs) : $this
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
- $name : string
-
The name of the index.
- $attrs : array<string, mixed>|string
-
The attributes for the index. If string it will be used as
type
.
Tags
Return values
$thisbaseColumnType()
Returns the base type name for the provided column.
public
baseColumnType(string $column) : string|null
This represent the database type a more complex class is based upon.
Parameters
- $column : string
-
The column name to get the base type from
Return values
string|null —The base type name
columns()
Get the column names in the table.
public
columns() : array<string|int, string>
Return values
array<string|int, string>constraints()
Get the names of all the constraints in the table.
public
constraints() : array<string|int, string>
Return values
array<string|int, string>defaultValues()
Get a hash of columns and their default values.
public
defaultValues() : array<string, mixed>
Return values
array<string, mixed>dropConstraint()
Remove a constraint.
public
dropConstraint(string $name) : $this
Parameters
- $name : string
-
Name of the constraint to remove
Return values
$thisgetColumn()
Get column data in the table.
public
getColumn(string $name) : array<string, mixed>|null
Parameters
- $name : string
-
The column name.
Return values
array<string, mixed>|null —Column data or null.
getColumnType()
Returns column type or null if a column does not exist.
public
getColumnType(string $name) : string|null
Parameters
- $name : string
-
The column to get the type of.
Return values
string|nullgetConstraint()
Read information about a constraint based on name.
public
getConstraint(string $name) : array<string, mixed>|null
Parameters
- $name : string
-
The name of the constraint.
Return values
array<string, mixed>|null —Array of constraint data, or null
getIndex()
Read information about an index based on name.
public
getIndex(string $name) : array<string, mixed>|null
Parameters
- $name : string
-
The name of the index.
Return values
array<string, mixed>|null —Array of index data, or null
getOptions()
Gets the options for a table.
public
getOptions() : array<string, mixed>
Table options allow you to set platform specific table level options. For example the engine type in MySQL.
Return values
array<string, mixed> —An array of options.
getPrimaryKey()
Get the column(s) used for the primary key.
public
getPrimaryKey() : array<string|int, string>
Return values
array<string|int, string> —Column name(s) for the primary key. An empty list will be returned when the table has no primary key.
hasAutoincrement()
Check whether a table has an autoIncrement column defined.
public
hasAutoincrement() : bool
Return values
boolhasColumn()
Returns true if a column exists in the schema.
public
hasColumn(string $name) : bool
Parameters
- $name : string
-
Column name.
Return values
boolindexes()
Get the names of all the indexes in the table.
public
indexes() : array<string|int, string>
Return values
array<string|int, string>isNullable()
Check whether a field is nullable
public
isNullable(string $name) : bool
Missing columns are nullable.
Parameters
- $name : string
-
The column to get the type of.
Return values
bool —Whether the field is nullable.
isTemporary()
Gets whether the table is temporary in the database.
public
isTemporary() : bool
Return values
bool —The current temporary setting.
name()
Get the name of the table.
public
name() : string
Return values
stringremoveColumn()
Remove a column from the table schema.
public
removeColumn(string $name) : $this
If the column is not defined in the table, no error will be raised.
Parameters
- $name : string
-
The name of the column
Return values
$thissetColumnType()
Sets the type of a column.
public
setColumnType(string $name, string $type) : $this
Parameters
- $name : string
-
The column to set the type of.
- $type : string
-
The type to set the column to.
Return values
$thissetOptions()
Sets the options for a table.
public
setOptions(array<string, mixed> $options) : $this
Table options allow you to set platform specific table level options. For example the engine type in MySQL.
Parameters
- $options : array<string, mixed>
-
The options to set, or null to read options.
Return values
$thissetTemporary()
Sets whether the table is temporary in the database.
public
setTemporary(bool $temporary) : $this
Parameters
- $temporary : bool
-
Whether the table is to be temporary.
Return values
$thistypeMap()
Returns an array where the keys are the column names in the schema and the values the database type they have.
public
typeMap() : array<string, string>