Skip to content

Commit

Permalink
revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jun 25, 2021
2 parents d27132e + 63dcfc4 commit 6651d7e
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 128 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ protected function addImpliedCommands(Grammar $grammar)
protected function addFluentIndexes()
{
foreach ($this->columns as $column) {
foreach (['unique', 'index', 'spatialIndex'] as $index) {
foreach (['primary', 'unique', 'index', 'spatialIndex'] as $index) {
// If the index has been specified on the given column, but is simply equal
// to "true" (boolean), no name has been specified for this index so the
// index method can be called without a name and it will generate one.
Expand Down
40 changes: 13 additions & 27 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MySqlGrammar extends Grammar
* @var string[]
*/
protected $modifiers = [
'Unsigned', 'Charset', 'Primary', 'Collate', 'VirtualAs', 'StoredAs', 'Nullable',
'Unsigned', 'Charset', 'Collate', 'VirtualAs', 'StoredAs', 'Nullable',
'Srid', 'Default', 'Increment', 'Comment', 'After', 'First',
];

Expand Down Expand Up @@ -927,30 +927,30 @@ protected function typeComputed(Fluent $column)
}

/**
* Get the SQL for a primary column modifier.
* Get the SQL for a generated virtual column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
public function modifyPrimary(Blueprint $blueprint, Fluent $column)
protected function modifyVirtualAs(Blueprint $blueprint, Fluent $column)
{
if (! $column->autoIncrement && ! is_null($column->primary)) {
return ' primary key';
if (! is_null($column->virtualAs)) {
return " as ({$column->virtualAs})";
}
}

/**
* Get the SQL for an auto-increment column modifier.
* Get the SQL for a generated stored column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
protected function modifyStoredAs(Blueprint $blueprint, Fluent $column)
{
if (in_array($column->type, $this->serials) && $column->autoIncrement) {
return ' auto_increment primary key';
if (! is_null($column->storedAs)) {
return " as ({$column->storedAs}) stored";
}
}

Expand Down Expand Up @@ -1029,30 +1029,16 @@ protected function modifyDefault(Blueprint $blueprint, Fluent $column)
}

/**
* Get the SQL for a generated virtual column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyVirtualAs(Blueprint $blueprint, Fluent $column)
{
if (! is_null($column->virtualAs)) {
return " as ({$column->virtualAs})";
}
}

/**
* Get the SQL for a generated stored column modifier.
* Get the SQL for an auto-increment column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyStoredAs(Blueprint $blueprint, Fluent $column)
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
{
if (! is_null($column->storedAs)) {
return " as ({$column->storedAs}) stored";
if (in_array($column->type, $this->serials) && $column->autoIncrement) {
return ' auto_increment primary key';
}
}

Expand Down
16 changes: 1 addition & 15 deletions src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PostgresGrammar extends Grammar
*
* @var string[]
*/
protected $modifiers = ['Primary', 'Collate', 'Increment', 'Nullable', 'Default', 'VirtualAs', 'StoredAs'];
protected $modifiers = ['Collate', 'Increment', 'Nullable', 'Default', 'VirtualAs', 'StoredAs'];

/**
* The columns available as serials.
Expand Down Expand Up @@ -979,20 +979,6 @@ protected function modifyNullable(Blueprint $blueprint, Fluent $column)
return $column->nullable ? ' null' : ' not null';
}

/**
* Get the SQL for a primary column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
public function modifyPrimary(Blueprint $blueprint, Fluent $column)
{
if (! $column->autoIncrement && ! is_null($column->primary)) {
return ' primary key';
}
}

/**
* Get the SQL for a default column modifier.
*
Expand Down
45 changes: 16 additions & 29 deletions src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SQLiteGrammar extends Grammar
*
* @var string[]
*/
protected $modifiers = ['Primary', 'VirtualAs', 'StoredAs', 'Nullable', 'Default', 'Increment'];
protected $modifiers = ['VirtualAs', 'StoredAs', 'Nullable', 'Default', 'Increment'];

/**
* The columns available as serials.
Expand Down Expand Up @@ -55,11 +55,12 @@ public function compileColumnListing($table)
*/
public function compileCreate(Blueprint $blueprint, Fluent $command)
{
return sprintf('%s table %s (%s%s)',
return sprintf('%s table %s (%s%s%s)',
$blueprint->temporary ? 'create temporary' : 'create',
$this->wrapTable($blueprint),
implode(', ', $this->getColumns($blueprint)),
(string) $this->addForeignKeys($blueprint)
(string) $this->addForeignKeys($blueprint),
(string) $this->addPrimaryKeys($blueprint)
);
}

Expand Down Expand Up @@ -848,30 +849,30 @@ protected function typeComputed(Fluent $column)
}

/**
* Get the SQL for a primary column modifier.
* Get the SQL for a generated virtual column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
public function modifyPrimary(Blueprint $blueprint, Fluent $column)
protected function modifyVirtualAs(Blueprint $blueprint, Fluent $column)
{
if (! $column->autoIncrement && ! is_null($column->primary)) {
return ' primary key';
if (! is_null($column->virtualAs)) {
return " as ({$column->virtualAs})";
}
}

/**
* Get the SQL for an auto-increment column modifier.
* Get the SQL for a generated stored column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
protected function modifyStoredAs(Blueprint $blueprint, Fluent $column)
{
if (in_array($column->type, $this->serials) && $column->autoIncrement) {
return ' primary key autoincrement';
if (! is_null($column->storedAs)) {
return " as ({$column->storedAs}) stored";
}
}

Expand Down Expand Up @@ -908,30 +909,16 @@ protected function modifyDefault(Blueprint $blueprint, Fluent $column)
}

/**
* Get the SQL for a generated virtual column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyVirtualAs(Blueprint $blueprint, Fluent $column)
{
if (! is_null($column->virtualAs)) {
return " as ({$column->virtualAs})";
}
}

/**
* Get the SQL for a generated stored column modifier.
* Get the SQL for an auto-increment column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyStoredAs(Blueprint $blueprint, Fluent $column)
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
{
if (! is_null($column->storedAs)) {
return " as ({$column->storedAs}) stored";
if (in_array($column->type, $this->serials) && $column->autoIncrement) {
return ' primary key autoincrement';
}
}
}
16 changes: 1 addition & 15 deletions src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SqlServerGrammar extends Grammar
*
* @var string[]
*/
protected $modifiers = ['Primary', 'Increment', 'Collate', 'Nullable', 'Default', 'Persisted'];
protected $modifiers = ['Increment', 'Collate', 'Nullable', 'Default', 'Persisted'];

/**
* The columns available as serials.
Expand Down Expand Up @@ -832,20 +832,6 @@ protected function typeComputed(Fluent $column)
return "as ({$column->expression})";
}

/**
* Get the SQL for a primary column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
public function modifyPrimary(Blueprint $blueprint, Fluent $column)
{
if (! $column->autoIncrement && ! is_null($column->primary)) {
return ' primary key';
}
}

/**
* Get the SQL for a collation column modifier.
*
Expand Down
17 changes: 0 additions & 17 deletions tests/Database/DatabaseMySqlSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,6 @@ public function testBasicCreateTable()
$this->assertSame('alter table `users` add `id` int unsigned not null auto_increment primary key, add `email` varchar(255) not null', $statements[0]);
}

public function testBasicCreateWithPrimaryKey()
{
$blueprint = new Blueprint('users');
$blueprint->create();
$blueprint->integer('foo')->primary()->unsigned();

$conn = $this->getConnection();
$conn->shouldReceive('getConfig')->once()->with('charset')->andReturn('utf8');
$conn->shouldReceive('getConfig')->once()->with('collation')->andReturn('utf8_unicode_ci');
$conn->shouldReceive('getConfig')->once()->with('engine')->andReturn(null);

$statements = $blueprint->toSql($conn, $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertSame("create table `users` (`foo` int unsigned primary key not null) default character set utf8 collate 'utf8_unicode_ci'", $statements[0]);
}

public function testAutoIncrementStartingValue()
{
$blueprint = new Blueprint('users');
Expand Down
11 changes: 0 additions & 11 deletions tests/Database/DatabasePostgresSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ public function testBasicCreateTable()
$this->assertSame('alter table "users" add column "id" serial primary key not null, add column "email" varchar(255) not null', $statements[0]);
}

public function testBasicCreateWithPrimaryKey()
{
$blueprint = new Blueprint('users');
$blueprint->create();
$blueprint->string('foo')->primary();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertSame('create table "users" ("foo" varchar(255) primary key not null)', $statements[0]);
}

public function testCreateTableWithAutoIncrementStartingValue()
{
$blueprint = new Blueprint('users');
Expand Down
4 changes: 2 additions & 2 deletions tests/Database/DatabaseSQLiteSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function testAddingPrimaryKey()
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertSame('create table "users" ("foo" varchar primary key not null)', $statements[0]);
$this->assertSame('create table "users" ("foo" varchar not null, primary key ("foo"))', $statements[0]);
}

public function testAddingForeignKey()
Expand All @@ -209,7 +209,7 @@ public function testAddingForeignKey()
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertSame('create table "users" ("foo" varchar primary key not null, "order_id" varchar not null, foreign key("order_id") references "orders"("id"))', $statements[0]);
$this->assertSame('create table "users" ("foo" varchar not null, "order_id" varchar not null, foreign key("order_id") references "orders"("id"), primary key ("foo"))', $statements[0]);
}

public function testAddingUniqueKey()
Expand Down
11 changes: 0 additions & 11 deletions tests/Database/DatabaseSqlServerSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@ public function testBasicCreateTable()
$this->assertSame('create table "prefix_users" ("id" int identity primary key not null, "email" nvarchar(255) not null)', $statements[0]);
}

public function testBasicCreateWithPrimaryKey()
{
$blueprint = new Blueprint('users');
$blueprint->create();
$blueprint->string('foo')->primary();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertSame('create table "users" ("foo" nvarchar(255) primary key not null)', $statements[0]);
}

public function testCreateTemporaryTable()
{
$blueprint = new Blueprint('users');
Expand Down

0 comments on commit 6651d7e

Please sign in to comment.