Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function parse($content)
return $matches[1] . 'resource: all';
}, $content);

$content = preg_replace_callback('/^(\s+)uuid(: true)?$/mi', function ($matches) {
return $matches[1] . 'id: uuid primary';
}, $content);

return Yaml::parse($content);
}

Expand Down
17 changes: 17 additions & 0 deletions tests/Feature/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ public function it_parses_shorthands()
], $this->subject->parse($blueprint));
}

/**
* @test
*/
public function it_parses_uuid_shorthand()
{
$blueprint = $this->fixture('definitions/uuid-shorthand.bp');

$this->assertEquals([
'models' => [
'Person' => [
'id' => 'uuid primary',
'timestamps' => 'timestamps',
],
]
], $this->subject->parse($blueprint));
}

/**
* @test
*/
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/Generator/MigrationGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function modelTreeDataProvider()
['definitions/optimize.bp', 'database/migrations/timestamp_create_optimizes_table.php', 'migrations/optimize.php'],
['definitions/model-key-constraints.bp', 'database/migrations/timestamp_create_orders_table.php', 'migrations/model-key-constraints.php'],
['definitions/disable-auto-columns.bp', 'database/migrations/timestamp_create_states_table.php', 'migrations/disable-auto-columns.php'],
['definitions/uuid-shorthand.bp', 'database/migrations/timestamp_create_people_table.php', 'migrations/uuid-shorthand.php'],
];
}
}
4 changes: 4 additions & 0 deletions tests/fixtures/definitions/uuid-shorthand.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
models:
Person:
uuid
timestamps
31 changes: 31 additions & 0 deletions tests/fixtures/migrations/uuid-shorthand.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 CreatePeopleTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('people', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->timestamps();
});
}

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