SQLiteGrammar.php 22 KB

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