Skip to content

Commit dbad5a3

Browse files
Support uuid primary key shorthand (#130)
1 parent fd47d8a commit dbad5a3

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

src/Blueprint.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public function parse($content)
3838
return $matches[1] . 'resource: all';
3939
}, $content);
4040

41+
$content = preg_replace_callback('/^(\s+)uuid(: true)?$/mi', function ($matches) {
42+
return $matches[1] . 'id: uuid primary';
43+
}, $content);
44+
4145
return Yaml::parse($content);
4246
}
4347

tests/Feature/BlueprintTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,23 @@ public function it_parses_shorthands()
9595
], $this->subject->parse($blueprint));
9696
}
9797

98+
/**
99+
* @test
100+
*/
101+
public function it_parses_uuid_shorthand()
102+
{
103+
$blueprint = $this->fixture('definitions/uuid-shorthand.bp');
104+
105+
$this->assertEquals([
106+
'models' => [
107+
'Person' => [
108+
'id' => 'uuid primary',
109+
'timestamps' => 'timestamps',
110+
],
111+
]
112+
], $this->subject->parse($blueprint));
113+
}
114+
98115
/**
99116
* @test
100117
*/

tests/Feature/Generator/MigrationGeneratorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public function modelTreeDataProvider()
138138
['definitions/optimize.bp', 'database/migrations/timestamp_create_optimizes_table.php', 'migrations/optimize.php'],
139139
['definitions/model-key-constraints.bp', 'database/migrations/timestamp_create_orders_table.php', 'migrations/model-key-constraints.php'],
140140
['definitions/disable-auto-columns.bp', 'database/migrations/timestamp_create_states_table.php', 'migrations/disable-auto-columns.php'],
141+
['definitions/uuid-shorthand.bp', 'database/migrations/timestamp_create_people_table.php', 'migrations/uuid-shorthand.php'],
141142
];
142143
}
143144
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
models:
2+
Person:
3+
uuid
4+
timestamps
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreatePeopleTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('people', function (Blueprint $table) {
17+
$table->uuid('id')->primary();
18+
$table->timestamps();
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*
25+
* @return void
26+
*/
27+
public function down()
28+
{
29+
Schema::dropIfExists('people');
30+
}
31+
}

0 commit comments

Comments
 (0)