| @@ 294-321 (lines=28) @@ | ||
| 291 | } |
|
| 292 | ||
| 293 | // Set the default primary key and add associated column |
|
| 294 | if (isset($newOptions['id']) && $newOptions['id'] !== false) { |
|
| 295 | if ($newOptions['id'] === true) { |
|
| 296 | $newOptions['primary_key'] = 'id'; |
|
| 297 | } elseif (is_string($newOptions['id'])) { |
|
| 298 | // Handle id => "field_name" to support AUTO_INCREMENT |
|
| 299 | $newOptions['primary_key'] = $newOptions['id']; |
|
| 300 | } else { |
|
| 301 | throw new \InvalidArgumentException(sprintf( |
|
| 302 | "Invalid value for option 'id': %s", |
|
| 303 | json_encode($newOptions['id']) |
|
| 304 | )); |
|
| 305 | } |
|
| 306 | ||
| 307 | if ($this->hasColumn($table->getName(), $newOptions['primary_key'])) { |
|
| 308 | throw new \RuntimeException(sprintf( |
|
| 309 | "Tried to create primary key column %s for table %s, but that column already exists", |
|
| 310 | $this->quoteColumnName($newOptions['primary_key']), |
|
| 311 | $this->quoteTableName($table->getName()) |
|
| 312 | )); |
|
| 313 | } |
|
| 314 | ||
| 315 | $column = new Column(); |
|
| 316 | $column |
|
| 317 | ->setName($newOptions['primary_key']) |
|
| 318 | ->setType('integer') |
|
| 319 | ->setIdentity(true); |
|
| 320 | $instructions->merge($this->getAddColumnInstructions($table, $column)); |
|
| 321 | } |
|
| 322 | ||
| 323 | // Add the primary key(s) |
|
| 324 | if (isset($newOptions['primary_key']) && $newOptions['primary_key'] !== false) { |
|
| @@ 266-292 (lines=27) @@ | ||
| 263 | } |
|
| 264 | ||
| 265 | // Set the default primary key and add associated column |
|
| 266 | if (isset($newOptions['id']) && $newOptions['id'] !== false) { |
|
| 267 | if ($newOptions['id'] === true) { |
|
| 268 | $newOptions['primary_key'] = 'id'; |
|
| 269 | } elseif (is_string($newOptions['id'])) { |
|
| 270 | // Handle id => "field_name" to support AUTO_INCREMENT |
|
| 271 | $newOptions['primary_key'] = $newOptions['id']; |
|
| 272 | } else { |
|
| 273 | throw new \InvalidArgumentException(sprintf( |
|
| 274 | "Invalid value for option 'id': %s", |
|
| 275 | json_encode($newOptions['id']) |
|
| 276 | )); |
|
| 277 | } |
|
| 278 | ||
| 279 | if ($this->hasColumn($table->getName(), $newOptions['primary_key'])) { |
|
| 280 | throw new \RuntimeException(sprintf( |
|
| 281 | "Tried to create primary key column %s for table %s, but that column already exists", |
|
| 282 | $this->quoteColumnName($newOptions['primary_key']), |
|
| 283 | $this->quoteTableName($table->getName()) |
|
| 284 | )); |
|
| 285 | } |
|
| 286 | ||
| 287 | $column = new Column(); |
|
| 288 | $column |
|
| 289 | ->setName($newOptions['primary_key']) |
|
| 290 | ->setType('integer'); |
|
| 291 | $instructions->merge($this->getAddColumnInstructions($table, $column)); |
|
| 292 | } |
|
| 293 | ||
| 294 | // Add the primary key(s) |
|
| 295 | if (isset($newOptions['primary_key']) && $newOptions['primary_key'] !== false) { |
|
| @@ 296-323 (lines=28) @@ | ||
| 293 | } |
|
| 294 | ||
| 295 | // Set the default primary key and add associated column |
|
| 296 | if (isset($newOptions['id']) && $newOptions['id'] !== false) { |
|
| 297 | if ($newOptions['id'] === true) { |
|
| 298 | $newOptions['primary_key'] = 'id'; |
|
| 299 | } elseif (is_string($newOptions['id'])) { |
|
| 300 | // Handle id => "field_name" to support AUTO_INCREMENT |
|
| 301 | $newOptions['primary_key'] = $newOptions['id']; |
|
| 302 | } else { |
|
| 303 | throw new \InvalidArgumentException(sprintf( |
|
| 304 | "Invalid value for option 'id': %s", |
|
| 305 | json_encode($newOptions['id']) |
|
| 306 | )); |
|
| 307 | } |
|
| 308 | ||
| 309 | if ($this->hasColumn($table->getName(), $newOptions['primary_key'])) { |
|
| 310 | throw new \RuntimeException(sprintf( |
|
| 311 | "Tried to create primary key column %s for table %s, but that column already exists", |
|
| 312 | $this->quoteColumnName($newOptions['primary_key']), |
|
| 313 | $this->quoteTableName($table->getName()) |
|
| 314 | )); |
|
| 315 | } |
|
| 316 | ||
| 317 | $column = new Column(); |
|
| 318 | $column |
|
| 319 | ->setName($newOptions['primary_key']) |
|
| 320 | ->setType('integer') |
|
| 321 | ->setIdentity(true); |
|
| 322 | $this->addColumn($table, $column); |
|
| 323 | } |
|
| 324 | ||
| 325 | // Add the primary key(s) |
|
| 326 | if (isset($newOptions['primary_key']) && $newOptions['primary_key'] !== false) { |
|