Skip to content

Commit 2a7b7ae

Browse files
committed
Add withoutPrimaryKey for integer column
1 parent 662ac36 commit 2a7b7ae

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

src/Schema/Grammar.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
class Grammar extends MySqlGrammar
1919
{
20-
use CompilesKeys, ModifiesColumns;
20+
use CompilesKeys;
21+
use ModifiesColumns;
2122

2223
public function __construct()
2324
{
@@ -64,7 +65,8 @@ protected function compileCreateTable($blueprint, $command, $connection)
6465
// We want to do as little as possible ourselves, so we rely on the parent
6566
// to compile everything and then potentially sneak some modifiers in.
6667
return $this->insertCreateTableModifiers(
67-
$blueprint, parent::compileCreateTable($blueprint, $command, $connection)
68+
$blueprint,
69+
parent::compileCreateTable($blueprint, $command, $connection)
6870
);
6971
}
7072

@@ -174,4 +176,20 @@ protected function compileKey(Blueprint $blueprint, Fluent $command, $type)
174176
// creating the indexes as a part of the create statement.
175177
return str_replace(sprintf('alter table %s add ', $this->wrapTable($blueprint)), '', $compiled);
176178
}
179+
180+
/**
181+
* Get the SQL for an auto-increment column modifier.
182+
*
183+
* @param \Illuminate\Database\Schema\Blueprint $blueprint
184+
* @param \Illuminate\Support\Fluent $column
185+
* @return string|null
186+
*/
187+
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
188+
{
189+
if (in_array($column->type, $this->serials) && $column->autoIncrement) {
190+
return ($column->withoutPrimaryKey === true)
191+
? ' auto_increment'
192+
: ' auto_increment primary key';
193+
}
194+
}
177195
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* @author https://github.com/srdante
4+
*/
5+
6+
namespace SingleStore\Laravel\Tests\Hybrid\CreateTable;
7+
8+
use SingleStore\Laravel\Schema\Blueprint;
9+
use SingleStore\Laravel\Tests\BaseTest;
10+
use SingleStore\Laravel\Tests\Hybrid\HybridTestHelpers;
11+
12+
class IncrementWithoutPrimaryKeyTest extends BaseTest
13+
{
14+
use HybridTestHelpers;
15+
16+
/** @test */
17+
public function it_adds_a_big_increments_without_primary_key()
18+
{
19+
$blueprint = $this->createTable(function (Blueprint $table) {
20+
$table->bigIncrements('id')->withoutPrimaryKey();
21+
});
22+
23+
$this->assertCreateStatement(
24+
$blueprint,
25+
'create table `test` (`id` bigint unsigned not null auto_increment)'
26+
);
27+
}
28+
29+
/** @test */
30+
public function it_adds_an_id_without_primary_key()
31+
{
32+
$blueprint = $this->createTable(function (Blueprint $table) {
33+
$table->id()->withoutPrimaryKey();
34+
});
35+
36+
$this->assertCreateStatement(
37+
$blueprint,
38+
'create table `test` (`id` bigint unsigned not null auto_increment)'
39+
);
40+
}
41+
}

0 commit comments

Comments
 (0)