PHP Класс yii\console\controllers\MigrateController

A migration means a set of persistent changes to the application environment that is shared among different developers. For example, in an application backed by a database, a migration may refer to a set of changes to the database, such as creating a new table, adding a new table column. This command provides support for tracking the migration history, upgrading or downloading with migrations, and creating new migration skeletons. The migration history is stored in a database table named as [[migrationTable]]. The table will be automatically created the first time this command is executed, if it does not exist. You may also manually create it as follows: ~~~ CREATE TABLE migration ( version varchar(180) PRIMARY KEY, apply_time integer ) ~~~ Below are some common usages of this command: ~~~ # creates a new migration named 'create_user_table' yii migrate/create create_user_table # applies ALL new migrations yii migrate # reverts the last applied migration yii migrate/down ~~~
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends BaseMigrateController
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$db the DB connection object or the application component ID of the DB connection to use when applying migrations. Starting from version 2.0.3, this can also be a configuration array for creating the object.
$fields column definition strings used for creating migration code. The format of each definition is COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR. Delimiter is ,. For example, --fields="name:string(12):notNull:unique" produces a string column of size 12 which is not null and unique values. Note: primary key is added automatically and is named id by default. If you want to use another name you may specify it explicitly like --fields="id_key:primaryKey,name:string(12):notNull:unique"
$generatorTemplateFiles a set of template paths for generating migration code automatically. The key is the template type, the value is a path or the alias. Supported types are: - create_table: table creating template - drop_table: table dropping template - add_column: adding new column template - drop_column: dropping column template - create_junction: create junction template
$migrationTable the name of the table for keeping applied migration information.
$templateFile
$useTablePrefix indicates whether the table names generated should consider the tablePrefix setting of the DB connection. For example, if the table name is post the generator wil return {{%post}}.

Открытые методы

Метод Описание
beforeAction ( Action $action ) : boolean This method is invoked right before an action is to be executed (after all possible filters.) It checks the existence of the [[migrationPath]].
optionAliases ( )
options ( $actionID )

Защищенные методы

Метод Описание
addDefaultPrimaryKey ( array &$fields ) Adds default primary key to fields list if there's no primary key specified
addMigrationHistory ( $version )
createMigration ( string $class ) : Migration Creates a new migration instance.
createMigrationHistoryTable ( ) Creates the migration history table.
generateMigrationSourceCode ( $params )
generateTableName ( string $tableName ) : string If useTablePrefix equals true, then the table name will contain the prefix format.
getMigrationHistory ( $limit )
parseFields ( ) : array Parse the command line migration fields
removeMigrationHistory ( $version )

Описание методов

addDefaultPrimaryKey() защищенный Метод

Adds default primary key to fields list if there's no primary key specified
С версии: 2.0.7
protected addDefaultPrimaryKey ( array &$fields )
$fields array parsed fields

addMigrationHistory() защищенный Метод

protected addMigrationHistory ( $version )

beforeAction() публичный Метод

This method is invoked right before an action is to be executed (after all possible filters.) It checks the existence of the [[migrationPath]].
public beforeAction ( Action $action ) : boolean
$action yii\base\Action the action to be executed.
Результат boolean whether the action should continue to be executed.

createMigration() защищенный Метод

Creates a new migration instance.
protected createMigration ( string $class ) : Migration
$class string the migration class name
Результат yii\db\Migration the migration instance

createMigrationHistoryTable() защищенный Метод

Creates the migration history table.

generateMigrationSourceCode() защищенный Метод

С версии: 2.0.8
protected generateMigrationSourceCode ( $params )

generateTableName() защищенный Метод

If useTablePrefix equals true, then the table name will contain the prefix format.
С версии: 2.0.8
protected generateTableName ( string $tableName ) : string
$tableName string the table name to generate.
Результат string

getMigrationHistory() защищенный Метод

protected getMigrationHistory ( $limit )

optionAliases() публичный Метод

С версии: 2.0.8
public optionAliases ( )

options() публичный Метод

public options ( $actionID )

parseFields() защищенный Метод

Parse the command line migration fields
С версии: 2.0.7
protected parseFields ( ) : array
Результат array parse result with following fields: - fields: array, parsed fields - foreignKeys: array, detected foreign keys

removeMigrationHistory() защищенный Метод

protected removeMigrationHistory ( $version )

Описание свойств

$db публичное свойство

the DB connection object or the application component ID of the DB connection to use when applying migrations. Starting from version 2.0.3, this can also be a configuration array for creating the object.
public $db

$fields публичное свойство

column definition strings used for creating migration code. The format of each definition is COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR. Delimiter is ,. For example, --fields="name:string(12):notNull:unique" produces a string column of size 12 which is not null and unique values. Note: primary key is added automatically and is named id by default. If you want to use another name you may specify it explicitly like --fields="id_key:primaryKey,name:string(12):notNull:unique"
С версии: 2.0.7
public $fields

$generatorTemplateFiles публичное свойство

a set of template paths for generating migration code automatically. The key is the template type, the value is a path or the alias. Supported types are: - create_table: table creating template - drop_table: table dropping template - add_column: adding new column template - drop_column: dropping column template - create_junction: create junction template
С версии: 2.0.7
public $generatorTemplateFiles

$migrationTable публичное свойство

the name of the table for keeping applied migration information.
public $migrationTable

$templateFile публичное свойство

public $templateFile

$useTablePrefix публичное свойство

indicates whether the table names generated should consider the tablePrefix setting of the DB connection. For example, if the table name is post the generator wil return {{%post}}.
С версии: 2.0.8
public $useTablePrefix