PHP 클래스 yii\console\controllers\BaseMigrateController

부터: 2.0
저자: Qiang Xue ([email protected])
상속: extends yii\console\Controller
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$defaultAction the default command action.
$migrationNamespaces list of namespaces containing the migration classes. Migration namespaces should be resolvable as a path alias if prefixed with @, e.g. if you specify the namespace app\migrations, the code Yii::getAlias('@app/migrations') should be able to return the file path to the directory this namespace refers to. For example: php [ 'app\migrations', 'some\extension\migrations', ]
$migrationPath the directory containing the migration classes. This can be either a path alias or a directory path. If you have set up [[migrationNamespaces]], you may set this field to null in order to disable usage of migrations that are not namespaced.
$templateFile the template file for generating new migrations. This can be either a path alias (e.g. "@app/migrations/template.php") or a file path.

공개 메소드들

메소드 설명
actionCreate ( string $name ) Creates a new migration.
actionDown ( integer $limit = 1 ) : integer Downgrades the application by reverting old migrations.
actionHistory ( integer $limit = 10 ) Displays the migration history.
actionMark ( string $version ) : integer Modifies the migration history to the specified version.
actionNew ( integer $limit = 10 ) Displays the un-applied new migrations.
actionRedo ( integer $limit = 1 ) : integer Redoes the last few migrations.
actionTo ( string $version ) Upgrades or downgrades till the specified version.
actionUp ( integer $limit ) : integer Upgrades the application by applying new migrations.
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]].
options ( $actionID )

보호된 메소드들

메소드 설명
addMigrationHistory ( string $version ) Adds new migration entry to the history.
createMigration ( string $class ) : yii\db\MigrationInterface Creates a new migration instance.
generateMigrationSourceCode ( array $params ) : string Generates new migration source PHP code.
getMigrationHistory ( integer $limit ) : array Returns the migration history.
getNewMigrations ( ) : array Returns the migrations that are not applied.
migrateDown ( string $class ) : boolean Downgrades with the specified migration class.
migrateToTime ( integer $time ) Migrates to the specified apply time in the past.
migrateToVersion ( string $version ) : integer Migrates to the certain version.
migrateUp ( string $class ) : boolean Upgrades with the specified migration class.
removeMigrationHistory ( string $version ) Removes existing migration from the history.

비공개 메소드들

메소드 설명
extractMigrationVersion ( string $rawVersion ) : string | false Checks if given migration version specification matches migration base name.
extractNamespaceMigrationVersion ( string $rawVersion ) : string | false Checks if given migration version specification matches namespaced migration name.
findMigrationPath ( string | null $namespace ) : string Finds the file path for the specified migration namespace.
generateClassName ( string $name ) : array Generates class base name and namespace from migration name from user input.
getNamespacePath ( string $namespace ) : string Returns the file path matching the give namespace.

메소드 상세

actionCreate() 공개 메소드

This command creates a new migration using the available migration template. After using this command, developers should modify the created migration skeleton by filling up the actual migration logic. yii migrate/create create_user_table In order to generate a namespaced migration, you should specify a namespace before the migration's name. Note that backslash (\) is usually considered a special character in the shell, so you need to escape it properly to avoid shell errors or incorrect behavior. For example: yii migrate/create 'app\\migrations\\createUserTable' In case [[migrationPath]] is not set and no namespace is provided, the first entry of [[migrationNamespaces]] will be used.
public actionCreate ( string $name )
$name string the name of the new migration. This should only contain letters, digits, underscores and/or backslashes. Note: If the migration name is of a special form, for example create_xxx or drop_xxx, then the generated migration file will contain extra code, in this case for creating/dropping tables.

actionDown() 공개 메소드

For example, yii migrate/down # revert the last migration yii migrate/down 3 # revert the last 3 migrations yii migrate/down all # revert all migrations
public actionDown ( integer $limit = 1 ) : integer
$limit integer the number of migrations to be reverted. Defaults to 1, meaning the last applied migration will be reverted.
리턴 integer the status of the action execution. 0 means normal, other values mean abnormal.

actionHistory() 공개 메소드

This command will show the list of migrations that have been applied so far. For example, yii migrate/history # showing the last 10 migrations yii migrate/history 5 # showing the last 5 migrations yii migrate/history all # showing the whole history
public actionHistory ( integer $limit = 10 )
$limit integer the maximum number of migrations to be displayed. If it is "all", the whole migration history will be displayed.

actionMark() 공개 메소드

No actual migration will be performed. yii migrate/mark 101129_185401 # using timestamp yii migrate/mark m101129_185401_create_user_table # using full name yii migrate/to app\migrations\M101129185401CreateUser # using full namespace name
public actionMark ( string $version ) : integer
$version string the version at which the migration history should be marked. This can be either the timestamp or the full name of the migration.
리턴 integer CLI exit code

