PHP Trait yii\db\SchemaBuilderTrait

These can be used in database migrations to define database schema types using a PHP interface. This is useful to define a schema in a DBMS independent way so that the application may run on different DBMS the same way. For example you may use the following code inside your migration files: php $this->createTable('example_table', [ 'id' => $this->primaryKey(), 'name' => $this->string(64)->notNull(), 'type' => $this->integer()->notNull()->defaultValue(10), 'description' => $this->text(), 'rule_name' => $this->string(64), 'data' => $this->text(), 'created_at' => $this->datetime()->notNull(), 'updated_at' => $this->datetime(), ]);
Since: 2.0.6
Author: Vasenin Matvey ([email protected])
Show file Open project: yiisoft/yii2

Public Methods

Method Description
bigInteger ( integer $length = null ) : ColumnSchemaBuilder Creates a bigint column.
bigPrimaryKey ( integer $length = null ) : ColumnSchemaBuilder Creates a big primary key column.
binary ( integer $length = null ) : ColumnSchemaBuilder Creates a binary column.
boolean ( ) : ColumnSchemaBuilder Creates a boolean column.
char ( integer $length = null ) : ColumnSchemaBuilder Creates a char column.
date ( ) : ColumnSchemaBuilder Creates a date column.
dateTime ( integer $precision = null ) : ColumnSchemaBuilder Creates a datetime column.
decimal ( integer $precision = null, integer $scale = null ) : ColumnSchemaBuilder Creates a decimal column.
double ( integer $precision = null ) : ColumnSchemaBuilder Creates a double column.
float ( integer $precision = null ) : ColumnSchemaBuilder Creates a float column.
integer ( integer $length = null ) : ColumnSchemaBuilder Creates an integer column.
money ( integer $precision = null, integer $scale = null ) : ColumnSchemaBuilder Creates a money column.
primaryKey ( integer $length = null ) : ColumnSchemaBuilder Creates a primary key column.
smallInteger ( integer $length = null ) : ColumnSchemaBuilder Creates a smallint column.
string ( integer $length = null ) : ColumnSchemaBuilder Creates a string column.
text ( ) : ColumnSchemaBuilder Creates a text column.
time ( integer $precision = null ) : ColumnSchemaBuilder Creates a time column.
timestamp ( integer $precision = null ) : ColumnSchemaBuilder Creates a timestamp column.

Protected Methods

Method Description
getDb ( ) : Connection

Method Details

bigInteger() public method

Creates a bigint column.
Since: 2.0.6
public bigInteger ( integer $length = null ) : ColumnSchemaBuilder
$length integer column size or precision definition. This parameter will be ignored if not supported by the DBMS.
return ColumnSchemaBuilder the column instance which can be further customized.

bigPrimaryKey() public method

Creates a big primary key column.
Since: 2.0.6
public bigPrimaryKey ( integer $length = null ) : ColumnSchemaBuilder
$length integer column size or precision definition. This parameter will be ignored if not supported by the DBMS.
return ColumnSchemaBuilder the column instance which can be further customized.

binary() public method

Creates a binary column.
Since: 2.0.6
public binary ( integer $length = null ) : ColumnSchemaBuilder
$length integer column size or precision definition. This parameter will be ignored if not supported by the DBMS.
return ColumnSchemaBuilder the column instance which can be further customized.

boolean() public method

Creates a boolean column.
Since: 2.0.6
public boolean ( ) : ColumnSchemaBuilder
return ColumnSchemaBuilder the column instance which can be further customized.

char() public method

Creates a char column.
Since: 2.0.8
public char ( integer $length = null ) : ColumnSchemaBuilder
$length integer column size definition i.e. the maximum string length. This parameter will be ignored if not supported by the DBMS.
return ColumnSchemaBuilder the column instance which can be further customized.

date() public method

Creates a date column.
Since: 2.0.6
public date ( ) : ColumnSchemaBuilder
return ColumnSchemaBuilder the column instance which can be further customized.

dateTime() public method

