From e14ca82d8b37416fb24bbe321a029bf037d9f1bf Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Tue, 17 Jan 2023 04:21:08 +0330 Subject: [PATCH 1/3] Update migrations.md --- migrations.md | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/migrations.md b/migrations.md index 1bb2f509faf..144fd15260e 100644 --- a/migrations.md +++ b/migrations.md @@ -9,7 +9,8 @@ - [Tables](#tables) - [Creating Tables](#creating-tables) - [Updating Tables](#updating-tables) - - [Renaming / Dropping Tables](#renaming-and-dropping-tables) + - [Renaming Tables](#renaming-tables) + - [Dropping Tables](#dropping-tables) - [Columns](#columns) - [Creating Columns](#creating-columns) - [Available Column Types](#available-column-types) @@ -319,8 +320,8 @@ The `table` method on the `Schema` facade may be used to update existing tables. $table->integer('votes'); }); - -### Renaming / Dropping Tables + +### Renaming Tables To rename an existing database table, use the `rename` method: @@ -328,6 +329,9 @@ To rename an existing database table, use the `rename` method: Schema::rename($from, $to); + +### Dropping Tables + To drop an existing table, you may use the `drop` or `dropIfExists` methods: Schema::drop('users'); @@ -998,7 +1002,7 @@ The `default` modifier accepts a value or an `Illuminate\Database\Query\Expressi }; > **Warning** -> Support for default expressions depends on your database driver, database version, and the field type. Please refer to your database's documentation. In addition, it is not possible to combine raw `default` expressions (using `DB::raw`) with column changes via the `change` method. +> Support for default expressions depends on your database driver, database version, and the field type. Please refer to your database's documentation. #### Column Order @@ -1014,10 +1018,22 @@ When using the MySQL database, the `after` method may be used to add columns aft ### Modifying Columns - -#### Prerequisites +The `change` method allows you to modify the type and attributes of existing columns. For example, you may wish to increase the size of a `string` column. To see the `change` method in action, let's increase the size of the `name` column from 25 to 50. To accomplish this, we simply define the new state of the column and then call the `change` method: -Before modifying a column, you must install the `doctrine/dbal` package using the Composer package manager. The Doctrine DBAL library is used to determine the current state of the column and to create the SQL queries needed to make the requested changes to your column: + Schema::table('users', function (Blueprint $table) { + $table->string('name', 50)->change(); + }); + +You must include all modifers you want to keep on the column definition explicitly. Any missing attribute will be dropped. For example, to retain nullable, default, and comment attributes, call each modifier explicitly: + + Schema::table('users', function (Blueprint $table) { + $table->integer('votes')->unsigned()->default(1)->comment('my comment')->change(); + }); + + +#### Modifying Columns On SQLite + +If your application is utilizing an SQLite database, you must install the `doctrine/dbal` package using the Composer package manager before modifying a column. The Doctrine DBAL library is used to determine the current state of the column and to create the SQL queries needed to make the requested changes to your column: composer require doctrine/dbal @@ -1034,25 +1050,7 @@ use Illuminate\Database\DBAL\TimestampType; ``` > **Warning** -> If your application is using Microsoft SQL Server, please ensure that you install `doctrine/dbal:^3.0`. - - -#### Updating Column Attributes - -The `change` method allows you to modify the type and attributes of existing columns. For example, you may wish to increase the size of a `string` column. To see the `change` method in action, let's increase the size of the `name` column from 25 to 50. To accomplish this, we simply define the new state of the column and then call the `change` method: - - Schema::table('users', function (Blueprint $table) { - $table->string('name', 50)->change(); - }); - -We could also modify a column to be nullable: - - Schema::table('users', function (Blueprint $table) { - $table->string('name', 50)->nullable()->change(); - }); - -> **Warning** -> The following column types can be modified: `bigInteger`, `binary`, `boolean`, `char`, `date`, `dateTime`, `dateTimeTz`, `decimal`, `double`, `integer`, `json`, `longText`, `mediumText`, `smallInteger`, `string`, `text`, `time`, `tinyText`, `unsignedBigInteger`, `unsignedInteger`, `unsignedSmallInteger`, and `uuid`. To modify a `timestamp` column type a [Doctrine type must be registered](#prerequisites). +> When using `doctrine/dbal` package, the following column types can be modified: `bigInteger`, `binary`, `boolean`, `char`, `date`, `dateTime`, `dateTimeTz`, `decimal`, `double`, `integer`, `json`, `longText`, `mediumText`, `smallInteger`, `string`, `text`, `time`, `tinyText`, `unsignedBigInteger`, `unsignedInteger`, `unsignedSmallInteger`, `ulid`, and `uuid`. To modify a `timestamp` column type a Doctrine type must be registered. ### Renaming Columns @@ -1091,7 +1089,6 @@ You may drop multiple columns from a table by passing an array of column names t $table->dropColumn(['votes', 'avatar', 'location']); }); - #### Dropping Columns On Legacy Databases From 083fef5c50a40854987de33566fc5bcff6d1c1a3 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Thu, 9 Feb 2023 17:36:55 +0330 Subject: [PATCH 2/3] Update migrations.md --- migrations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations.md b/migrations.md index 144fd15260e..72dd1301ec5 100644 --- a/migrations.md +++ b/migrations.md @@ -1024,7 +1024,7 @@ The `change` method allows you to modify the type and attributes of existing col $table->string('name', 50)->change(); }); -You must include all modifers you want to keep on the column definition explicitly. Any missing attribute will be dropped. For example, to retain nullable, default, and comment attributes, call each modifier explicitly: +You must include all modifers you want to keep on the column definition explicitly. Any missing attribute will be dropped. For example, to retain unsigned, default, and comment attributes, call each modifier explicitly: Schema::table('users', function (Blueprint $table) { $table->integer('votes')->unsigned()->default(1)->comment('my comment')->change(); From 253679c81460ba7b9fab9ba6354ecf9359407edc Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 10 Feb 2023 16:16:36 -0600 Subject: [PATCH 3/3] formatting --- migrations.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/migrations.md b/migrations.md index 72dd1301ec5..45f78ac42a2 100644 --- a/migrations.md +++ b/migrations.md @@ -9,8 +9,7 @@ - [Tables](#tables) - [Creating Tables](#creating-tables) - [Updating Tables](#updating-tables) - - [Renaming Tables](#renaming-tables) - - [Dropping Tables](#dropping-tables) + - [Renaming / Dropping Tables](#renaming-and-dropping-tables) - [Columns](#columns) - [Creating Columns](#creating-columns) - [Available Column Types](#available-column-types) @@ -320,8 +319,8 @@ The `table` method on the `Schema` facade may be used to update existing tables. $table->integer('votes'); }); - -### Renaming Tables + +### Renaming / Dropping Tables To rename an existing database table, use the `rename` method: @@ -329,9 +328,6 @@ To rename an existing database table, use the `rename` method: Schema::rename($from, $to); - -### Dropping Tables - To drop an existing table, you may use the `drop` or `dropIfExists` methods: Schema::drop('users'); @@ -1024,7 +1020,7 @@ The `change` method allows you to modify the type and attributes of existing col $table->string('name', 50)->change(); }); -You must include all modifers you want to keep on the column definition explicitly. Any missing attribute will be dropped. For example, to retain unsigned, default, and comment attributes, call each modifier explicitly: +When modifying a column, you must explicitly include all of the modifiers you want to keep on the column definition - any missing attribute will be dropped. For example, to retain the `unsigned`, `default`, and `comment` attributes, you must call each modifier explicitly when changing the column: Schema::table('users', function (Blueprint $table) { $table->integer('votes')->unsigned()->default(1)->comment('my comment')->change(); @@ -1050,7 +1046,7 @@ use Illuminate\Database\DBAL\TimestampType; ``` > **Warning** -> When using `doctrine/dbal` package, the following column types can be modified: `bigInteger`, `binary`, `boolean`, `char`, `date`, `dateTime`, `dateTimeTz`, `decimal`, `double`, `integer`, `json`, `longText`, `mediumText`, `smallInteger`, `string`, `text`, `time`, `tinyText`, `unsignedBigInteger`, `unsignedInteger`, `unsignedSmallInteger`, `ulid`, and `uuid`. To modify a `timestamp` column type a Doctrine type must be registered. +> When using the `doctrine/dbal` package, the following column types can be modified: `bigInteger`, `binary`, `boolean`, `char`, `date`, `dateTime`, `dateTimeTz`, `decimal`, `double`, `integer`, `json`, `longText`, `mediumText`, `smallInteger`, `string`, `text`, `time`, `tinyText`, `unsignedBigInteger`, `unsignedInteger`, `unsignedSmallInteger`, `ulid`, and `uuid`. ### Renaming Columns