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.
 /**
  * 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();
     }
 }
Exemplo n.º 2
0
 /**
  * @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);
 }
Exemplo n.º 3
0
 /**
  * @inheritdoc
  * @param string|null $name
  */
 public function addPrimaryKey($name, $table, $columns)
 {
     if (is_null($name)) {
         $name = implode('-', (array) $columns);
     }
     parent::addPrimaryKey($name, $table, $columns);
 }
Exemplo n.º 4
0
 /**
  * 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);
 }
Exemplo n.º 5
0
 public function addPrimaryKey($name, $table, $columns)
 {
     if (is_null($name)) {
         $name = self::formIndexName($table, $columns, 'pk');
     }
     return parent::addPrimaryKey($name, $table, $columns);
 }