Interface TableSchemaInterface
An interface used by database TableSchema objects.
Constants
- 
          
          stringTYPE_BIGINTEGER ¶'biginteger'Big Integer column type 
- 
          
          stringTYPE_BINARY ¶'binary'Binary column type 
- 
          
          stringTYPE_BINARY_UUID ¶'binaryuuid'Binary UUID column type 
- 
          
          stringTYPE_BOOLEAN ¶'boolean'Boolean column type 
- 
          
          stringTYPE_CHAR ¶'char'Char column type 
- 
          
          stringTYPE_DATE ¶'date'Date column type 
- 
          
          stringTYPE_DATETIME ¶'datetime'Datetime column type 
- 
          
          stringTYPE_DATETIME_FRACTIONAL ¶'datetimefractional'Datetime with fractional seconds column type 
- 
          
          stringTYPE_DECIMAL ¶'decimal'Decimal column type 
- 
          
          stringTYPE_FLOAT ¶'float'Float column type 
- 
          
          stringTYPE_INTEGER ¶'integer'Integer column type 
- 
          
          stringTYPE_JSON ¶'json'JSON column type 
- 
          
          stringTYPE_SMALLINTEGER ¶'smallinteger'Small Integer column type 
- 
          
          stringTYPE_STRING ¶'string'String column type 
- 
          
          stringTYPE_TEXT ¶'text'Text column type 
- 
          
          stringTYPE_TIME ¶'time'Time column type 
- 
          
          stringTYPE_TIMESTAMP ¶'timestamp'Timestamp column type 
- 
          
          stringTYPE_TIMESTAMP_FRACTIONAL ¶'timestampfractional'Timestamp with fractional seconds column type 
- 
          
          stringTYPE_TIMESTAMP_TIMEZONE ¶'timestamptimezone'Timestamp with time zone column type 
- 
          
          stringTYPE_TINYINTEGER ¶'tinyinteger'Tiny Integer column type 
- 
          
          stringTYPE_UUID ¶'uuid'UUID column type 
Method Summary
- 
          addColumn() publicAdd a column to the table. 
- 
          addConstraint() publicAdd a constraint. 
- 
          addIndex() publicAdd an index. 
- 
          baseColumnType() publicReturns the base type name for the provided column. This represent the database type a more complex class is based upon. 
- 
          columns() publicGet the column names in the table. 
- 
          constraints() publicGet the names of all the constraints in the table. 
- 
          defaultValues() publicGet a hash of columns and their default values. 
- 
          dropConstraint() publicRemove a constraint. 
- 
          getColumn() publicGet column data in the table. 
- 
          getColumnType() publicReturns column type or null if a column does not exist. 
- 
          getConstraint() publicRead information about a constraint based on name. 
- 
          getIndex() publicRead information about an index based on name. 
- 
          getOptions() publicGets the options for a table. 
- 
          getPrimaryKey() publicGet the column(s) used for the primary key. 
- 
          hasAutoincrement() publicCheck whether a table has an autoIncrement column defined. 
- 
          hasColumn() publicReturns true if a column exists in the schema. 
- 
          indexes() publicGet the names of all the indexes in the table. 
- 
          isNullable() publicCheck whether a field is nullable 
- 
          isTemporary() publicGets whether the table is temporary in the database. 
- 
          name() publicGet the name of the table. 
- 
          removeColumn() publicRemove a column from the table schema. 
- 
          setColumnType() publicSets the type of a column. 
- 
          setOptions() publicSets the options for a table. 
- 
          setTemporary() publicSets whether the table is temporary in the database. 
- 
          typeMap() publicReturns an array where the keys are the column names in the schema and the values the database type they have. 
Method Detail
addColumn() ¶ public
addColumn(string $name, array<string, mixed>|string $attrs): $thisAdd a column to the table.
Attributes
Columns can have several attributes:
- typeThe type of the column. This should be one of CakePHP's abstract types.
- lengthThe length of the column.
- precisionThe number of decimal places to store for float and decimal types.
- defaultThe default value of the column.
- nullWhether the column can hold nulls.
- fixedWhether the column is a fixed length column. This is only present/valid with string columns.
- unsignedWhether 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:
- commentThe comment for the column.
Parameters
- 
                string$name
- The name of the column 
- 
                array<string, mixed>|string$attrs
