Commit d5cd6b0d by Vladimir

Update Migration.php

add ability to use an array in multi columns parameters
parent 369e4218
...@@ -358,15 +358,15 @@ class Migration extends \yii\base\Component ...@@ -358,15 +358,15 @@ class Migration extends \yii\base\Component
* The method will properly quote the table and column names. * The method will properly quote the table and column names.
* @param string $name the name of the foreign key constraint. * @param string $name the name of the foreign key constraint.
* @param string $table the table that the foreign key constraint will be added to. * @param string $table the table that the foreign key constraint will be added to.
* @param string $columns the name of the column to that the constraint will be added on. If there are multiple columns, separate them with commas. * @param string $columns the name of the column to that the constraint will be added on. If there are multiple columns, separate them with commas or use an array.
* @param string $refTable the table that the foreign key references to. * @param string $refTable the table that the foreign key references to.
* @param string $refColumns the name of the column that the foreign key references to. If there are multiple columns, separate them with commas. * @param string $refColumns the name of the column that the foreign key references to. If there are multiple columns, separate them with commas or use an array.
* @param string $delete the ON DELETE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL * @param string $delete the ON DELETE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
* @param string $update the ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL * @param string $update the ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
*/ */
public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null) public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null)
{ {
echo " > add foreign key $name: $table ($columns) references $refTable ($refColumns) ..."; echo " > add foreign key $name: $table (" . implode(',', (array)$columns) . ") references $refTable (" . implode(',', (array)$refColumns) . ") ...";
$time = microtime(true); $time = microtime(true);
$this->db->createCommand()->addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete, $update)->execute(); $this->db->createCommand()->addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete, $update)->execute();
echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n"; echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n";
...@@ -390,12 +390,12 @@ class Migration extends \yii\base\Component ...@@ -390,12 +390,12 @@ class Migration extends \yii\base\Component
* @param string $name the name of the index. The name will be properly quoted by the method. * @param string $name the name of the index. The name will be properly quoted by the method.
* @param string $table the table that the new index will be created for. The table name will be properly quoted by the method. * @param string $table the table that the new index will be created for. The table name will be properly quoted by the method.
* @param string $column the column(s) that should be included in the index. If there are multiple columns, please separate them * @param string $column the column(s) that should be included in the index. If there are multiple columns, please separate them
* by commas. The column names will be properly quoted by the method. * by commas or use an array. The column names will be properly quoted by the method.
* @param boolean $unique whether to add UNIQUE constraint on the created index. * @param boolean $unique whether to add UNIQUE constraint on the created index.
*/ */
public function createIndex($name, $table, $column, $unique = false) public function createIndex($name, $table, $column, $unique = false)
{ {
echo " > create" . ($unique ? ' unique' : '') . " index $name on $table ($column) ..."; echo " > create" . ($unique ? ' unique' : '') . " index $name on $table (" . implode(',', (array)$column) . ") ...";
$time = microtime(true); $time = microtime(true);
$this->db->createCommand()->createIndex($name, $table, $column, $unique)->execute(); $this->db->createCommand()->createIndex($name, $table, $column, $unique)->execute();
echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n"; echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment