Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Database\Schema\Grammars;
4
 
5
use Doctrine\DBAL\Schema\Index;
6
use Illuminate\Database\Connection;
7
use Illuminate\Database\Schema\Blueprint;
8
use Illuminate\Support\Arr;
9
use Illuminate\Support\Fluent;
10
use RuntimeException;
11
 
12
class SQLiteGrammar extends Grammar
13
{
14
    /**
15
     * The possible column modifiers.
16
     *
17
     * @var string[]
18
     */
19
    protected $modifiers = ['VirtualAs', 'StoredAs', 'Nullable', 'Default', 'Increment'];
20
 
21
    /**
22
     * The columns available as serials.
23
     *
24
     * @var string[]
25
     */
26
    protected $serials = ['bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger'];
27
 
28
    /**
29
     * Compile the query to determine if a table exists.
30
     *
31
     * @return string
32
     */
33
    public function compileTableExists()
34
    {
35
        return "select * from sqlite_master where type = 'table' and name = ?";
36
    }
37
 
38
    /**
39
     * Compile the query to determine the list of columns.
40
     *
41
     * @param  string  $table
42
     * @return string
43
     */
44
    public function compileColumnListing($table)
45
    {
46
        return 'pragma table_info('.$this->wrap(str_replace('.', '__', $table)).')';
47
    }
48
 
49
    /**
50
     * Compile a create table command.
51
     *
52
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
53
     * @param  \Illuminate\Support\Fluent  $command
54
     * @return string
55
     */
56
    public function compileCreate(Blueprint $blueprint, Fluent $command)
57
    {
58
        return sprintf('%s table %s (%s%s%s)',
59
            $blueprint->temporary ? 'create temporary' : 'create',
60
            $this->wrapTable($blueprint),
61
            implode(', ', $this->getColumns($blueprint)),
62
            (string) $this->addForeignKeys($blueprint),
63
            (string) $this->addPrimaryKeys($blueprint)
64
        );
65
    }
66
 
67
    /**
68
     * Get the foreign key syntax for a table creation statement.
69
     *
70
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
71
     * @return string|null
72
     */
73
    protected function addForeignKeys(Blueprint $blueprint)
74
    {
75
        $foreigns = $this->getCommandsByName($blueprint, 'foreign');
76
 
77
        return collect($foreigns)->reduce(function ($sql, $foreign) {
78
            // Once we have all the foreign key commands for the table creation statement
79
            // we'll loop through each of them and add them to the create table SQL we
80
            // are building, since SQLite needs foreign keys on the tables creation.
81
            $sql .= $this->getForeignKey($foreign);
82
 
83
            if (! is_null($foreign->onDelete)) {
84
                $sql .= " on delete {$foreign->onDelete}";
85
            }
86
 
87
            // If this foreign key specifies the action to be taken on update we will add
88
            // that to the statement here. We'll append it to this SQL and then return
89
            // the SQL so we can keep adding any other foreign constraints onto this.
90
            if (! is_null($foreign->onUpdate)) {
91
                $sql .= " on update {$foreign->onUpdate}";
92
            }
93
 
94
            return $sql;
95
        }, '');
96
    }
97
 
98
    /**
99
     * Get the SQL for the foreign key.
100
     *
101
     * @param  \Illuminate\Support\Fluent  $foreign
102
     * @return string
103
     */
104
    protected function getForeignKey($foreign)
105
    {
106
        // We need to columnize the columns that the foreign key is being defined for
107
        // so that it is a properly formatted list. Once we have done this, we can
108
        // return the foreign key SQL declaration to the calling method for use.
109
        return sprintf(', foreign key(%s) references %s(%s)',
110
            $this->columnize($foreign->columns),
111
            $this->wrapTable($foreign->on),
112
            $this->columnize((array) $foreign->references)
113
        );
114
    }
115
 
116
    /**
117
     * Get the primary key syntax for a table creation statement.
118
     *
119
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
120
     * @return string|null
121
     */
122
    protected function addPrimaryKeys(Blueprint $blueprint)
123
    {
124
        if (! is_null($primary = $this->getCommandByName($blueprint, 'primary'))) {
125
            return ", primary key ({$this->columnize($primary->columns)})";
126
        }
127
    }
128
 
129
    /**
130
     * Compile alter table commands for adding columns.
131
     *
132
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
133
     * @param  \Illuminate\Support\Fluent  $command
134
     * @return array
135
     */
136
    public function compileAdd(Blueprint $blueprint, Fluent $command)
137
    {
138
        $columns = $this->prefixArray('add column', $this->getColumns($blueprint));
139
 
140
        return collect($columns)->reject(function ($column) {
141
            return preg_match('/as \(.*\) stored/', $column) > 0;
142
        })->map(function ($column) use ($blueprint) {
143
            return 'alter table '.$this->wrapTable($blueprint).' '.$column;
144
        })->all();
145
    }
146
 
147
    /**
148
     * Compile a rename column command.
149
     *
150
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
151
     * @param  \Illuminate\Support\Fluent  $command
152
     * @param  \Illuminate\Database\Connection  $connection
153
     * @return array|string
154
     */
155
    public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
156
    {
157
        return $connection->usingNativeSchemaOperations()
158
            ? sprintf('alter table %s rename column %s to %s',
159
                $this->wrapTable($blueprint),
160
                $this->wrap($command->from),
161
                $this->wrap($command->to)
162
            )
163
            : parent::compileRenameColumn($blueprint, $command, $connection);
164
    }
165
 
166
    /**
167
     * Compile a unique key command.
168
     *
169
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
170
     * @param  \Illuminate\Support\Fluent  $command
171
     * @return string
172
     */
173
    public function compileUnique(Blueprint $blueprint, Fluent $command)
174
    {
175
        return sprintf('create unique index %s on %s (%s)',
176
            $this->wrap($command->index),
177
            $this->wrapTable($blueprint),
178
            $this->columnize($command->columns)
179
        );
180
    }
181
 
182
    /**
183
     * Compile a plain index key command.
184
     *
185
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
186
     * @param  \Illuminate\Support\Fluent  $command
187
     * @return string
188
     */
189
    public function compileIndex(Blueprint $blueprint, Fluent $command)
190
    {
191
        return sprintf('create index %s on %s (%s)',
192
            $this->wrap($command->index),
193
            $this->wrapTable($blueprint),
194
            $this->columnize($command->columns)
195
        );
196
    }
197
 
198
    /**
199
     * Compile a spatial index key command.
200
     *
201
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
202
     * @param  \Illuminate\Support\Fluent  $command
203
     * @return void
204
     *
205
     * @throws \RuntimeException
206
     */
207
    public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)
