addPrimaryKey() public method

The method will properly quote the table and column names.
public addPrimaryKey ( string $name, string $table, string | array $columns )
$name string the name of the primary key constraint.
$table string the table that the primary key constraint will be added to.
$columns string | array comma separated string or array of columns that the primary key will consist of.
コード例 #1
0
 /**
  * Create table in database
  */
 public function runCreateTable()
 {
     $this->dropTable();
     if ($this->hideMigrationOutput) {
         ob_start();
     }
     /** @var Connection $_conn */
     $_conn = Yii::$app->{$this->db};
     if (!$_conn->schema->getTableSchema($this->tableName)) {
         $this->migrationClass->createTable($this->tableNameRaw, $this->columns);
         if (is_array($this->primaryKeys) && sizeof($this->primaryKeys)) {
             try {
                 $this->migrationClass->addPrimaryKey("{$this->tableNameRaw}_pk", $this->tableNameRaw, $this->primaryKeys);
             } catch (\yii\db\Exception $exp) {
             }
         }
     }
     if ($this->hideMigrationOutput) {
         ob_clean();
         ob_flush();
     }
 }
コード例 #2
0
ファイル: Migration.php プロジェクト: flexibuild/migrate
 /**
  * @inheritdoc
  * Note: table will be auto pefixied if [[$autoWrapTableNames]] is true.
  */
 public function addPrimaryKey($name, $table, $columns)
 {
     $table = $this->autoWrappedTableName($table);
     return parent::addPrimaryKey($name, $table, $columns);
 }
コード例 #3
0
ファイル: Migration.php プロジェクト: ivan-chkv/yii2-boost
 /**
  * @inheritdoc
  * @param string|null $name
  */
 public function addPrimaryKey($name, $table, $columns)
 {
     if (is_null($name)) {
         $name = implode('-', (array) $columns);
     }
     parent::addPrimaryKey($name, $table, $columns);
 }
コード例 #4
0
ファイル: Migration.php プロジェクト: lav45/yii2-db-migrate
 /**
  * Builds and executes a SQL statement for creating a primary key.
  * The method will properly quote the table and column names.
  * @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.
  * @param string $name default null, the name of the primary key constraint.
  */
 public function addPrimaryKey($table, $columns, $name = null)
 {
     $name = $name ?: $this->getNamePrimaryKey($table);
     parent::addPrimaryKey($name, $table, $columns);
 }
コード例 #5
0
ファイル: Migration.php プロジェクト: carono/yii2-installer
 public function addPrimaryKey($name, $table, $columns)
 {
     if (is_null($name)) {
         $name = self::formIndexName($table, $columns, 'pk');
     }
     return parent::addPrimaryKey($name, $table, $columns);
 }