Skip to content

Commit e9aa383

Browse files
[11.x] Add binary type and other enhancements on migartions (#9449)
* Update migrations.md * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent bc56f6d commit e9aa383

File tree

1 file changed

+47
-25
lines changed

1 file changed

+47
-25
lines changed

migrations.md

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,12 @@ The `binary` method creates a `BLOB` equivalent column:
479479

480480
$table->binary('photo');
481481

482+
When utilizing MySQL, MariaDB, or SQL Server, you may pass `length` and `fixed` arguments to create `VARBINARY` or `BINARY` equivalent column:
483+
484+
$table->binary('data', length: 16); // VARBINARY(16)
485+
486+
$table->binary('data', length: 16, fixed: true); // BINARY(16)
487+
482488
<a name="column-method-boolean"></a>
483489
#### `boolean()` {.collection-method}
484490

@@ -491,21 +497,21 @@ The `boolean` method creates a `BOOLEAN` equivalent column:
491497

492498
The `char` method creates a `CHAR` equivalent column with of a given length:
493499

494-
$table->char('name', 100);
500+
$table->char('name', length: 100);
495501

496502
<a name="column-method-dateTimeTz"></a>
497503
#### `dateTimeTz()` {.collection-method}
498504

499-
The `dateTimeTz` method creates a `DATETIME` (with timezone) equivalent column with an optional precision (total digits):
505+
The `dateTimeTz` method creates a `DATETIME` (with timezone) equivalent column with an optional fractional seconds precision:
500506

501-
$table->dateTimeTz('created_at', $precision = 0);
507+
$table->dateTimeTz('created_at', precision: 0);
502508

503509
<a name="column-method-dateTime"></a>
504510
#### `dateTime()` {.collection-method}
505511

506-
The `dateTime` method creates a `DATETIME` equivalent column with an optional precision (total digits):
512+
The `dateTime` method creates a `DATETIME` equivalent column with an optional fractional seconds precision:
507513

508-
$table->dateTime('created_at', $precision = 0);
514+
$table->dateTime('created_at', precision: 0);
509515

510516
<a name="column-method-date"></a>
511517
#### `date()` {.collection-method}
@@ -519,7 +525,7 @@ The `date` method creates a `DATE` equivalent column:
519525

520526
The `decimal` method creates a `DECIMAL` equivalent column with the given precision (total digits) and scale (decimal digits):
521527

522-
$table->decimal('amount', $precision = 8, $scale = 2);
528+
$table->decimal('amount', total: 8, places: 2);
523529

524530
<a name="column-method-double"></a>
525531
#### `double()` {.collection-method}
@@ -540,7 +546,7 @@ The `enum` method creates a `ENUM` equivalent column with the given valid values
540546

541547
The `float` method creates a `FLOAT` equivalent column with the given precision:
542548

543-
$table->float('amount', $precision = 53);
549+
$table->float('amount', precision: 53);
544550

545551
<a name="column-method-foreignId"></a>
546552
#### `foreignId()` {.collection-method}
@@ -641,6 +647,10 @@ The `longText` method creates a `LONGTEXT` equivalent column:
641647

642648
$table->longText('description');
643649

650+
When utilizing MySQL or MariaDB, you may apply a `binary` character set to the column in order to create a `LONGBLOB` equivalent column:
651+
652+
$table->longText('data')->charset('binary'); // LONGBLOB
653+
644654
<a name="column-method-macAddress"></a>
645655
#### `macAddress()` {.collection-method}
646656

@@ -669,6 +679,10 @@ The `mediumText` method creates a `MEDIUMTEXT` equivalent column:
669679

670680
$table->mediumText('description');
671681

682+
When utilizing MySQL or MariaDB, you may apply a `binary` character set to the column in order to create a `MEDIUMBLOB` equivalent column:
683+
684+
$table->mediumText('data')->charset('binary'); // MEDIUMBLOB
685+
672686
<a name="column-method-morphs"></a>
673687
#### `morphs()` {.collection-method}
674688

@@ -683,7 +697,7 @@ This method is intended to be used when defining the columns necessary for a pol
683697

684698
The `nullableTimestamps` method is an alias of the [timestamps](#column-method-timestamps) method:
685699

686-
$table->nullableTimestamps(0);
700+
$table->nullableTimestamps(precision: 0);
687701

688702
<a name="column-method-nullableMorphs"></a>
689703
#### `nullableMorphs()` {.collection-method}
@@ -737,23 +751,23 @@ The `smallInteger` method creates a `SMALLINT` equivalent column:
737751
<a name="column-method-softDeletesTz"></a>
738752
#### `softDeletesTz()` {.collection-method}
739753

740-
The `softDeletesTz` method adds a nullable `deleted_at` `TIMESTAMP` (with timezone) equivalent column with an optional precision (total digits). This column is intended to store the `deleted_at` timestamp needed for Eloquent's "soft delete" functionality:
754+
The `softDeletesTz` method adds a nullable `deleted_at` `TIMESTAMP` (with timezone) equivalent column with an optional fractional seconds precision. This column is intended to store the `deleted_at` timestamp needed for Eloquent's "soft delete" functionality:
741755

742-
$table->softDeletesTz($column = 'deleted_at', $precision = 0);
756+
$table->softDeletesTz('deleted_at', precision: 0);
743757

744758
<a name="column-method-softDeletes"></a>
745759
#### `softDeletes()` {.collection-method}
746760

747-
The `softDeletes` method adds a nullable `deleted_at` `TIMESTAMP` equivalent column with an optional precision (total digits). This column is intended to store the `deleted_at` timestamp needed for Eloquent's "soft delete" functionality:
761+
The `softDeletes` method adds a nullable `deleted_at` `TIMESTAMP` equivalent column with an optional fractional seconds precision. This column is intended to store the `deleted_at` timestamp needed for Eloquent's "soft delete" functionality:
748762

749-
$table->softDeletes($column = 'deleted_at', $precision = 0);
763+
$table->softDeletes('deleted_at', precision: 0);
750764

751765
<a name="column-method-string"></a>
752766
#### `string()` {.collection-method}
753767

754768
The `string` method creates a `VARCHAR` equivalent column of the given length:
755769

756-
$table->string('name', 100);
770+
$table->string('name', length: 100);
757771

758772
<a name="column-method-text"></a>
759773
#### `text()` {.collection-method}
@@ -762,47 +776,51 @@ The `text` method creates a `TEXT` equivalent column:
762776

763777
$table->text('description');
764778

779+
When utilizing MySQL or MariaDB, you may apply a `binary` character set to the column in order to create a `BLOB` equivalent column:
780+
781+
$table->text('data')->charset('binary'); // BLOB
782+
765783
<a name="column-method-timeTz"></a>
766784
#### `timeTz()` {.collection-method}
767785

768-
The `timeTz` method creates a `TIME` (with timezone) equivalent column with an optional precision (total digits):
786+
The `timeTz` method creates a `TIME` (with timezone) equivalent column with an optional fractional seconds precision:
769787

770-
$table->timeTz('sunrise', $precision = 0);
788+
$table->timeTz('sunrise', precision: 0);
771789

772790
<a name="column-method-time"></a>
773791
#### `time()` {.collection-method}
774792

775-
The `time` method creates a `TIME` equivalent column with an optional precision (total digits):
793+
The `time` method creates a `TIME` equivalent column with an optional fractional seconds precision:
776794

777-
$table->time('sunrise', $precision = 0);
795+
$table->time('sunrise', precision: 0);
778796

779797
<a name="column-method-timestampTz"></a>
780798
#### `timestampTz()` {.collection-method}
781799

782-
The `timestampTz` method creates a `TIMESTAMP` (with timezone) equivalent column with an optional precision (total digits):
800+
The `timestampTz` method creates a `TIMESTAMP` (with timezone) equivalent column with an optional fractional seconds precision:
783801

784-
$table->timestampTz('added_at', $precision = 0);
802+
$table->timestampTz('added_at', precision: 0);
785803

786804
<a name="column-method-timestamp"></a>
787805
#### `timestamp()` {.collection-method}
788806

789-
The `timestamp` method creates a `TIMESTAMP` equivalent column with an optional precision (total digits):
807+
The `timestamp` method creates a `TIMESTAMP` equivalent column with an optional fractional seconds precision:
790808

791-
$table->timestamp('added_at', $precision = 0);
809+
$table->timestamp('added_at', precision: 0);
792810

793811
<a name="column-method-timestampsTz"></a>
794812
#### `timestampsTz()` {.collection-method}
795813

796-
The `timestampsTz` method creates `created_at` and `updated_at` `TIMESTAMP` (with timezone) equivalent columns with an optional precision (total digits):
814+
The `timestampsTz` method creates `created_at` and `updated_at` `TIMESTAMP` (with timezone) equivalent columns with an optional fractional seconds precision:
797815

798-
$table->timestampsTz($precision = 0);
816+
$table->timestampsTz(precision: 0);
799817

800818
<a name="column-method-timestamps"></a>
801819
#### `timestamps()` {.collection-method}
802820

803-
The `timestamps` method creates `created_at` and `updated_at` `TIMESTAMP` equivalent columns with an optional precision (total digits):
821+
The `timestamps` method creates `created_at` and `updated_at` `TIMESTAMP` equivalent columns with an optional fractional seconds precision:
804822

805-
$table->timestamps($precision = 0);
823+
$table->timestamps(precision: 0);
806824

807825
<a name="column-method-tinyIncrements"></a>
808826
#### `tinyIncrements()` {.collection-method}
@@ -825,6 +843,10 @@ The `tinyText` method creates a `TINYTEXT` equivalent column:
825843

826844
$table->tinyText('notes');
827845

846+
When utilizing MySQL or MariaDB, you may apply a `binary` character set to the column in order to create a `TINYBLOB` equivalent column:
847+
848+
$table->tinyText('data')->charset('binary'); // TINYBLOB
849+
828850
<a name="column-method-unsignedBigInteger"></a>
829851
#### `unsignedBigInteger()` {.collection-method}
830852

0 commit comments

Comments
 (0)