208
    {
209
        throw new RuntimeException('The database driver in use does not support spatial indexes.');
210
    }
211
 
212
    /**
213
     * Compile a foreign key command.
214
     *
215
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
216
     * @param  \Illuminate\Support\Fluent  $command
217
     * @return string
218
     */
219
    public function compileForeign(Blueprint $blueprint, Fluent $command)
220
    {
221
        // Handled on table creation...
222
    }
223
 
224
    /**
225
     * Compile a drop table command.
226
     *
227
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
228
     * @param  \Illuminate\Support\Fluent  $command
229
     * @return string
230
     */
231
    public function compileDrop(Blueprint $blueprint, Fluent $command)
232
    {
233
        return 'drop table '.$this->wrapTable($blueprint);
234
    }
235
 
236
    /**
237
     * Compile a drop table (if exists) command.
238
     *
239
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
240
     * @param  \Illuminate\Support\Fluent  $command
241
     * @return string
242
     */
243
    public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
244
    {
245
        return 'drop table if exists '.$this->wrapTable($blueprint);
246
    }
247
 
248
    /**
249
     * Compile the SQL needed to drop all tables.
250
     *
251
     * @return string
252
     */
253
    public function compileDropAllTables()
254
    {
255
        return "delete from sqlite_master where type in ('table', 'index', 'trigger')";
256
    }
257
 
258
    /**
259
     * Compile the SQL needed to drop all views.
260
     *
261
     * @return string
262
     */
263
    public function compileDropAllViews()
264
    {
265
        return "delete from sqlite_master where type in ('view')";
266
    }
267
 
