| @@ 325-342 (lines=18) @@ | ||
| 322 | } |
|
| 323 | ||
| 324 | // Add the primary key(s) |
|
| 325 | if (isset($newOptions['primary_key']) && $newOptions['primary_key'] !== false) { |
|
| 326 | $sql = sprintf( |
|
| 327 | 'ADD CONSTRAINT %s PRIMARY KEY (', |
|
| 328 | $this->quoteColumnName($parts['table'] . '_pkey') |
|
| 329 | ); |
|
| 330 | if (is_string($newOptions['primary_key'])) { // handle primary_key => 'id' |
|
| 331 | $sql .= $this->quoteColumnName($newOptions['primary_key']); |
|
| 332 | } else if (is_array($newOptions['primary_key'])) { // handle primary_key => array('tag_id', 'resource_id') |
|
| 333 | $sql .= implode(',', array_map([$this, 'quoteColumnName'], $newOptions['primary_key'])); |
|
| 334 | } else { |
|
| 335 | throw new \InvalidArgumentException(sprintf( |
|
| 336 | "Invalid value for option 'primary_key': %s", |
|
| 337 | json_encode($newOptions['primary_key']) |
|
| 338 | )); |
|
| 339 | } |
|
| 340 | $sql .= ')'; |
|
| 341 | $instructions->addAlter($sql); |
|
| 342 | } |
|
| 343 | ||
| 344 | // Process table comments |
|
| 345 | if (array_key_exists('comment', $newOptions)) { |
|
| @@ 327-344 (lines=18) @@ | ||
| 324 | } |
|
| 325 | ||
| 326 | // Add the primary key(s) |
|
| 327 | if (isset($newOptions['primary_key']) && $newOptions['primary_key'] !== false) { |
|
| 328 | $sql = sprintf( |
|
| 329 | 'ADD CONSTRAINT %s PRIMARY KEY (', |
|
| 330 | $this->quoteColumnName('PK_' . $table->getName()) |
|
| 331 | ); |
|
| 332 | if (is_string($newOptions['primary_key'])) { // handle primary_key => 'id' |
|
| 333 | $sql .= $this->quoteColumnName($newOptions['primary_key']); |
|
| 334 | } else if (is_array($newOptions['primary_key'])) { // handle primary_key => array('tag_id', 'resource_id') |
|
| 335 | $sql .= implode(',', array_map([$this, 'quoteColumnName'], $newOptions['primary_key'])); |
|
| 336 | } else { |
|
| 337 | throw new \InvalidArgumentException(sprintf( |
|
| 338 | "Invalid value for option 'primary_key': %s", |
|
| 339 | json_encode($newOptions['primary_key']) |
|
| 340 | )); |
|
| 341 | } |
|
| 342 | $sql .= ')'; |
|
| 343 | $instructions->addAlter($sql); |
|
| 344 | } |
|
| 345 | ||
| 346 | return $instructions; |
|
| 347 | } |
|