mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-16 22:39:52 +08:00
Merge pull request #521 from sergon/migrate_command_primary_key
Migrate command primary key
This commit is contained in:
@@ -673,9 +673,9 @@ class Command extends \yii\base\Component
|
|||||||
* @param string $table the table that the primary key constraint will be removed from.
|
* @param string $table the table that the primary key constraint will be removed from.
|
||||||
* @return Command the command object itself
|
* @return Command the command object itself
|
||||||
*/
|
*/
|
||||||
public function dropPrimarykey($name, $table)
|
public function dropPrimaryKey($name, $table)
|
||||||
{
|
{
|
||||||
$sql = $this->db->getQueryBuilder()->dropPrimarykey($name, $table);
|
$sql = $this->db->getQueryBuilder()->dropPrimaryKey($name, $table);
|
||||||
return $this->setSql($sql);
|
return $this->setSql($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -309,6 +309,35 @@ class Migration extends \yii\base\Component
|
|||||||
echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n";
|
echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds and executes a SQL statement for creating a primary key.
|
||||||
|
* The method will properly quote the table and column names.
|
||||||
|
* @param string $name the name of the primary key constraint.
|
||||||
|
* @param string $table the table that the primary key constraint will be added to.
|
||||||
|
* @param string|array $columns comma separated string or array of columns that the primary key will consist of.
|
||||||
|
*/
|
||||||
|
public function addPrimaryKey($name, $table, $columns)
|
||||||
|
{
|
||||||
|
echo " > add primary key $name on $table (".(is_array($columns) ? implode(',',$columns) : $columns).") ...";
|
||||||
|
$time = microtime(true);
|
||||||
|
$this->db->createCommand()->addPrimaryKey($name, $table, $columns)->execute();
|
||||||
|
echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds and executes a SQL statement for dropping a primary key.
|
||||||
|
* @param string $name the name of the primary key constraint to be removed.
|
||||||
|
* @param string $table the table that the primary key constraint will be removed from.
|
||||||
|
* @return Command the command object itself
|
||||||
|
*/
|
||||||
|
public function dropPrimaryKey($name, $table)
|
||||||
|
{
|
||||||
|
echo " > drop primary key $name ...";
|
||||||
|
$time = microtime(true);
|
||||||
|
$this->db->createCommand()->dropPrimaryKey($name, $table)->execute();
|
||||||
|
echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a SQL statement for adding a foreign key constraint to an existing table.
|
* Builds a SQL statement for adding a foreign key constraint to an existing table.
|
||||||
* The method will properly quote the table and column names.
|
* The method will properly quote the table and column names.
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ class QueryBuilder extends \yii\base\Object
|
|||||||
* @param string $table the table that the primary key constraint will be removed from.
|
* @param string $table the table that the primary key constraint will be removed from.
|
||||||
* @return string the SQL statement for removing a primary key constraint from an existing table. *
|
* @return string the SQL statement for removing a primary key constraint from an existing table. *
|
||||||
*/
|
*/
|
||||||
public function dropPrimarykey($name, $table)
|
public function dropPrimaryKey($name, $table)
|
||||||
{
|
{
|
||||||
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
|
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
|
||||||
. ' DROP CONSTRAINT ' . $this->db->quoteColumnName($name);
|
. ' DROP CONSTRAINT ' . $this->db->quoteColumnName($name);
|
||||||
|
|||||||
Reference in New Issue
Block a user