268
    /**
269
     * Compile the SQL needed to retrieve all table names.
270
     *
271
     * @return string
272
     */
273
    public function compileGetAllTables()
274
    {
275
        return 'select type, name from sqlite_master where type = \'table\' and name not like \'sqlite_%\'';
276
    }
277
 
278
    /**
279
     * Compile the SQL needed to retrieve all view names.
280
     *
281
     * @return string
282
     */
283
    public function compileGetAllViews()
284
    {
285
        return 'select type, name from sqlite_master where type = \'view\'';
286
    }
287
 
288
    /**
289
     * Compile the SQL needed to rebuild the database.
290
     *
291
     * @return string
292
     */
293
    public function compileRebuild()
294
    {
295
        return 'vacuum';
296
    }
297
 
298
    /**
299
     * Compile a drop column 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 compileDropColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
307
    {
308
        if ($connection->usingNativeSchemaOperations()) {
309
            $table = $this->wrapTable($blueprint);
310
 
311
            $columns = $this->prefixArray('drop column', $this->wrapArray($command->columns));
312
 
313
            return collect($columns)->map(fn ($column) => 'alter table '.$table.' '.$column
314
            )->all();
315
        } else {
316
            $tableDiff = $this->getDoctrineTableDiff(
317
                $blueprint, $schema = $connection->getDoctrineSchemaManager()
318
            );
319
 
320
            foreach ($command->columns as $name) {
321
                $tableDiff->removedColumns[$name] = $connection->getDoctrineColumn(
322
                    $this->getTablePrefix().$blueprint->getTable(), $name
323
                );
324
            }
325
 
326
            return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff);
327
        }
328
    }
329
 
330
    /**
331
     * Compile a drop unique key command.
332
     *
333
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
334
     * @param  \Illuminate\Support\Fluent  $command
335
     * @return string
336
     */
337
    public function compileDropUnique(Blueprint $blueprint, Fluent $command)
338
    {
339
        $index = $this->wrap($command->index);
340
 
341
        return "drop index {$index}";
342
    }
343
 
344
    /**
345
     * Compile a drop index command.
346
     *
347
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
348
     * @param  \Illuminate\Support\Fluent  $command
349
     * @return string
350
     */
351
    public function compileDropIndex(Blueprint $blueprint, Fluent $command)
352
    {
353
        $index = $this->wrap($command->index);
354
 
355
        return "drop index {$index}";
356
    }
357
 
358
    /**
359
     * Compile a drop spatial index command.
360
     *
361
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
362
     * @param  \Illuminate\Support\Fluent  $command
363
     * @return void
364
     *
365
     * @throws \RuntimeException
366
     */
367
    public function compileDropSpatialIndex(Blueprint $blueprint, Fluent $command)
368
    {
369
        throw new RuntimeException('The database driver in use does not support spatial indexes.');
370
    }
371
 
372
    /**
373
     * Compile a rename table command.
374
     *
375
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
376
     * @param  \Illuminate\Support\Fluent  $command
377
     * @return string
378
     */
379
    public function compileRename(Blueprint $blueprint, Fluent $command)
380
    {
381
        $from = $this->wrapTable($blueprint);
382
 
383
        return "alter table {$from} rename to ".$this->wrapTable($command->to);
384
    }
385
 
386
    /**
387
     * Compile a rename index command.
388
     *
389
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
390
     * @param  \Illuminate\Support\Fluent  $command
391
     * @param  \Illuminate\Database\Connection  $connection
392
     * @return array
393
     *
394
     * @throws \RuntimeException
395
     */
396
    public function compileRenameIndex(Blueprint $blueprint, Fluent $command, Connection $connection)
397
    {
398
        $schemaManager = $connection->getDoctrineSchemaManager();
399
 
400
        $indexes = $schemaManager->listTableIndexes($this->getTablePrefix().$blueprint->getTable());
401
 
402
        $index = Arr::get($indexes, $command->from);
403
 
404
        if (! $index) {
405
            throw new RuntimeException("Index [{$command->from}] does not exist.");
406
        }
407
 
408
        $newIndex = new Index(
409
            $command->to, $index->getColumns(), $index->isUnique(),
410
            $index->isPrimary(), $index->getFlags(), $index->getOptions()
411
        );
412
 
413
        $platform = $schemaManager->getDatabasePlatform();
414
 
415
        return [
416
            $platform->getDropIndexSQL($command->from, $this->getTablePrefix().$blueprint->getTable()),
417
            $platform->getCreateIndexSQL($newIndex, $this->getTablePrefix().$blueprint->getTable()),
418
        ];
419
    }
