Interface SchemaInterface
An interface used by TableSchema objects.
Method Summary
- 
          addColumn() publicAdd a column to the table. 
- 
          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. 
- 
          defaultValues() publicGet a hash of columns and their default values. 
- 
          getColumn() publicGet column data in the table. 
- 
          getColumnType() publicReturns column type or null if a column does not exist. 
- 
          getOptions() publicGets the options for a table. 
- 
          hasColumn() publicReturns true if a column exists in the schema. 
- 
          isNullable() publicCheck whether or not a field is nullable 
- 
          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. 
- 
          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, string|array $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 or not the column can hold nulls.
- fixedWhether or not the column is a fixed length column. This is only present/valid with string columns.
- unsignedWhether 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:
- commentThe comment for the column.
Parameters
- 
                string$name
- The name of the column 
- 
                string|array$attrs
- The attributes for the column or the type name. 
Returns
$thisbaseColumnType() ¶ 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
defaultValues() ¶ public
defaultValues(): arrayGet a hash of columns and their default values.
Returns
arraygetColumn() ¶ public
getColumn(string $name): array|nullGet column data in the table.
Parameters
- 
                string$name
- The column name. 
Returns
array|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|nullgetOptions() ¶ public
getOptions(): arrayGets the options for a table.
Table options allow you to set platform specific table level options. For example the engine type in MySQL.
Returns
arrayAn array of options.
hasColumn() ¶ public
hasColumn(string $name): boolReturns true if a column exists in the schema.
Parameters
- 
                string$name
- Column name. 
Returns
boolisNullable() ¶ public
isNullable(string $name): boolCheck whether or not a field is nullable
Missing columns are nullable.
Parameters
- 
                string$name
- The column to get the type of. 
Returns
boolWhether or not the field is nullable.
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 $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$options
- The options to set, or null to read options. 
Returns
$thistypeMap() ¶ public
typeMap(): arrayReturns an array where the keys are the column names in the schema and the values the database type they have.
Returns
array