PostgresGrammar.php 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. <?php
  2. namespace Illuminate\Database\Schema\Grammars;
  3. use RuntimeException;
  4. use Illuminate\Support\Fluent;
  5. use Illuminate\Database\Schema\Blueprint;
  6. class PostgresGrammar extends Grammar
  7. {
  8. /**
  9. * If this Grammar supports schema changes wrapped in a transaction.
  10. *
  11. * @var bool
  12. */
  13. protected $transactions = true;
  14. /**
  15. * The possible column modifiers.
  16. *
  17. * @var array
  18. */
  19. protected $modifiers = ['Increment', 'Nullable', 'Default'];
  20. /**
  21. * The columns available as serials.
  22. *
  23. * @var array
  24. */
  25. protected $serials = ['bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger'];
  26. /**
  27. * The commands to be executed outside of create or alter command.
  28. *
  29. * @var array
  30. */
  31. protected $fluentCommands = ['Comment'];
  32. /**
  33. * Compile the query to determine if a table exists.
  34. *
  35. * @return string
  36. */
  37. public function compileTableExists()
  38. {
  39. return 'select * from information_schema.tables where table_schema = ? and table_name = ?';
  40. }
  41. /**
  42. * Compile the query to determine the list of columns.
  43. *
  44. * @return string
  45. */
  46. public function compileColumnListing()
  47. {
  48. return 'select column_name from information_schema.columns where table_schema = ? and table_name = ?';
  49. }
  50. /**
  51. * Compile a create table command.
  52. *
  53. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  54. * @param \Illuminate\Support\Fluent $command
  55. * @return string
  56. */
  57. public function compileCreate(Blueprint $blueprint, Fluent $command)
  58. {
  59. return sprintf('%s table %s (%s)',
  60. $blueprint->temporary ? 'create temporary' : 'create',
  61. $this->wrapTable($blueprint),
  62. implode(', ', $this->getColumns($blueprint))
  63. );
  64. }
  65. /**
  66. * Compile a column addition command.
  67. *
  68. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  69. * @param \Illuminate\Support\Fluent $command
  70. * @return string
  71. */
  72. public function compileAdd(Blueprint $blueprint, Fluent $command)
  73. {
  74. return sprintf('alter table %s %s',
  75. $this->wrapTable($blueprint),
  76. implode(', ', $this->prefixArray('add column', $this->getColumns($blueprint)))
  77. );
  78. }
  79. /**
  80. * Compile a primary key command.
  81. *
  82. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  83. * @param \Illuminate\Support\Fluent $command
  84. * @return string
  85. */
  86. public function compilePrimary(Blueprint $blueprint, Fluent $command)
  87. {
  88. $columns = $this->columnize($command->columns);
  89. return 'alter table '.$this->wrapTable($blueprint)." add primary key ({$columns})";
  90. }
  91. /**
  92. * Compile a unique key command.
  93. *
  94. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  95. * @param \Illuminate\Support\Fluent $command
  96. * @return string
  97. */
  98. public function compileUnique(Blueprint $blueprint, Fluent $command)
  99. {
  100. return sprintf('alter table %s add constraint %s unique (%s)',
  101. $this->wrapTable($blueprint),
  102. $this->wrap($command->index),
  103. $this->columnize($command->columns)
  104. );
  105. }
  106. /**
  107. * Compile a plain index key command.
  108. *
  109. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  110. * @param \Illuminate\Support\Fluent $command
  111. * @return string
  112. */
  113. public function compileIndex(Blueprint $blueprint, Fluent $command)
  114. {
  115. return sprintf('create index %s on %s%s (%s)',
  116. $this->wrap($command->index),
  117. $this->wrapTable($blueprint),
  118. $command->algorithm ? ' using '.$command->algorithm : '',
  119. $this->columnize($command->columns)
  120. );
  121. }
  122. /**
  123. * Compile a spatial index key command.
  124. *
  125. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  126. * @param \Illuminate\Support\Fluent $command
  127. * @return string
  128. */
  129. public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)
  130. {
  131. $command->algorithm = 'gist';
  132. return $this->compileIndex($blueprint, $command);
  133. }
  134. /**
  135. * Compile a foreign key command.
  136. *
  137. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  138. * @param \Illuminate\Support\Fluent $command
  139. * @return string
  140. */
  141. public function compileForeign(Blueprint $blueprint, Fluent $command)
  142. {
  143. $sql = parent::compileForeign($blueprint, $command);
  144. if (! is_null($command->deferrable)) {
  145. $sql .= $command->deferrable ? ' deferrable' : ' not deferrable';
  146. }
  147. if ($command->deferrable && ! is_null($command->initiallyImmediate)) {
  148. $sql .= $command->initiallyImmediate ? ' initially immediate' : ' initially deferred';
  149. }
  150. return $sql;
  151. }
  152. /**
  153. * Compile a drop table command.
  154. *
  155. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  156. * @param \Illuminate\Support\Fluent $command
  157. * @return string
  158. */
  159. public function compileDrop(Blueprint $blueprint, Fluent $command)
  160. {
  161. return 'drop table '.$this->wrapTable($blueprint);
  162. }
  163. /**
  164. * Compile a drop table (if exists) command.
  165. *
  166. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  167. * @param \Illuminate\Support\Fluent $command
  168. * @return string
  169. */
  170. public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
  171. {
  172. return 'drop table if exists '.$this->wrapTable($blueprint);
  173. }
  174. /**
  175. * Compile the SQL needed to drop all tables.
  176. *
  177. * @param string $tables
  178. * @return string
  179. */
  180. public function compileDropAllTables($tables)
  181. {
  182. return 'drop table "'.implode('","', $tables).'" cascade';
  183. }
  184. /**
  185. * Compile the SQL needed to retrieve all table names.
  186. *
  187. * @param string $schema
  188. * @return string
  189. */
  190. public function compileGetAllTables($schema)
  191. {
  192. return "select tablename from pg_catalog.pg_tables where schemaname = '{$schema}'";
  193. }
  194. /**
  195. * Compile a drop column command.
  196. *
  197. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  198. * @param \Illuminate\Support\Fluent $command
  199. * @return string
  200. */
  201. public function compileDropColumn(Blueprint $blueprint, Fluent $command)
  202. {
  203. $columns = $this->prefixArray('drop column', $this->wrapArray($command->columns));
  204. return 'alter table '.$this->wrapTable($blueprint).' '.implode(', ', $columns);
  205. }
  206. /**
  207. * Compile a drop primary key command.
  208. *
  209. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  210. * @param \Illuminate\Support\Fluent $command
  211. * @return string
  212. */
  213. public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
  214. {
  215. $index = $this->wrap("{$blueprint->getTable()}_pkey");
  216. return 'alter table '.$this->wrapTable($blueprint)." drop constraint {$index}";
  217. }
  218. /**
  219. * Compile a drop unique key command.
  220. *
  221. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  222. * @param \Illuminate\Support\Fluent $command
  223. * @return string
  224. */
  225. public function compileDropUnique(Blueprint $blueprint, Fluent $command)
  226. {
  227. $index = $this->wrap($command->index);
  228. return "alter table {$this->wrapTable($blueprint)} drop constraint {$index}";
  229. }
  230. /**
  231. * Compile a drop index command.
  232. *
  233. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  234. * @param \Illuminate\Support\Fluent $command
  235. * @return string
  236. */
  237. public function compileDropIndex(Blueprint $blueprint, Fluent $command)
  238. {
  239. return "drop index {$this->wrap($command->index)}";
  240. }
  241. /**
  242. * Compile a drop spatial index command.
  243. *
  244. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  245. * @param \Illuminate\Support\Fluent $command
  246. * @return string
  247. */
  248. public function compileDropSpatialIndex(Blueprint $blueprint, Fluent $command)
  249. {
  250. return $this->compileDropIndex($blueprint, $command);
  251. }
  252. /**
  253. * Compile a drop foreign key command.
  254. *
  255. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  256. * @param \Illuminate\Support\Fluent $command
  257. * @return string
  258. */
  259. public function compileDropForeign(Blueprint $blueprint, Fluent $command)
  260. {
  261. $index = $this->wrap($command->index);
  262. return "alter table {$this->wrapTable($blueprint)} drop constraint {$index}";
  263. }
  264. /**
  265. * Compile a rename table command.
  266. *
  267. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  268. * @param \Illuminate\Support\Fluent $command
  269. * @return string
  270. */
  271. public function compileRename(Blueprint $blueprint, Fluent $command)
  272. {
  273. $from = $this->wrapTable($blueprint);
  274. return "alter table {$from} rename to ".$this->wrapTable($command->to);
  275. }
  276. /**
  277. * Compile a rename index command.
  278. *
  279. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  280. * @param \Illuminate\Support\Fluent $command
  281. * @return string
  282. */
  283. public function compileRenameIndex(Blueprint $blueprint, Fluent $command)
  284. {
  285. return sprintf('alter index %s rename to %s',
  286. $this->wrap($command->from),
  287. $this->wrap($command->to)
  288. );
  289. }
  290. /**
  291. * Compile the command to enable foreign key constraints.
  292. *
  293. * @return string
  294. */
  295. public function compileEnableForeignKeyConstraints()
  296. {
  297. return 'SET CONSTRAINTS ALL IMMEDIATE;';
  298. }
  299. /**
  300. * Compile the command to disable foreign key constraints.
  301. *
  302. * @return string
  303. */
  304. public function compileDisableForeignKeyConstraints()
  305. {
  306. return 'SET CONSTRAINTS ALL DEFERRED;';
  307. }
  308. /**
  309. * Compile a comment command.
  310. *
  311. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  312. * @param \Illuminate\Support\Fluent $command
  313. * @return string
  314. */
  315. public function compileComment(Blueprint $blueprint, Fluent $command)
  316. {
  317. return sprintf('comment on column %s.%s is %s',
  318. $this->wrapTable($blueprint),
  319. $this->wrap($command->column->name),
  320. "'".str_replace("'", "''", $command->value)."'"
  321. );
  322. }
  323. /**
  324. * Create the column definition for a char type.
  325. *
  326. * @param \Illuminate\Support\Fluent $column
  327. * @return string
  328. */
  329. protected function typeChar(Fluent $column)
  330. {
  331. return "char({$column->length})";
  332. }
  333. /**
  334. * Create the column definition for a string type.
  335. *
  336. * @param \Illuminate\Support\Fluent $column
  337. * @return string
  338. */
  339. protected function typeString(Fluent $column)
  340. {
  341. return "varchar({$column->length})";
  342. }
  343. /**
  344. * Create the column definition for a text type.
  345. *
  346. * @param \Illuminate\Support\Fluent $column
  347. * @return string
  348. */
  349. protected function typeText(Fluent $column)
  350. {
  351. return 'text';
  352. }
  353. /**
  354. * Create the column definition for a medium text type.
  355. *
  356. * @param \Illuminate\Support\Fluent $column
  357. * @return string
  358. */
  359. protected function typeMediumText(Fluent $column)
  360. {
  361. return 'text';
  362. }
  363. /**
  364. * Create the column definition for a long text type.
  365. *
  366. * @param \Illuminate\Support\Fluent $column
  367. * @return string
  368. */
  369. protected function typeLongText(Fluent $column)
  370. {
  371. return 'text';
  372. }
  373. /**
  374. * Create the column definition for an integer type.
  375. *
  376. * @param \Illuminate\Support\Fluent $column
  377. * @return string
  378. */
  379. protected function typeInteger(Fluent $column)
  380. {
  381. return $column->autoIncrement ? 'serial' : 'integer';
  382. }
  383. /**
  384. * Create the column definition for a big integer type.
  385. *
  386. * @param \Illuminate\Support\Fluent $column
  387. * @return string
  388. */
  389. protected function typeBigInteger(Fluent $column)
  390. {
  391. return $column->autoIncrement ? 'bigserial' : 'bigint';
  392. }
  393. /**
  394. * Create the column definition for a medium integer type.
  395. *
  396. * @param \Illuminate\Support\Fluent $column
  397. * @return string
  398. */
  399. protected function typeMediumInteger(Fluent $column)
  400. {
  401. return $column->autoIncrement ? 'serial' : 'integer';
  402. }
  403. /**
  404. * Create the column definition for a tiny integer type.
  405. *
  406. * @param \Illuminate\Support\Fluent $column
  407. * @return string
  408. */
  409. protected function typeTinyInteger(Fluent $column)
  410. {
  411. return $column->autoIncrement ? 'smallserial' : 'smallint';
  412. }
  413. /**
  414. * Create the column definition for a small integer type.
  415. *
  416. * @param \Illuminate\Support\Fluent $column
  417. * @return string
  418. */
  419. protected function typeSmallInteger(Fluent $column)
  420. {
  421. return $column->autoIncrement ? 'smallserial' : 'smallint';
  422. }
  423. /**
  424. * Create the column definition for a float type.
  425. *
  426. * @param \Illuminate\Support\Fluent $column
  427. * @return string
  428. */
  429. protected function typeFloat(Fluent $column)
  430. {
  431. return $this->typeDouble($column);
  432. }
  433. /**
  434. * Create the column definition for a double type.
  435. *
  436. * @param \Illuminate\Support\Fluent $column
  437. * @return string
  438. */
  439. protected function typeDouble(Fluent $column)
  440. {
  441. return 'double precision';
  442. }
  443. /**
  444. * Create the column definition for a real type.
  445. *
  446. * @param \Illuminate\Support\Fluent $column
  447. * @return string
  448. */
  449. protected function typeReal(Fluent $column)
  450. {
  451. return 'real';
  452. }
  453. /**
  454. * Create the column definition for a decimal type.
  455. *
  456. * @param \Illuminate\Support\Fluent $column
  457. * @return string
  458. */
  459. protected function typeDecimal(Fluent $column)
  460. {
  461. return "decimal({$column->total}, {$column->places})";
  462. }
  463. /**
  464. * Create the column definition for a boolean type.
  465. *
  466. * @param \Illuminate\Support\Fluent $column
  467. * @return string
  468. */
  469. protected function typeBoolean(Fluent $column)
  470. {
  471. return 'boolean';
  472. }
  473. /**
  474. * Create the column definition for an enumeration type.
  475. *
  476. * @param \Illuminate\Support\Fluent $column
  477. * @return string
  478. */
  479. protected function typeEnum(Fluent $column)
  480. {
  481. return sprintf(
  482. 'varchar(255) check ("%s" in (%s))',
  483. $column->name,
  484. $this->quoteString($column->allowed)
  485. );
  486. }
  487. /**
  488. * Create the column definition for a json type.
  489. *
  490. * @param \Illuminate\Support\Fluent $column
  491. * @return string
  492. */
  493. protected function typeJson(Fluent $column)
  494. {
  495. return 'json';
  496. }
  497. /**
  498. * Create the column definition for a jsonb type.
  499. *
  500. * @param \Illuminate\Support\Fluent $column
  501. * @return string
  502. */
  503. protected function typeJsonb(Fluent $column)
  504. {
  505. return 'jsonb';
  506. }
  507. /**
  508. * Create the column definition for a date type.
  509. *
  510. * @param \Illuminate\Support\Fluent $column
  511. * @return string
  512. */
  513. protected function typeDate(Fluent $column)
  514. {
  515. return 'date';
  516. }
  517. /**
  518. * Create the column definition for a date-time type.
  519. *
  520. * @param \Illuminate\Support\Fluent $column
  521. * @return string
  522. */
  523. protected function typeDateTime(Fluent $column)
  524. {
  525. return "timestamp($column->precision) without time zone";
  526. }
  527. /**
  528. * Create the column definition for a date-time (with time zone) type.
  529. *
  530. * @param \Illuminate\Support\Fluent $column
  531. * @return string
  532. */
  533. protected function typeDateTimeTz(Fluent $column)
  534. {
  535. return "timestamp($column->precision) with time zone";
  536. }
  537. /**
  538. * Create the column definition for a time type.
  539. *
  540. * @param \Illuminate\Support\Fluent $column
  541. * @return string
  542. */
  543. protected function typeTime(Fluent $column)
  544. {
  545. return "time($column->precision) without time zone";
  546. }
  547. /**
  548. * Create the column definition for a time (with time zone) type.
  549. *
  550. * @param \Illuminate\Support\Fluent $column
  551. * @return string
  552. */
  553. protected function typeTimeTz(Fluent $column)
  554. {
  555. return "time($column->precision) with time zone";
  556. }
  557. /**
  558. * Create the column definition for a timestamp type.
  559. *
  560. * @param \Illuminate\Support\Fluent $column
  561. * @return string
  562. */
  563. protected function typeTimestamp(Fluent $column)
  564. {
  565. $columnType = "timestamp($column->precision) without time zone";
  566. return $column->useCurrent ? "$columnType default CURRENT_TIMESTAMP" : $columnType;
  567. }
  568. /**
  569. * Create the column definition for a timestamp (with time zone) type.
  570. *
  571. * @param \Illuminate\Support\Fluent $column
  572. * @return string
  573. */
  574. protected function typeTimestampTz(Fluent $column)
  575. {
  576. $columnType = "timestamp($column->precision) with time zone";
  577. return $column->useCurrent ? "$columnType default CURRENT_TIMESTAMP" : $columnType;
  578. }
  579. /**
  580. * Create the column definition for a year type.
  581. *
  582. * @param \Illuminate\Support\Fluent $column
  583. * @return string
  584. */
  585. protected function typeYear(Fluent $column)
  586. {
  587. return $this->typeInteger($column);
  588. }
  589. /**
  590. * Create the column definition for a binary type.
  591. *
  592. * @param \Illuminate\Support\Fluent $column
  593. * @return string
  594. */
  595. protected function typeBinary(Fluent $column)
  596. {
  597. return 'bytea';
  598. }
  599. /**
  600. * Create the column definition for a uuid type.
  601. *
  602. * @param \Illuminate\Support\Fluent $column
  603. * @return string
  604. */
  605. protected function typeUuid(Fluent $column)
  606. {
  607. return 'uuid';
  608. }
  609. /**
  610. * Create the column definition for an IP address type.
  611. *
  612. * @param \Illuminate\Support\Fluent $column
  613. * @return string
  614. */
  615. protected function typeIpAddress(Fluent $column)
  616. {
  617. return 'inet';
  618. }
  619. /**
  620. * Create the column definition for a MAC address type.
  621. *
  622. * @param \Illuminate\Support\Fluent $column
  623. * @return string
  624. */
  625. protected function typeMacAddress(Fluent $column)
  626. {
  627. return 'macaddr';
  628. }
  629. /**
  630. * Create the column definition for a spatial Geometry type.
  631. *
  632. * @param \Illuminate\Support\Fluent $column
  633. * @throws \RuntimeException
  634. */
  635. protected function typeGeometry(Fluent $column)
  636. {
  637. throw new RuntimeException('The database driver in use does not support the Geometry spatial column type.');
  638. }
  639. /**
  640. * Create the column definition for a spatial Point type.
  641. *
  642. * @param \Illuminate\Support\Fluent $column
  643. * @return string
  644. */
  645. protected function typePoint(Fluent $column)
  646. {
  647. return $this->formatPostGisType('point');
  648. }
  649. /**
  650. * Create the column definition for a spatial LineString type.
  651. *
  652. * @param \Illuminate\Support\Fluent $column
  653. * @return string
  654. */
  655. protected function typeLineString(Fluent $column)
  656. {
  657. return $this->formatPostGisType('linestring');
  658. }
  659. /**
  660. * Create the column definition for a spatial Polygon type.
  661. *
  662. * @param \Illuminate\Support\Fluent $column
  663. * @return string
  664. */
  665. protected function typePolygon(Fluent $column)
  666. {
  667. return $this->formatPostGisType('polygon');
  668. }
  669. /**
  670. * Create the column definition for a spatial GeometryCollection type.
  671. *
  672. * @param \Illuminate\Support\Fluent $column
  673. * @return string
  674. */
  675. protected function typeGeometryCollection(Fluent $column)
  676. {
  677. return $this->formatPostGisType('geometrycollection');
  678. }
  679. /**
  680. * Create the column definition for a spatial MultiPoint type.
  681. *
  682. * @param \Illuminate\Support\Fluent $column
  683. * @return string
  684. */
  685. protected function typeMultiPoint(Fluent $column)
  686. {
  687. return $this->formatPostGisType('multipoint');
  688. }
  689. /**
  690. * Create the column definition for a spatial MultiLineString type.
  691. *
  692. * @param \Illuminate\Support\Fluent $column
  693. * @return string
  694. */
  695. public function typeMultiLineString(Fluent $column)
  696. {
  697. return $this->formatPostGisType('multilinestring');
  698. }
  699. /**
  700. * Create the column definition for a spatial MultiPolygon type.
  701. *
  702. * @param \Illuminate\Support\Fluent $column
  703. * @return string
  704. */
  705. protected function typeMultiPolygon(Fluent $column)
  706. {
  707. return $this->formatPostGisType('multipolygon');
  708. }
  709. /**
  710. * Format the column definition for a PostGIS spatial type.
  711. *
  712. * @param string $type
  713. * @return string
  714. */
  715. private function formatPostGisType(string $type)
  716. {
  717. return "geography($type, 4326)";
  718. }
  719. /**
  720. * Get the SQL for a nullable column modifier.
  721. *
  722. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  723. * @param \Illuminate\Support\Fluent $column
  724. * @return string|null
  725. */
  726. protected function modifyNullable(Blueprint $blueprint, Fluent $column)
  727. {
  728. return $column->nullable ? ' null' : ' not null';
  729. }
  730. /**
  731. * Get the SQL for a default column modifier.
  732. *
  733. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  734. * @param \Illuminate\Support\Fluent $column
  735. * @return string|null
  736. */
  737. protected function modifyDefault(Blueprint $blueprint, Fluent $column)
  738. {
  739. if (! is_null($column->default)) {
  740. return ' default '.$this->getDefaultValue($column->default);
  741. }
  742. }
  743. /**
  744. * Get the SQL for an auto-increment column modifier.
  745. *
  746. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  747. * @param \Illuminate\Support\Fluent $column
  748. * @return string|null
  749. */
  750. protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
  751. {
  752. if (in_array($column->type, $this->serials) && $column->autoIncrement) {
  753. return ' primary key';
  754. }
  755. }
  756. }