- The attributes for the column or the type name. 
Returns
$thisaddConstraint() ¶ public
addConstraint(string $name, array<string, mixed>|string $attrs): $thisAdd a constraint.
Used to add constraints to a table. For example primary keys, unique keys and foreign keys.
Attributes
- typeThe type of constraint being added.
- columnsThe columns in the index.
- referencesThe table, column a foreign key references.
- updateThe behavior on update. Options are 'restrict', 'setNull', 'cascade', 'noAction'.
- deleteThe 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<string, mixed>|string$attrs
- The attributes for the constraint. If string it will be used as - type.
Returns
$thisThrows
Cake\Database\Exception\DatabaseExceptionaddIndex() ¶ public
addIndex(string $name, array<string, mixed>|string $attrs): $thisAdd an index.
Used to add indexes, and full text indexes in platforms that support them.
Attributes
- typeThe type of index being added.
- columnsThe columns in the index.
Parameters
- 
                string$name
- The name of the index. 
- 
                array<string, mixed>|string$attrs
- The attributes for the index. If string it will be used as - type.
Returns
$thisThrows
Cake\Database\Exception\DatabaseExceptionbaseColumnType() ¶ public
baseColumnType(string $column): string|nullReturns 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|nullThe base type name
columns() ¶ public
columns(): array<string>Get the column names in the table.
Returns
array<string>constraints() ¶ public
constraints(): array<string>Get the names of all the constraints in the table.
Returns
array<string>defaultValues() ¶ public
defaultValues(): array<string, mixed>Get a hash of columns and their default values.
Returns
array<string, mixed>dropConstraint() ¶ public
dropConstraint(string $name): $thisRemove a constraint.
Parameters
- 
                string$name
- Name of the constraint to remove 
Returns
$thisgetColumn() ¶ public
getColumn(string $name): array<string, mixed>|nullGet column data in the table.
Parameters
- 
                string$name
- The column name. 
Returns
array<string, mixed>|nullColumn data or null.
getColumnType() ¶ public
getColumnType(string $name): string|nullReturns column type or null if a column does not exist.
Parameters
- 
                string$name
- The column to get the type of. 
Returns
string|nullgetConstraint() ¶ public
getConstraint(string $name): array<string, mixed>|nullRead information about a constraint based on name.
Parameters
- 
                string$name
- The name of the constraint. 
Returns
array<string, mixed>|nullArray of constraint data, or null
getIndex() ¶ public
getIndex(string $name): array<string, mixed>|nullRead information about an index based on name.
Parameters
- 
                string$name
- The name of the index. 
Returns
array<string, mixed>|nullArray of index data, or null
getOptions() ¶ public
getOptions(): array<string, mixed>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<string, mixed>An array of options.
getPrimaryKey() ¶ public
getPrimaryKey(): array<string>Get the column(s) used for the primary key.
Returns
array<string>Column name(s) for the primary key. An empty list will be returned when the table has no primary key.
hasAutoincrement() ¶ public
hasAutoincrement(): boolCheck whether a table has an autoIncrement column defined.
Returns
boolhasColumn() ¶ public
hasColumn(string $name): boolReturns true if a column exists in the schema.
Parameters
- 
                string$name
- Column name. 
Returns
boolindexes() ¶ public
indexes(): array<string>Get the names of all the indexes in the table.
Returns
array<string>isNullable() ¶ public
isNullable(string $name): boolCheck whether a field is nullable
Missing columns are nullable.
Parameters
- 
                string$name
- The column to get the type of. 
Returns
boolWhether the field is nullable.
isTemporary() ¶ public
isTemporary(): boolGets whether the table is temporary in the database.
Returns
boolThe current temporary setting.
removeColumn() ¶ public
removeColumn(string $name): $thisRemove 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
$thissetColumnType() ¶ public
setColumnType(string $name, string $type): $thisSets 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
$thissetOptions() ¶ public
setOptions(array<string, mixed> $options): $thisSets 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<string, mixed>$options
- The options to set, or null to read options. 
Returns
$thissetTemporary() ¶ public
setTemporary(bool $temporary): $thisSets whether the table is temporary in the database.
Parameters
- 
                bool$temporary
- Whether the table is to be temporary. 
Returns
$thistypeMap() ¶ public
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.
Returns
array<string, string>