Creates a datetime column.
Since: 2.0.6
public dateTime ( integer $precision = null ) : ColumnSchemaBuilder
$precision integer column value precision. First parameter passed to the column type, e.g. DATETIME(precision). This parameter will be ignored if not supported by the DBMS.
return ColumnSchemaBuilder the column instance which can be further customized.

decimal() public method

Creates a decimal column.
Since: 2.0.6
public decimal ( integer $precision = null, integer $scale = null ) : ColumnSchemaBuilder
$precision integer column value precision, which is usually the total number of digits. First parameter passed to the column type, e.g. DECIMAL(precision, scale). This parameter will be ignored if not supported by the DBMS.
$scale integer column value scale, which is usually the number of digits after the decimal point. Second parameter passed to the column type, e.g. DECIMAL(precision, scale). This parameter will be ignored if not supported by the DBMS.
return ColumnSchemaBuilder the column instance which can be further customized.

double() public method

Creates a double column.
Since: 2.0.6
public double ( integer $precision = null ) : ColumnSchemaBuilder
$precision integer column value precision. First parameter passed to the column type, e.g. DOUBLE(precision). This parameter will be ignored if not supported by the DBMS.
return ColumnSchemaBuilder the column instance which can be further customized.

float() public method

Creates a float column.
Since: 2.0.6
public float ( integer $precision = null ) : ColumnSchemaBuilder
$precision integer column value precision. First parameter passed to the column type, e.g. FLOAT(precision). This parameter will be ignored if not supported by the DBMS.
return ColumnSchemaBuilder the column instance which can be further customized.

getDb() abstract protected method

abstract protected getDb ( ) : Connection
return Connection the database connection to be used for schema building.

integer() public method

Creates an integer column.
Since: 2.0.6
public integer ( integer $length = null ) : ColumnSchemaBuilder
$length integer column size or precision definition. This parameter will be ignored if not supported by the DBMS.
return ColumnSchemaBuilder the column instance which can be further customized.

money() public method

Creates a money column.
Since: 2.0.6
public money ( integer $precision = null, integer $scale = null ) : ColumnSchemaBuilder
$precision integer column value precision, which is usually the total number of digits. First parameter passed to the column type, e.g. DECIMAL(precision, scale). This parameter will be ignored if not supported by the DBMS.
$scale integer column value scale, which is usually the number of digits after the decimal point. Second parameter passed to the column type, e.g. DECIMAL(precision, scale). This parameter will be ignored if not supported by the DBMS.
return ColumnSchemaBuilder the column instance which can be further customized.

primaryKey() public method

Creates a primary key column.
Since: 2.0.6
public primaryKey ( integer $length = null ) : ColumnSchemaBuilder
$length integer column size or precision definition. This parameter will be ignored if not supported by the DBMS.
return ColumnSchemaBuilder the column instance which can be further customized.

smallInteger() public method

Creates a smallint column.
Since: 2.0.6
public smallInteger ( integer $length = null ) : ColumnSchemaBuilder
$length integer column size or precision definition. This parameter will be ignored if not supported by the DBMS.
return ColumnSchemaBuilder the column instance which can be further customized.

string() public method

Creates a string column.
Since: 2.0.6
public string ( integer $length = null ) : ColumnSchemaBuilder
$length integer column size definition i.e. the maximum string length. This parameter will be ignored if not supported by the DBMS.
return ColumnSchemaBuilder the column instance which can be further customized.

text() public method

Creates a text column.
Since: 2.0.6
public text ( ) : ColumnSchemaBuilder
return ColumnSchemaBuilder the column instance which can be further customized.

time() public method

Creates a time column.
Since: 2.0.6
public time ( integer $precision = null ) : ColumnSchemaBuilder
$precision integer column value precision. First parameter passed to the column type, e.g. TIME(precision). This parameter will be ignored if not supported by the DBMS.
return ColumnSchemaBuilder the column instance which can be further customized.

timestamp() public method

Creates a timestamp column.
Since: 2.0.6
public timestamp ( integer $precision = null ) : ColumnSchemaBuilder
$precision integer column value precision. First parameter passed to the column type, e.g. TIMESTAMP(precision). This parameter will be ignored if not supported by the DBMS.
return ColumnSchemaBuilder the column instance which can be further customized.