420
 
421
    /**
422
     * Compile the command to enable foreign key constraints.
423
     *
424
     * @return string
425
     */
426
    public function compileEnableForeignKeyConstraints()
427
    {
428
        return 'PRAGMA foreign_keys = ON;';
429
    }
430
 
431
    /**
432
     * Compile the command to disable foreign key constraints.
433
     *
434
     * @return string
435
     */
436
    public function compileDisableForeignKeyConstraints()
437
    {
438
        return 'PRAGMA foreign_keys = OFF;';
439
    }
440
 
441
    /**
442
     * Compile the SQL needed to enable a writable schema.
443
     *
444
     * @return string
445
     */
446
    public function compileEnableWriteableSchema()
447
    {
448
        return 'PRAGMA writable_schema = 1;';
449
    }
450
 
451
    /**
452
     * Compile the SQL needed to disable a writable schema.
453
     *
454
     * @return string
455
     */
456
    public function compileDisableWriteableSchema()
457
    {
458
        return 'PRAGMA writable_schema = 0;';
459
    }
460
 
461
    /**
462
     * Create the column definition for a char type.
463
     *
464
     * @param  \Illuminate\Support\Fluent  $column
465
     * @return string
466
     */
467
    protected function typeChar(Fluent $column)
468
    {
469
        return 'varchar';
470
    }
471
 
472
    /**
473
     * Create the column definition for a string type.
474
     *
475
     * @param  \Illuminate\Support\Fluent  $column
476
     * @return string
477
     */
478
    protected function typeString(Fluent $column)
479
    {
480
        return 'varchar';
481
    }
482
 
483
    /**
484
     * Create the column definition for a tiny text type.
485
     *
486
     * @param  \Illuminate\Support\Fluent  $column
487
     * @return string
488
     */
489
    protected function typeTinyText(Fluent $column)
490
    {
491
        return 'text';
492
    }
493
 
494
    /**
495
     * Create the column definition for a text type.
496
     *
497
     * @param  \Illuminate\Support\Fluent  $column
498
     * @return string
499
     */
500
    protected function typeText(Fluent $column)
501
    {
502
        return 'text';
503
    }
504
 
505
    /**
506
     * Create the column definition for a medium text type.
507
     *
508
     * @param  \Illuminate\Support\Fluent  $column
509
     * @return string
510
     */
511
    protected function typeMediumText(Fluent $column)
512
    {
513
        return 'text';
514
    }
515
 
516
    /**
517
     * Create the column definition for a long text type.
518
     *
519
     * @param  \Illuminate\Support\Fluent  $column
520
     * @return string
521
     */
522
    protected function typeLongText(Fluent $column)
523
    {
524
        return 'text';
525
    }
526
 
527
    /**
528
     * Create the column definition for an integer type.
529
     *
530
     * @param  \Illuminate\Support\Fluent  $column
531
     * @return string
532
     */
533
    protected function typeInteger(Fluent $column)
534
    {
535
        return 'integer';
536
    }
537
 
538
    /**
539
     * Create the column definition for a big integer type.
540
     *
541
     * @param  \Illuminate\Support\Fluent  $column
542
     * @return string
543
     */
544
    protected function typeBigInteger(Fluent $column)
545
    {
546
        return 'integer';
547
    }
548
 
549
    /**
550
     * Create the column definition for a medium integer type.
551
     *
552
     * @param  \Illuminate\Support\Fluent  $column
553
     * @return string
554
     */
555
    protected function typeMediumInteger(Fluent $column)
556
    {
557
        return 'integer';
558
    }
559
 
560
    /**
561
     * Create the column definition for a tiny integer type.
562
     *
563
     * @param  \Illuminate\Support\Fluent  $column
564
     * @return string
565
     */
