Skip to content

Commit

Permalink
Support uuid primary key shorthand (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccreary authored Apr 17, 2020
1 parent fd47d8a commit dbad5a3
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
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');
}
}

0 comments on commit dbad5a3

Please sign in to comment.