Skip to content

Commit

Permalink
[5.8] Revert #26454 and change default to bigIncrements in the migrat…
Browse files Browse the repository at this point in the history
…ion stub (#26472)

* Revert "Add tests for switching the default increments() method"

This reverts commit 22e1f7c.

* Revert "Make tests use bigincrements as default"

This reverts commit fd6002f.

* Revert "Switch increments to use unsignedBigInteger"

This reverts commit a406533.

* Use bigIncrements
  • Loading branch information
sisve authored and taylorotwell committed Nov 11, 2018
1 parent cc8c84c commit 74c5730
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 102 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Migrations/stubs/create.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
17 changes: 0 additions & 17 deletions src/Illuminate/Database/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down
37 changes: 8 additions & 29 deletions tests/Database/DatabaseMySqlSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
Expand All @@ -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()
Expand All @@ -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();
Expand All @@ -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()
Expand All @@ -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();
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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');
Expand Down
35 changes: 7 additions & 28 deletions tests/Database/DatabasePostgresSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,15 +24,15 @@ 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');
$blueprint->string('email');
$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()
Expand All @@ -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]);
}

Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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');
Expand Down Expand Up @@ -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();
Expand Down
29 changes: 4 additions & 25 deletions tests/Database/DatabaseSqlServerSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,15 +24,15 @@ 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');
$blueprint->string('email');
$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();
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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');
Expand Down

0 comments on commit 74c5730

Please sign in to comment.