Download the PHP package carono/yii2-migrate without Composer
On this page you can find all versions of the php package carono/yii2-migrate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download carono/yii2-migrate
More information about carono/yii2-migrate
Files in carono/yii2-migrate
Package yii2-migrate
Short Description Trait to help create databases in migrations for Yii2
License MIT
Informations about the package yii2-migrate
[RUS]
MigrationTrait
To expand the migration capabilities, you must add a trait \carono\yii2migrate\traits\MigrationTrait or extend the migration class from \carono\yii2migrate\Migration
public function tableOptions()
Return the array with the settings for creating tables, where the key is the name of the db driver.
When creating tables through createTable(), if no properties are specified, they will be picked up from this function
public function newTables()
Return an array where the key is the name of the table, and the values are columns with types.
If you call the $this->upNewTables() function, all specified tables will be created via createTable()
If you call the function $this->downNewTables(), all specified table will be deleted using dropTable()
pubic function newColumns()
Return an array where the key is the name of an existing table and the values are columns with types.
If you call the function $this->upNewColumns(), all specified columns will be created using addColumn()
If you call the function $this->downNewColumns(), all specified columns will be deleted after dropColumn()
public function newIndex()
Return an array where the key is the name of an existing table and the values are the index parameters via $this->index()
If you call the $this->upNewIndex() function, all specified indexes will be created via createIndex()
If you call the function $this->downNewIndex(), all specified columns will be deleted using the dropIndex()
Working with foreign keys
Create a table, specifying a foreign key, by table name only
Adding a foreign key column
Adding a foreign key to an existing column
Adding foreign key with auto name
Delete foreign key by column name
Working with indexes
Create an index with an automatic name
Deleting an index by column name
(!) It is necessary to pay attention, if there are several columns on the index, then it is necessary to specify them in the necessary sequence. If there are several indexes with such a set and sequence, all of them will be deleted. (!) Does not work correctly with postgreSQL (https://github.com/yiisoft/yii2/issues/16639)
Pivot tables
To implement many-to-many tables, you can use the $this->pivot() function, a table with 2 keys will be created. The names of the keys in the PivotTable are generated automatically, so they can be set via refColumn() and sourceColumn()
Create a PivotTable by creating a table. The result is the table {{%user}}[id] {{%pv_user_photos}}[user_id, photo_id]
Create a PivotTable by adding a column.
Specify the name of the PivotTable
PivotTrait
Trait to help work with pivot tables.
$company
- table model Company (requires trait PivotTrait)
$user
- model of table User
PvCompanyDirector
- a pivot table of the two models: company and user
Pivot table
- a table which contains 2 primary key
Added to the table PvCompanyDirector a bunch of the end user company
Get the PvCompanyDirector model for the company-user bundle
Removed a bunch of the user-company
Remove all users from PvCompanyDirector for this company
Save to a temporary link variable so that you can use them later
The preservation of the ties of a temporary variable.
$clear - completely clears all links before adding
The change in behavior of the migration class
public function createIndex($name, $table, $columns, $unique = false)
- $name you can specify null to generate the index name automatically
public function createTable($table, $columns, $options = null)
- $columns supports the $this->foreignKey() and $this->pivot()
- if $options is not specified, options are pulled from $this->tableOptions, if there are no options, then from @tableOptions to $columns
public function alterColumn($table, $column, $type)
- $type supports type $this->foreignKey()
public function addColumn($table, $column, $type)
- $type supports type $this->foreignKey() and $this->pivot()
public function addPrimaryKey($name, $table, $columns)
- $name you can specify null to generate the index name automatically
public function dropColumn($table, $column)
- Before deleting the table, foreign keys are cleared
An example of a complete migration
The resulting database schema