生成数据字典
This commit is contained in:
parent
b0c0c8b9fa
commit
02cdd6b040
|
|
@ -11,7 +11,10 @@
|
|||
|
||||
namespace Beike\Console\Commands;
|
||||
|
||||
use UniSharp\DocUs\Parser;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class GenerateDatabaseDict extends Command
|
||||
{
|
||||
|
|
@ -20,6 +23,27 @@ class GenerateDatabaseDict extends Command
|
|||
|
||||
public function handle()
|
||||
{
|
||||
$filePath = storage_path('database.md');
|
||||
// $filePath = '/Users/edward/Guangda/Products/beike/beikedocs/docs/dev/database.md';
|
||||
$tables = $this->getTables();
|
||||
$markdown = view('vendor.unisharp.markdown', compact('tables'))->render();
|
||||
file_put_contents($filePath, $markdown);
|
||||
dump('done');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有数据表信息
|
||||
* @return Collection
|
||||
*/
|
||||
private function getTables(): Collection
|
||||
{
|
||||
$schema = Parser::getSchema();
|
||||
return $schema->map(function ($item) {
|
||||
$tableName = $item['name'];
|
||||
$result = collect(DB::select("SHOW TABLE STATUS WHERE Name='{$tableName}'"))->first();
|
||||
$item['comment'] = $result->Comment;
|
||||
return $item;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
"stripe/stripe-php": "^8.8",
|
||||
"tormjens/eventy": "^0.8.0",
|
||||
"ultrono/laravel-sitemap": "^9.1",
|
||||
"unisharp/doc-us": "^1.3",
|
||||
"zanysoft/laravel-zip": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "d41aaf4336e9383247e1340f2fe6ffe5",
|
||||
"content-hash": "793040fbe53dc3a99b2c8ea50fcc03cb",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asm89/stack-cors",
|
||||
|
|
@ -6942,6 +6942,66 @@
|
|||
},
|
||||
"time": "2022-03-11T10:11:30+00:00"
|
||||
},
|
||||
{
|
||||
"name": "unisharp/doc-us",
|
||||
"version": "v1.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/UniSharp/doc-us.git",
|
||||
"reference": "8175acac629a92ff7245a3f8a4f53ee4b9a4a752"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/UniSharp/doc-us/zipball/8175acac629a92ff7245a3f8a4f53ee4b9a4a752",
|
||||
"reference": "8175acac629a92ff7245a3f8a4f53ee4b9a4a752",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"illuminate/database": ">5.3",
|
||||
"illuminate/support": ">5.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^0.9.6",
|
||||
"phpunit/phpunit": "^5.6",
|
||||
"vlucas/phpdotenv": "^2.4"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"UniSharp\\DocUs\\DocUsServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"UniSharp\\DocUs\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "UniSharp Ltd.",
|
||||
"email": "unisharp-service@unisharp.com",
|
||||
"homepage": "http://unisharp.com"
|
||||
}
|
||||
],
|
||||
"description": "A MySQL Schema Documantation Generator for Laravel",
|
||||
"support": {
|
||||
"issues": "https://github.com/UniSharp/doc-us/issues",
|
||||
"source": "https://github.com/UniSharp/doc-us/tree/v1.3.0"
|
||||
},
|
||||
"time": "2018-02-22T10:01:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "vlucas/phpdotenv",
|
||||
"version": "v5.4.1",
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ return [
|
|||
*/
|
||||
|
||||
'paths' => [
|
||||
base_path('themes/default')
|
||||
base_path('themes/default'),
|
||||
resource_path('views'),
|
||||
],
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
# 数据字典
|
||||
@foreach ($tables as $index => $table)
|
||||
|
||||
## {{$index+1}}. `{{ $table['name'] }}`
|
||||
|
||||
#### 描述: {{ $table['comment'] }}
|
||||
|
||||
|
||||
|
||||
#### 字段:
|
||||
|
||||
| 字段 | 类型 | 属性 | 默认值 | 描述 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
@foreach ($table['columns'] as $column)
|
||||
| `{{ $column->name }}` | {{ $column->type }} | {{ $column->attributes->implode(', ') }} | {{ $column->default }} | {{ $column->description }} |
|
||||
@endforeach
|
||||
@if (count($table['indices']))
|
||||
|
||||
#### 索引:
|
||||
|
||||
| 名字 | 字段 | 类型 | 描述 |
|
||||
| --- | --- | --- | --- |
|
||||
@foreach($table['indices'] as $indices)
|
||||
| `{{ $indices->name }}` | {{ $indices->columns->map(function ($column) { return "`{$column}`"; })->implode(', ') }} | {{ $indices->type }} | {{ $indices->description }} |
|
||||
@endforeach
|
||||
@endif
|
||||
@endforeach
|
||||
Loading…
Reference in New Issue