566
    protected function typeTinyInteger(Fluent $column)
567
    {
568
        return 'integer';
569
    }
570
 
571
    /**
572
     * Create the column definition for a small integer type.
573
     *
574
     * @param  \Illuminate\Support\Fluent  $column
575
     * @return string
576
     */
577
    protected function typeSmallInteger(Fluent $column)
578
    {
579
        return 'integer';
580
    }
581
 
582
    /**
583
     * Create the column definition for a float type.
584
     *
585
     * @param  \Illuminate\Support\Fluent  $column
586
     * @return string
587
     */
588
    protected function typeFloat(Fluent $column)
589
    {
590
        return 'float';
591
    }
592
 
593
    /**
594
     * Create the column definition for a double type.
595
     *
596
     * @param  \Illuminate\Support\Fluent  $column
597
     * @return string
598
     */
599
    protected function typeDouble(Fluent $column)
600
    {
601
        return 'float';
602
    }
603
 
604
    /**
605
     * Create the column definition for a decimal type.
606
     *
607
     * @param  \Illuminate\Support\Fluent  $column
608
     * @return string
609
     */
610
    protected function typeDecimal(Fluent $column)
611
    {
612
        return 'numeric';
613
    }
614
 
615
    /**
616
     * Create the column definition for a boolean type.
617
     *
618
     * @param  \Illuminate\Support\Fluent  $column
619
     * @return string
620
     */
621
    protected function typeBoolean(Fluent $column)
622
    {
623
        return 'tinyint(1)';
624
    }
625
 
626
    /**
627
     * Create the column definition for an enumeration type.
628
     *
629
     * @param  \Illuminate\Support\Fluent  $column
630
     * @return string
631
     */
632
    protected function typeEnum(Fluent $column)
633
    {
634
        return sprintf(
635
            'varchar check ("%s" in (%s))',
636
            $column->name,
637
            $this->quoteString($column->allowed)
638
        );
639
    }
640
 
641
    /**
642
     * Create the column definition for a json type.
643
     *
644
     * @param  \Illuminate\Support\Fluent  $column
645
     * @return string
646
     */
647
    protected function typeJson(Fluent $column)
648
    {
649
        return 'text';
650
    }
651
 
652
    /**
653
     * Create the column definition for a jsonb type.
654
     *
655
     * @param  \Illuminate\Support\Fluent  $column
656
     * @return string
657
     */
658
    protected function typeJsonb(Fluent $column)
659
    {
660
        return 'text';
661
    }
662
 
663
    /**
664
     * Create the column definition for a date type.
665
     *
666
     * @param  \Illuminate\Support\Fluent  $column
667
     * @return string
668
     */
669
    protected function typeDate(Fluent $column)
670
    {
671
        return 'date';
672
    }
673
 
674
    /**
675
     * Create the column definition for a date-time type.
676
     *
677
     * @param  \Illuminate\Support\Fluent  $column
678
     * @return string
679
     */
680
    protected function typeDateTime(Fluent $column)
681
    {
682
        return $this->typeTimestamp($column);
683
    }
684
 
685
    /**
686
     * Create the column definition for a date-time (with time zone) type.
687
     *
688
     * Note: "SQLite does not have a storage class set aside for storing dates and/or times."
689
     *
690
     * @link https://www.sqlite.org/datatype3.html
691
     *
692
     * @param  \Illuminate\Support\Fluent  $column
693
     * @return string
694
     */
695
    protected function typeDateTimeTz(Fluent $column)
696
    {
697
        return $this->typeDateTime($column);
698
    }
699
 
700
    /**
701
     * Create the column definition for a time type.
702
     *
703
     * @param  \Illuminate\Support\Fluent  $column
704
     * @return string
705
     */
706
    protected function typeTime(Fluent $column)
707
    {
708
        return 'time';
709
    }
710
 
711
    /**
712
     * Create the column definition for a time (with time zone) type.
713
     *
714
     * @param  \Illuminate\Support\Fluent  $column
715
     * @return string
716
     */
717
    protected function typeTimeTz(Fluent $column)
718
    {
719
        return $this->typeTime($column);
720
    }
721
 
