Skip to content

Commit 62edefe

Browse files
author
Nathan Esayeas
authored
Generate migration columns with comments (#347)
1 parent a68730e commit 62edefe

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

src/Lexers/ModelLexer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class ModelLexer implements Lexer
9595
'primary' => 'primary',
9696
'foreign' => 'foreign',
9797
'ondelete' => 'onDelete',
98+
'comment' => 'comment',
9899
];
99100

100101
public function analyze(array $tokens): array
@@ -206,7 +207,7 @@ private function buildColumn(string $name, string $definition)
206207
$data_type = null;
207208
$modifiers = [];
208209

209-
$tokens = preg_split('#".*?"(*SKIP)(*FAIL)|\s+#', $definition);
210+
$tokens = preg_split('#("|\').*?\1(*SKIP)(*FAIL)|\s+#', $definition);
210211
foreach ($tokens as $token) {
211212
$parts = explode(':', $token);
212213
$value = $parts[0];

tests/Feature/Generator/MigrationGeneratorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ public function modelTreeDataProvider()
754754
['drafts/unconventional-foreign-key.yaml', 'database/migrations/timestamp_create_states_table.php', 'migrations/unconventional-foreign-key.php'],
755755
['drafts/resource-statements.yaml', 'database/migrations/timestamp_create_users_table.php', 'migrations/resource-statements.php'],
756756
['drafts/enum-options.yaml', 'database/migrations/timestamp_create_messages_table.php', 'migrations/enum-options.php'],
757+
['drafts/columns-with-comments.yaml', 'database/migrations/timestamp_create_professions_table.php', 'migrations/columns-with-comments.php'],
757758
];
758759
}
759760
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
models:
2+
Profession:
3+
title: string:400 comment:"Some title for the profession"
4+
description: string:400 nullable comment:'Some description for the profession'
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreateProfessionsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('professions', function (Blueprint $table) {
17+
$table->id();
18+
$table->string('title', 400)->comment("Some title for the profession");
19+
$table->string('description', 400)->nullable()->comment('Some description for the profession');
20+
$table->timestamps();
21+
});
22+
}
23+
24+
/**
25+
* Reverse the migrations.
26+
*
27+
* @return void
28+
*/
29+
public function down()
30+
{
31+
Schema::dropIfExists('professions');
32+
}
33+
}

0 commit comments

Comments
 (0)