On this page
Trait yii\db\SchemaBuilderTrait
Implemented by | yii\db\Migration |
---|---|
Available since version | 2.0.6 |
Source Code | https://github.com/yiisoft/yii2/blob/master/framework/db/SchemaBuilderTrait.php |
SchemaBuilderTrait contains shortcut methods to create instances of yii\db\ColumnSchemaBuilder.
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:
$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(),
]);
Public Methods
Protected Methods
Method | Description | Defined By |
---|---|---|
getDb() | yii\db\SchemaBuilderTrait |
Method Details
bigInteger() public method (available since version 2.0.6)
Creates a bigint column.
public yii\db\ColumnSchemaBuilder bigInteger ( $length = null ) | ||
---|---|---|
$length | integer | Column size or precision definition. This parameter will be ignored if not supported by the DBMS. |
return | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
bigPrimaryKey() public method (available since version 2.0.6)
Creates a big primary key column.
public yii\db\ColumnSchemaBuilder bigPrimaryKey ( $length = null ) | ||
---|---|---|
$length | integer | Column size or precision definition. This parameter will be ignored if not supported by the DBMS. |
return | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
binary() public method (available since version 2.0.6)
Creates a binary column.
public yii\db\ColumnSchemaBuilder binary ( $length = null ) | ||
---|---|---|
$length | integer | Column size or precision definition. This parameter will be ignored if not supported by the DBMS. |
return | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
boolean() public method (available since version 2.0.6)
Creates a boolean column.
public yii\db\ColumnSchemaBuilder boolean ( ) | ||
---|---|---|
return | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
char() public method (available since version 2.0.8)
Creates a char column.
public yii\db\ColumnSchemaBuilder char ( $length = null ) | ||
---|---|---|
$length | integer | Column size definition i.e. the maximum string length. This parameter will be ignored if not supported by the DBMS. |
return | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
date() public method (available since version 2.0.6)
Creates a date column.
public yii\db\ColumnSchemaBuilder date ( ) | ||
---|---|---|
return | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
dateTime() public method (available since version 2.0.6)
Creates a datetime column.
public yii\db\ColumnSchemaBuilder dateTime ( $precision = null ) | ||
---|---|---|
$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 | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
decimal() public method (available since version 2.0.6)
Creates a decimal column.
public yii\db\ColumnSchemaBuilder decimal ( $precision = null, $scale = null ) | ||
---|---|---|
$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 | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
double() public method (available since version 2.0.6)
Creates a double column.
public yii\db\ColumnSchemaBuilder double ( $precision = null ) | ||
---|---|---|
$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 | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
float() public method (available since version 2.0.6)
Creates a float column.
public yii\db\ColumnSchemaBuilder float ( $precision = null ) | ||
---|---|---|
$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 | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
getDb() protected abstract method
protected abstract yii\db\Connection getDb ( ) | ||
---|---|---|
return | yii\db\Connection | The database connection to be used for schema building. |
integer() public method (available since version 2.0.6)
Creates an integer column.
public yii\db\ColumnSchemaBuilder integer ( $length = null ) | ||
---|---|---|
$length | integer | Column size or precision definition. This parameter will be ignored if not supported by the DBMS. |
return | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
money() public method (available since version 2.0.6)
Creates a money column.
public yii\db\ColumnSchemaBuilder money ( $precision = null, $scale = null ) | ||
---|---|---|
$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 | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
primaryKey() public method (available since version 2.0.6)
Creates a primary key column.
public yii\db\ColumnSchemaBuilder primaryKey ( $length = null ) | ||
---|---|---|
$length | integer | Column size or precision definition. This parameter will be ignored if not supported by the DBMS. |
return | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
smallInteger() public method (available since version 2.0.6)
Creates a smallint column.
public yii\db\ColumnSchemaBuilder smallInteger ( $length = null ) | ||
---|---|---|
$length | integer | Column size or precision definition. This parameter will be ignored if not supported by the DBMS. |
return | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
string() public method (available since version 2.0.6)
Creates a string column.
public yii\db\ColumnSchemaBuilder string ( $length = null ) | ||
---|---|---|
$length | integer | Column size definition i.e. the maximum string length. This parameter will be ignored if not supported by the DBMS. |
return | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
text() public method (available since version 2.0.6)
Creates a text column.
public yii\db\ColumnSchemaBuilder text ( ) | ||
---|---|---|
return | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
time() public method (available since version 2.0.6)
Creates a time column.
public yii\db\ColumnSchemaBuilder time ( $precision = null ) | ||
---|---|---|
$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 | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
timestamp() public method (available since version 2.0.6)
Creates a timestamp column.
public yii\db\ColumnSchemaBuilder timestamp ( $precision = null ) | ||
---|---|---|
$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 | yii\db\ColumnSchemaBuilder | The column instance which can be further customized. |
© 2008–2017 by Yii Software LLC
Licensed under the three clause BSD license.
http://www.yiiframework.com/doc-2.0/yii-db-schemabuildertrait.html