722
    /**
723
     * Create the column definition for a timestamp type.
724
     *
725
     * @param  \Illuminate\Support\Fluent  $column
726
     * @return string
727
     */
728
    protected function typeTimestamp(Fluent $column)
729
    {
730
        return $column->useCurrent ? 'datetime default CURRENT_TIMESTAMP' : 'datetime';
731
    }
732
 
733
    /**
734
     * Create the column definition for a timestamp (with time zone) type.
735
     *
736
     * @param  \Illuminate\Support\Fluent  $column
737
     * @return string
738
     */
739
    protected function typeTimestampTz(Fluent $column)
740
    {
741
        return $this->typeTimestamp($column);
742
    }
743
 
744
    /**
745
     * Create the column definition for a year type.
746
     *
747
     * @param  \Illuminate\Support\Fluent  $column
748
     * @return string
749
     */
750
    protected function typeYear(Fluent $column)
751
    {
752
        return $this->typeInteger($column);
753
    }
754
 
755
    /**
756
     * Create the column definition for a binary type.
757
     *
758
     * @param  \Illuminate\Support\Fluent  $column
759
     * @return string
760
     */
761
    protected function typeBinary(Fluent $column)
762
    {
763
        return 'blob';
764
    }
765
 
766
    /**
767
     * Create the column definition for a uuid type.
768
     *
769
     * @param  \Illuminate\Support\Fluent  $column
770
     * @return string
771
     */
772
    protected function typeUuid(Fluent $column)
773
    {
774
        return 'varchar';
775
    }
776
 
777
    /**
778
     * Create the column definition for an IP address type.
779
     *
780
     * @param  \Illuminate\Support\Fluent  $column
781
     * @return string
782
     */
783
    protected function typeIpAddress(Fluent $column)
784
    {
785
        return 'varchar';
786
    }
787
 
788
    /**
789
     * Create the column definition for a MAC address type.
790
     *
791
     * @param  \Illuminate\Support\Fluent  $column
792
     * @return string
793
     */
794
    protected function typeMacAddress(Fluent $column)
795
    {
796
        return 'varchar';
797
    }
798
 
799
    /**
800
     * Create the column definition for a spatial Geometry type.
801
     *
802
     * @param  \Illuminate\Support\Fluent  $column
803
     * @return string
804
     */
805
    public function typeGeometry(Fluent $column)
806
    {
807
        return 'geometry';
808
    }
809
 
810
    /**
811
     * Create the column definition for a spatial Point type.
812
     *
813
     * @param  \Illuminate\Support\Fluent  $column
814
     * @return string
815
     */
816
    public function typePoint(Fluent $column)
817
    {
818
        return 'point';
819
    }
820
 
821
    /**
822
     * Create the column definition for a spatial LineString type.
823
     *
824
     * @param  \Illuminate\Support\Fluent  $column
825
     * @return string
826
     */
827
    public function typeLineString(Fluent $column)
828
    {
829
        return 'linestring';
830
    }
831
 
832
    /**
833
     * Create the column definition for a spatial Polygon type.
834
     *
835
     * @param  \Illuminate\Support\Fluent  $column
836
     * @return string
837
     */
838
    public function typePolygon(Fluent $column)
839
    {
840
        return 'polygon';
841
    }
842
 
843
    /**
844
     * Create the column definition for a spatial GeometryCollection type.
845
     *
846
     * @param  \Illuminate\Support\Fluent  $column
847
     * @return string
848
     */
849
    public function typeGeometryCollection(Fluent $column)
850
    {
851
        return 'geometrycollection';
852
    }
853
 
854
    /**
855
     * Create the column definition for a spatial MultiPoint type.
856
     *
857
     * @param  \Illuminate\Support\Fluent  $column
858
     * @return string
859
     */
860
    public function typeMultiPoint(Fluent $column)
861
    {
862
        return 'multipoint';
863
    }
864
 
865
    /**
866
     * Create the column definition for a spatial MultiLineString type.
867
     *
868
     * @param  \Illuminate\Support\Fluent  $column
869
     * @return string
870
     */
871
    public function typeMultiLineString(Fluent $column)
872
    {
873
        return 'multilinestring';
874
    }
