Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Generators/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function buildDefinition(Model $model)
/** @var \Blueprint\Models\Column $column */
foreach ($model->columns() as $column) {
$dataType = $column->dataType();
if ($column->name() === 'id' && $dataType !== 'uuid') {
if ($column->name() === 'id' && $dataType !== 'uuid' && $dataType !== 'increments') {
$dataType = 'bigIncrements';
} elseif ($column->dataType() === 'id') {
$dataType = 'unsignedBigInteger';
Expand Down
30 changes: 30 additions & 0 deletions tests/Feature/Generator/MigrationGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,35 @@ public function output_uses_big_increments_for_id_column()
$this->assertEquals(['created' => [$timestamp_path]], $this->subject->output($tree));
}

/**
* @test
*/
public function output_uses_increments_for_id_column()
{
$app = \Mockery::mock();
$app->expects('version')
->withNoArgs()
->andReturn('6.0.0');
App::swap($app);

$this->files->expects('stub')
->with('migration.stub')
->andReturn(file_get_contents('stubs/migration.stub'));

$now = Carbon::now();
Carbon::setTestNow($now);

$timestamp_path = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_roles_table.php');

$this->files->expects('put')
->with($timestamp_path, $this->fixture('migrations/model-increments-only.php'));

$tokens = $this->blueprint->parse($this->fixture('definitions/model-increments-only.bp'));
$tree = $this->blueprint->analyze($tokens);

$this->assertEquals(['created' => [$timestamp_path]], $this->subject->output($tree));
}

public function modelTreeDataProvider()
{
return [
Expand All @@ -136,6 +165,7 @@ public function modelTreeDataProvider()
['definitions/relationships.bp', 'database/migrations/timestamp_create_comments_table.php', 'migrations/relationships.php'],
['definitions/unconventional.bp', 'database/migrations/timestamp_create_teams_table.php', 'migrations/unconventional.php'],
['definitions/model-key-constraints.bp', 'database/migrations/timestamp_create_orders_table.php', 'migrations/model-key-constraints.php'],
['definitions/model-increments-only.bp', 'database/migrations/timestamp_create_roles_table.php', 'migrations/model-increments-only.php'],
];
}
}
5 changes: 5 additions & 0 deletions tests/fixtures/definitions/model-increments-only.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
models:
Role:
id: increments
some_id: unsignedInteger
timestamps: false
31 changes: 31 additions & 0 deletions tests/fixtures/migrations/model-increments-only.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateRolesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('some_id');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('roles');
}
}