actionNew() 공개 메소드

This command will show the new migrations that have not been applied. For example, yii migrate/new # showing the first 10 new migrations yii migrate/new 5 # showing the first 5 new migrations yii migrate/new all # showing all new migrations
public actionNew ( integer $limit = 10 )
$limit integer the maximum number of new migrations to be displayed. If it is `all`, all available new migrations will be displayed.

actionRedo() 공개 메소드

This command will first revert the specified migrations, and then apply them again. For example, yii migrate/redo # redo the last applied migration yii migrate/redo 3 # redo the last 3 applied migrations yii migrate/redo all # redo all migrations
public actionRedo ( integer $limit = 1 ) : integer
$limit integer the number of migrations to be redone. Defaults to 1, meaning the last applied migration will be redone.
리턴 integer the status of the action execution. 0 means normal, other values mean abnormal.

actionTo() 공개 메소드

Can also downgrade versions to the certain apply time in the past by providing a UNIX timestamp or a string parseable by the strtotime() function. This means that all the versions applied after the specified certain time would be reverted. This command will first revert the specified migrations, and then apply them again. For example, yii migrate/to 101129_185401 # using timestamp yii migrate/to m101129_185401_create_user_table # using full name yii migrate/to 1392853618 # using UNIX timestamp yii migrate/to "2014-02-15 13:00:50" # using strtotime() parseable string yii migrate/to app\migrations\M101129185401CreateUser # using full namespace name
public actionTo ( string $version )
$version string either the version name or the certain time value in the past that the application should be migrated to. This can be either the timestamp, the full name of the migration, the UNIX timestamp, or the parseable datetime string.

actionUp() 공개 메소드

For example, yii migrate # apply all new migrations yii migrate 3 # apply the first 3 new migrations
public actionUp ( integer $limit ) : integer
$limit integer the number of new migrations to be applied. If 0, it means applying all available new migrations.
리턴 integer the status of the action execution. 0 means normal, other values mean abnormal.

addMigrationHistory() 추상적인 보호된 메소드

Adds new migration entry to the history.
abstract protected addMigrationHistory ( string $version )
$version string migration version name.

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 ) : yii\db\MigrationInterface
$class string the migration class name
리턴 yii\db\MigrationInterface the migration instance

generateMigrationSourceCode() 보호된 메소드

Child class may override this method, adding extra logic or variation to the process.
부터: 2.0.8
protected generateMigrationSourceCode ( array $params ) : string
$params array generation parameters, usually following parameters are present: - name: string migration base name - className: string migration class name
리턴 string generated PHP code.

getMigrationHistory() 추상적인 보호된 메소드

Returns the migration history.
abstract protected getMigrationHistory ( integer $limit ) : array
$limit integer the maximum number of records in the history to be returned. `null` for "no limit".
리턴 array the migration history

getNewMigrations() 보호된 메소드

Returns the migrations that are not applied.
protected getNewMigrations ( ) : array
리턴 array list of new migrations

migrateDown() 보호된 메소드

Downgrades with the specified migration class.
protected migrateDown ( string $class ) : boolean
$class string the migration class name
리턴 boolean whether the migration is successful

migrateToTime() 보호된 메소드

Migrates to the specified apply time in the past.
protected migrateToTime ( integer $time )
$time integer UNIX timestamp value.

migrateToVersion() 보호된 메소드

Migrates to the certain version.
protected migrateToVersion ( string $version ) : integer
$version string name in the full format.
리턴 integer CLI exit code

migrateUp() 보호된 메소드

Upgrades with the specified migration class.
protected migrateUp ( string $class ) : boolean
$class string the migration class name
리턴 boolean whether the migration is successful

options() 공개 메소드

public options ( $actionID )

removeMigrationHistory() 추상적인 보호된 메소드

Removes existing migration from the history.
abstract protected removeMigrationHistory ( string $version )
$version string migration version name.

프로퍼티 상세

$defaultAction 공개적으로 프로퍼티

the default command action.
public $defaultAction

$migrationNamespaces 공개적으로 프로퍼티

list of namespaces containing the migration classes. Migration namespaces should be resolvable as a path alias if prefixed with @, e.g. if you specify the namespace app\migrations, the code Yii::getAlias('@app/migrations') should be able to return the file path to the directory this namespace refers to. For example: php [ 'app\migrations', 'some\extension\migrations', ]
부터: 2.0.10
public $migrationNamespaces

$migrationPath 공개적으로 프로퍼티

the directory containing the migration classes. This can be either a path alias or a directory path. If you have set up [[migrationNamespaces]], you may set this field to null in order to disable usage of migrations that are not namespaced.
public $migrationPath

$templateFile 공개적으로 프로퍼티

the template file for generating new migrations. This can be either a path alias (e.g. "@app/migrations/template.php") or a file path.
public $templateFile