875
 
876
    /**
877
     * Create the column definition for a spatial MultiPolygon type.
878
     *
879
     * @param  \Illuminate\Support\Fluent  $column
880
     * @return string
881
     */
882
    public function typeMultiPolygon(Fluent $column)
883
    {
884
        return 'multipolygon';
885
    }
886
 
887
    /**
888
     * Create the column definition for a generated, computed column type.
889
     *
890
     * @param  \Illuminate\Support\Fluent  $column
891
     * @return void
892
     *
893
     * @throws \RuntimeException
894
     */
895
    protected function typeComputed(Fluent $column)
896
    {
897
        throw new RuntimeException('This database driver requires a type, see the virtualAs / storedAs modifiers.');
898
    }
899
 
900
    /**
901
     * Get the SQL for a generated virtual column modifier.
902
     *
903
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
904
     * @param  \Illuminate\Support\Fluent  $column
905
     * @return string|null
906
     */
907
    protected function modifyVirtualAs(Blueprint $blueprint, Fluent $column)
908
    {
909
        if (! is_null($virtualAs = $column->virtualAsJson)) {
910
            if ($this->isJsonSelector($virtualAs)) {
911
                $virtualAs = $this->wrapJsonSelector($virtualAs);
912
            }
913
 
914
            return " as ({$virtualAs})";
915
        }
916
 
917
        if (! is_null($virtualAs = $column->virtualAs)) {
918
            return " as ({$virtualAs})";
919
        }
920
    }
921
 
922
    /**
923
     * Get the SQL for a generated stored column modifier.
924
     *
925
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
926
     * @param  \Illuminate\Support\Fluent  $column
927
     * @return string|null
928
     */
929
    protected function modifyStoredAs(Blueprint $blueprint, Fluent $column)
930
    {
931
        if (! is_null($storedAs = $column->storedAsJson)) {
932
            if ($this->isJsonSelector($storedAs)) {
933
                $storedAs = $this->wrapJsonSelector($storedAs);
934
            }
935
 
936
            return " as ({$storedAs}) stored";
937
        }
938
 
939
        if (! is_null($storedAs = $column->storedAs)) {
940
            return " as ({$column->storedAs}) stored";
941
        }
942
    }
943
 
944
    /**
945
     * Get the SQL for a nullable column modifier.
946
     *
947
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
948
     * @param  \Illuminate\Support\Fluent  $column
949
     * @return string|null
950
     */
951
    protected function modifyNullable(Blueprint $blueprint, Fluent $column)
952
    {
953
        if (is_null($column->virtualAs) &&
954
            is_null($column->virtualAsJson) &&
955
            is_null($column->storedAs) &&
956
            is_null($column->storedAsJson)) {
957
            return $column->nullable ? '' : ' not null';
958
        }
959
 
960
        if ($column->nullable === false) {
961
            return ' not null';
962
        }
963
    }
964
 
965
    /**
966
     * Get the SQL for a default column modifier.
967
     *
968
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
969
     * @param  \Illuminate\Support\Fluent  $column
970
     * @return string|null
971
     */
972
    protected function modifyDefault(Blueprint $blueprint, Fluent $column)
973
    {
974
        if (! is_null($column->default) && is_null($column->virtualAs) && is_null($column->virtualAsJson) && is_null($column->storedAs)) {
975
            return ' default '.$this->getDefaultValue($column->default);
976
        }
977
    }
978
 
979
    /**
980
     * Get the SQL for an auto-increment column modifier.
981
     *
982
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
983
     * @param  \Illuminate\Support\Fluent  $column
984
     * @return string|null
985
     */
986
    protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
987
    {
988
        if (in_array($column->type, $this->serials) && $column->autoIncrement) {
989
            return ' primary key autoincrement';
990
        }
991
    }
992
 
993
    /**
994
     * Wrap the given JSON selector.
995
     *
996
     * @param  string  $value
997
     * @return string
998
     */
999
    protected function wrapJsonSelector($value)
1000
    {
1001
        [$field, $path] = $this->wrapJsonFieldAndPath($value);
1002
 
1003
        return 'json_extract('.$field.$path.')';
1004
    }
1005
}