From 74c5730070f4f510993dce843d004903e4b49889 Mon Sep 17 00:00:00 2001 From: Simon Svensson Date: Sun, 11 Nov 2018 14:50:44 +0100 Subject: [PATCH] [5.8] Revert #26454 and change default to bigIncrements in the migration stub (#26472) * Revert "Add tests for switching the default increments() method" This reverts commit 22e1f7c8d54f04b916ef352f27f858c16b570c7f. * Revert "Make tests use bigincrements as default" This reverts commit fd6002feedcd99326d6a17966bb8d6d091a8c77a. * Revert "Switch increments to use unsignedBigInteger" This reverts commit a40653328d830b92b464540bc1468b6f183b75d4. * Use bigIncrements --- .../Database/Migrations/stubs/create.stub | 2 +- src/Illuminate/Database/Schema/Blueprint.php | 4 +- src/Illuminate/Database/Schema/Builder.php | 17 --------- .../DatabaseMySqlSchemaGrammarTest.php | 37 ++++--------------- .../DatabasePostgresSchemaGrammarTest.php | 35 ++++-------------- .../DatabaseSqlServerSchemaGrammarTest.php | 29 ++------------- 6 files changed, 22 insertions(+), 102 deletions(-) diff --git a/src/Illuminate/Database/Migrations/stubs/create.stub b/src/Illuminate/Database/Migrations/stubs/create.stub index a98c4749cb1f..08e171bc558f 100755 --- a/src/Illuminate/Database/Migrations/stubs/create.stub +++ b/src/Illuminate/Database/Migrations/stubs/create.stub @@ -14,7 +14,7 @@ class DummyClass extends Migration public function up() { Schema::create('DummyTable', function (Blueprint $table) { - $table->increments('id'); + $table->bigIncrements('id'); $table->timestamps(); }); } diff --git a/src/Illuminate/Database/Schema/Blueprint.php b/src/Illuminate/Database/Schema/Blueprint.php index afbc4e97fd52..6ff1af22a2c3 100755 --- a/src/Illuminate/Database/Schema/Blueprint.php +++ b/src/Illuminate/Database/Schema/Blueprint.php @@ -526,14 +526,14 @@ public function foreign($columns, $name = null) } /** - * Create a new auto-incrementing integer column on the table. + * Create a new auto-incrementing integer (4-byte) column on the table. * * @param string $column * @return \Illuminate\Database\Schema\ColumnDefinition */ public function increments($column) { - return $this->{Builder::$defaultIncrementsType}($column, true); + return $this->unsignedInteger($column, true); } /** diff --git a/src/Illuminate/Database/Schema/Builder.php b/src/Illuminate/Database/Schema/Builder.php index 6c378a6a0cc9..2e25cf0cd9dc 100755 --- a/src/Illuminate/Database/Schema/Builder.php +++ b/src/Illuminate/Database/Schema/Builder.php @@ -36,13 +36,6 @@ class Builder */ public static $defaultStringLength = 255; - /** - * The default increments type for migrations. - * - * @var string - */ - public static $defaultIncrementsType = 'unsignedBigInteger'; - /** * Create a new database Schema manager. * @@ -66,16 +59,6 @@ public static function defaultStringLength($length) static::$defaultStringLength = $length; } - /** - * Set the default increments type to a 4 byte integer. - * - * @return void - */ - public static function useIntegerIncrements() - { - static::$defaultIncrementsType = 'unsignedInteger'; - } - /** * Determine if the given table exists. * diff --git a/tests/Database/DatabaseMySqlSchemaGrammarTest.php b/tests/Database/DatabaseMySqlSchemaGrammarTest.php index 44fc51de6f48..11091f7b4375 100755 --- a/tests/Database/DatabaseMySqlSchemaGrammarTest.php +++ b/tests/Database/DatabaseMySqlSchemaGrammarTest.php @@ -5,7 +5,6 @@ use Mockery as m; use PHPUnit\Framework\TestCase; use Illuminate\Database\Connection; -use Illuminate\Database\Schema\Builder; use Illuminate\Database\Query\Expression; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Grammars\MySqlGrammar; @@ -32,7 +31,7 @@ public function testBasicCreateTable() $statements = $blueprint->toSql($conn, $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals("create table `users` (`id` bigint unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8 collate 'utf8_unicode_ci'", $statements[0]); + $this->assertEquals("create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8 collate 'utf8_unicode_ci'", $statements[0]); $blueprint = new Blueprint('users'); $blueprint->increments('id'); @@ -44,7 +43,7 @@ public function testBasicCreateTable() $statements = $blueprint->toSql($conn, $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table `users` add `id` bigint unsigned not null auto_increment primary key, add `email` varchar(255) not null', $statements[0]); + $this->assertEquals('alter table `users` add `id` int unsigned not null auto_increment primary key, add `email` varchar(255) not null', $statements[0]); } public function testEngineCreateTable() @@ -62,7 +61,7 @@ public function testEngineCreateTable() $statements = $blueprint->toSql($conn, $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals("create table `users` (`id` bigint unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8 collate 'utf8_unicode_ci' engine = InnoDB", $statements[0]); + $this->assertEquals("create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8 collate 'utf8_unicode_ci' engine = InnoDB", $statements[0]); $blueprint = new Blueprint('users'); $blueprint->create(); @@ -77,7 +76,7 @@ public function testEngineCreateTable() $statements = $blueprint->toSql($conn, $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals("create table `users` (`id` bigint unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8 collate 'utf8_unicode_ci' engine = InnoDB", $statements[0]); + $this->assertEquals("create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8 collate 'utf8_unicode_ci' engine = InnoDB", $statements[0]); } public function testCharsetCollationCreateTable() @@ -95,7 +94,7 @@ public function testCharsetCollationCreateTable() $statements = $blueprint->toSql($conn, $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals("create table `users` (`id` bigint unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci'", $statements[0]); + $this->assertEquals("create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci'", $statements[0]); $blueprint = new Blueprint('users'); $blueprint->create(); @@ -110,7 +109,7 @@ public function testCharsetCollationCreateTable() $statements = $blueprint->toSql($conn, $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals("create table `users` (`id` bigint unsigned not null auto_increment primary key, `email` varchar(255) character set utf8mb4 collate 'utf8mb4_unicode_ci' not null) default character set utf8 collate 'utf8_unicode_ci'", $statements[0]); + $this->assertEquals("create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) character set utf8mb4 collate 'utf8mb4_unicode_ci' not null) default character set utf8 collate 'utf8_unicode_ci'", $statements[0]); } public function testBasicCreateTableWithPrefix() @@ -128,7 +127,7 @@ public function testBasicCreateTableWithPrefix() $statements = $blueprint->toSql($conn, $grammar); $this->assertCount(1, $statements); - $this->assertEquals('create table `prefix_users` (`id` bigint unsigned not null auto_increment primary key, `email` varchar(255) not null)', $statements[0]); + $this->assertEquals('create table `prefix_users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null)', $statements[0]); } public function testCreateTemporaryTable() @@ -145,7 +144,7 @@ public function testCreateTemporaryTable() $statements = $blueprint->toSql($conn, $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('create temporary table `users` (`id` bigint unsigned not null auto_increment primary key, `email` varchar(255) not null)', $statements[0]); + $this->assertEquals('create temporary table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null)', $statements[0]); } public function testDropTable() @@ -379,18 +378,8 @@ public function testAddingIncrementingID() $blueprint->increments('id'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertCount(1, $statements); - $this->assertEquals('alter table `users` add `id` bigint unsigned not null auto_increment primary key', $statements[0]); - - Builder::useIntegerIncrements(); - $blueprint = new Blueprint('users'); - $blueprint->increments('id'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertCount(1, $statements); $this->assertEquals('alter table `users` add `id` int unsigned not null auto_increment primary key', $statements[0]); - - Builder::$defaultIncrementsType = 'unsignedBigInteger'; } public function testAddingSmallIncrementingID() @@ -403,16 +392,6 @@ public function testAddingSmallIncrementingID() $this->assertEquals('alter table `users` add `id` smallint unsigned not null auto_increment primary key', $statements[0]); } - public function testAddingIntegerIncrementingID() - { - $blueprint = new Blueprint('users'); - $blueprint->integerIncrements('id'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertEquals('alter table `users` add `id` int unsigned not null auto_increment primary key', $statements[0]); - } - public function testAddingBigIncrementingID() { $blueprint = new Blueprint('users'); diff --git a/tests/Database/DatabasePostgresSchemaGrammarTest.php b/tests/Database/DatabasePostgresSchemaGrammarTest.php index 2dc25bc45cd0..da42ae4e5fea 100755 --- a/tests/Database/DatabasePostgresSchemaGrammarTest.php +++ b/tests/Database/DatabasePostgresSchemaGrammarTest.php @@ -5,7 +5,6 @@ use Mockery as m; use PHPUnit\Framework\TestCase; use Illuminate\Database\Connection; -use Illuminate\Database\Schema\Builder; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Grammars\PostgresGrammar; @@ -25,7 +24,7 @@ public function testBasicCreateTable() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('create table "users" ("id" bigserial primary key not null, "email" varchar(255) not null)', $statements[0]); + $this->assertEquals('create table "users" ("id" serial primary key not null, "email" varchar(255) not null)', $statements[0]); $blueprint = new Blueprint('users'); $blueprint->increments('id'); @@ -33,7 +32,7 @@ public function testBasicCreateTable() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table "users" add column "id" bigserial primary key not null, add column "email" varchar(255) not null', $statements[0]); + $this->assertEquals('alter table "users" add column "id" serial primary key not null, add column "email" varchar(255) not null', $statements[0]); } public function testCreateTableAndCommentColumn() @@ -45,7 +44,7 @@ public function testCreateTableAndCommentColumn() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(2, $statements); - $this->assertEquals('create table "users" ("id" bigserial primary key not null, "email" varchar(255) not null)', $statements[0]); + $this->assertEquals('create table "users" ("id" serial primary key not null, "email" varchar(255) not null)', $statements[0]); $this->assertEquals('comment on column "users"."email" is \'my first comment\'', $statements[1]); } @@ -59,7 +58,7 @@ public function testCreateTemporaryTable() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('create temporary table "users" ("id" bigserial primary key not null, "email" varchar(255) not null)', $statements[0]); + $this->assertEquals('create temporary table "users" ("id" serial primary key not null, "email" varchar(255) not null)', $statements[0]); } public function testDropTable() @@ -273,18 +272,8 @@ public function testAddingIncrementingID() $blueprint->increments('id'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertCount(1, $statements); - $this->assertEquals('alter table "users" add column "id" bigserial primary key not null', $statements[0]); - - Builder::useIntegerIncrements(); - $blueprint = new Blueprint('users'); - $blueprint->increments('id'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertCount(1, $statements); $this->assertEquals('alter table "users" add column "id" serial primary key not null', $statements[0]); - - Builder::$defaultIncrementsType = 'unsignedBigInteger'; } public function testAddingSmallIncrementingID() @@ -307,16 +296,6 @@ public function testAddingMediumIncrementingID() $this->assertEquals('alter table "users" add column "id" serial primary key not null', $statements[0]); } - public function testAddingIntegerIncrementingID() - { - $blueprint = new Blueprint('users'); - $blueprint->integerIncrements('id'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertEquals('alter table "users" add column "id" serial primary key not null', $statements[0]); - } - public function testAddingBigIncrementingID() { $blueprint = new Blueprint('users'); @@ -687,19 +666,19 @@ public function testAddingGeneratedAs() $blueprint->increments('foo')->generatedAs(); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table "users" add column "foo" bigint generated by default as identity primary key not null', $statements[0]); + $this->assertEquals('alter table "users" add column "foo" integer generated by default as identity primary key not null', $statements[0]); // With always modifier $blueprint = new Blueprint('users'); $blueprint->increments('foo')->generatedAs()->always(); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table "users" add column "foo" bigint generated always as identity primary key not null', $statements[0]); + $this->assertEquals('alter table "users" add column "foo" integer generated always as identity primary key not null', $statements[0]); // With sequence options $blueprint = new Blueprint('users'); $blueprint->increments('foo')->generatedAs('increment by 10 start with 100'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table "users" add column "foo" bigint generated by default as identity (increment by 10 start with 100) primary key not null', $statements[0]); + $this->assertEquals('alter table "users" add column "foo" integer generated by default as identity (increment by 10 start with 100) primary key not null', $statements[0]); // Not a primary key $blueprint = new Blueprint('users'); $blueprint->integer('foo')->generatedAs(); diff --git a/tests/Database/DatabaseSqlServerSchemaGrammarTest.php b/tests/Database/DatabaseSqlServerSchemaGrammarTest.php index 61a873e8ed6a..c51722e8a40d 100755 --- a/tests/Database/DatabaseSqlServerSchemaGrammarTest.php +++ b/tests/Database/DatabaseSqlServerSchemaGrammarTest.php @@ -5,7 +5,6 @@ use Mockery as m; use PHPUnit\Framework\TestCase; use Illuminate\Database\Connection; -use Illuminate\Database\Schema\Builder; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Grammars\SqlServerGrammar; @@ -25,7 +24,7 @@ public function testBasicCreateTable() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('create table "users" ("id" bigint identity primary key not null, "email" nvarchar(255) not null)', $statements[0]); + $this->assertEquals('create table "users" ("id" int identity primary key not null, "email" nvarchar(255) not null)', $statements[0]); $blueprint = new Blueprint('users'); $blueprint->increments('id'); @@ -33,7 +32,7 @@ public function testBasicCreateTable() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table "users" add "id" bigint identity primary key not null, "email" nvarchar(255) not null', $statements[0]); + $this->assertEquals('alter table "users" add "id" int identity primary key not null, "email" nvarchar(255) not null', $statements[0]); $blueprint = new Blueprint('users'); $blueprint->create(); @@ -42,7 +41,7 @@ public function testBasicCreateTable() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()->setTablePrefix('prefix_')); $this->assertCount(1, $statements); - $this->assertEquals('create table "prefix_users" ("id" bigint identity primary key not null, "email" nvarchar(255) not null)', $statements[0]); + $this->assertEquals('create table "prefix_users" ("id" int identity primary key not null, "email" nvarchar(255) not null)', $statements[0]); } public function testCreateTemporaryTable() @@ -55,7 +54,7 @@ public function testCreateTemporaryTable() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('create table "#users" ("id" bigint identity primary key not null, "email" nvarchar(255) not null)', $statements[0]); + $this->assertEquals('create table "#users" ("id" int identity primary key not null, "email" nvarchar(255) not null)', $statements[0]); } public function testDropTable() @@ -273,18 +272,8 @@ public function testAddingIncrementingID() $blueprint->increments('id'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertCount(1, $statements); - $this->assertEquals('alter table "users" add "id" bigint identity primary key not null', $statements[0]); - - Builder::useIntegerIncrements(); - $blueprint = new Blueprint('users'); - $blueprint->increments('id'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertCount(1, $statements); $this->assertEquals('alter table "users" add "id" int identity primary key not null', $statements[0]); - - Builder::$defaultIncrementsType = 'unsignedBigInteger'; } public function testAddingSmallIncrementingID() @@ -307,16 +296,6 @@ public function testAddingMediumIncrementingID() $this->assertEquals('alter table "users" add "id" int identity primary key not null', $statements[0]); } - public function testAddingIntegerIncrementingID() - { - $blueprint = new Blueprint('users'); - $blueprint->integerIncrements('id'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertEquals('alter table "users" add "id" int identity primary key not null', $statements[0]); - } - public function testAddingBigIncrementingID() { $blueprint = new Blueprint('users');