Skip to content

Commit 38edd34

Browse files
author
Nathan Esayeas
authored
fix: datatype of an id column (#109)
1 parent 5f6cda5 commit 38edd34

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

src/Generators/MigrationGenerator.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,10 @@ protected function buildDefinition(Model $model)
5555
/** @var \Blueprint\Models\Column $column */
5656
foreach ($model->columns() as $column) {
5757
$dataType = $column->dataType();
58-
if ($column->name() === 'id' && $dataType !== 'uuid') {
58+
if ($column->name() === 'id' && $dataType === 'id') {
5959
$dataType = 'bigIncrements';
60-
} elseif ($column->dataType() === 'id') {
60+
} elseif ($dataType === 'id') {
6161
$dataType = 'unsignedBigInteger';
62-
} elseif ($column->dataType() === 'uuid') {
63-
$dataType = 'uuid';
6462
}
6563

6664
if ($dataType === 'bigIncrements' && $this->isLaravel7orNewer()) {

tests/Feature/Lexers/ModelLexerTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,16 @@ public function it_returns_models()
4545
'count' => 'integer',
4646
'timestamps' => 'timestamps'
4747
],
48+
'ModelThree' => [
49+
'id' => 'increments',
50+
],
4851
],
4952
];
5053

5154
$actual = $this->subject->analyze($tokens);
5255

5356
$this->assertIsArray($actual['models']);
54-
$this->assertCount(2, $actual['models']);
57+
$this->assertCount(3, $actual['models']);
5558

5659
$model = $actual['models']['ModelOne'];
5760
$this->assertEquals('ModelOne', $model->name());
@@ -80,6 +83,17 @@ public function it_returns_models()
8083
$this->assertEquals('count', $columns['count']->name());
8184
$this->assertEquals('integer', $columns['count']->dataType());
8285
$this->assertEquals([], $columns['count']->modifiers());
86+
87+
$model = $actual['models']['ModelThree'];
88+
$this->assertEquals('ModelThree', $model->name());
89+
$this->assertTrue($model->usesTimestamps());
90+
$this->assertFalse($model->usesSoftDeletes());
91+
92+
$columns = $model->columns();
93+
$this->assertCount(1, $columns);
94+
$this->assertEquals('id', $columns['id']->name());
95+
$this->assertEquals('increments', $columns['id']->dataType());
96+
$this->assertEquals([], $columns['id']->modifiers());
8397
}
8498

8599
/**

tests/fixtures/definitions/model-modifiers.bp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
models:
22
Modifier:
3+
id: increments
34
title: string nullable
45
name: string:1000 unique charset:'utf8'
56
content: string default:''

tests/fixtures/migrations/model-modifiers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class CreateModifiersTable extends Migration
1414
public function up()
1515
{
1616
Schema::create('modifiers', function (Blueprint $table) {
17-
$table->id();
17+
$table->increments('id');
1818
$table->string('title')->nullable();
1919
$table->string('name', 1000)->unique()->charset('utf8');
2020
$table->string('content')->default('');

0 commit comments

Comments
 (0)