Skip to content

Commit 161d87b

Browse files
author
dogstar
committed
添加数据库字典生成脚本命令
1 parent ec98c82 commit 161d87b

2 files changed

Lines changed: 144 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* 生成数据库字典文档
4+
*
5+
* @license http://www.phalapi.net/license GPL 协议
6+
* @link http://www.phalapi.net/
7+
* @author: dogstar <chanzonghuang@gmail.com> 2025-03-31
8+
*/
9+
10+
require_once dirname(__FILE__) . '/../public/init.php';
11+
$databaseName = \PhalApi\DI()->config->get('dbs.servers.db_master.name');
12+
echo "开始生成数据库字典文件 {$databaseName} ... ", PHP_EOL;
13+
14+
$tabeRows = \PhalApi\DI()->notorm->demo->queryAll('SHOW TABLES;', array());
15+
16+
$mdContent = "# {$databaseName}数据库字典\n\n";
17+
18+
foreach ($tabeRows as $it) {
19+
$it = array_values($it);
20+
$tableName = $it[0];
21+
22+
$sqlTD = "SELECT
23+
table_comment
24+
FROM
25+
information_schema.`TABLES`
26+
WHERE
27+
table_schema = '{$databaseName}'
28+
and table_name = '{$tableName}'";
29+
$fieldsRowsTD = \PhalApi\DI()->notorm->demo->queryAll($sqlTD, array());
30+
$tableDesc = isset($fieldsRowsTD[0]['table_comment']) ? $fieldsRowsTD[0]['table_comment'] : '';
31+
32+
$mdContent .= "## {$tableName}表结构 {$tableDesc}\n";
33+
34+
$mdContent .= "字段|类型|默认值|是否允许为NULL|索引|注释 \n";
35+
$mdContent .= "---|---|---|---|---|--- \n";
36+
37+
$sql = "show full fields from {$tableName}";
38+
$fieldsRows = \PhalApi\DI()->notorm->demo->queryAll($sql, array());
39+
foreach ($fieldsRows as $it) {
40+
$mdContent .= sprintf("%s|%s|%s|%s|%s|%s \n", str_replace(['\r\n',"\r\n","\n"],['',"",""],$it['Field']), $it['Type'], $it['Default'], $it['Null'] == 'YES' ? '允许NULL' : '不为NULL', getKeyStr($it['Key']), str_replace(['\r\n',"\r\n","\n"],['',"",""],$it['Comment']));
41+
}
42+
$mdContent .= "\n\n";
43+
}
44+
45+
$mdFile = API_ROOT . '/data/phalapi_database_wiki.md';
46+
file_put_contents($mdFile, $mdContent);
47+
48+
echo "$mdFile 已保存!", PHP_EOL;
49+
50+
function getKeyStr($key) {
51+
$map = array(
52+
'UNI' => '',
53+
'MUL' => '',
54+
);
55+
return $key;
56+
}

data/phalapi_database_wiki.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# phalapi数据库字典
2+
3+
## phalapi_curd表结构
4+
字段|类型|默认值|是否允许为NULL|索引|注释
5+
---|---|---|---|---|---
6+
id|int(10)||不为NULL|PRI|
7+
title|varchar(20)||允许NULL||
8+
content|text||允许NULL||
9+
state|tinyint(4)||允许NULL||
10+
post_date|datetime||允许NULL||
11+
12+
13+
## phalapi_portal_admin表结构
14+
字段|类型|默认值|是否允许为NULL|索引|注释
15+
---|---|---|---|---|---
16+
id|int(11)||不为NULL|PRI|
17+
username|varchar(20)||不为NULL|UNI|管理员账号
18+
password|varchar(100)||不为NULL||密码
19+
salt|varchar(64)||不为NULL||盐值
20+
role|varchar(20)|admin|不为NULL||管理员角色,admin普通管理员,super超级管理员
21+
state|tinyint(4)|1|不为NULL||状态,1可用0禁止
22+
created_at|datetime||允许NULL||创建时间
23+
24+
25+
## phalapi_portal_admin_role表结构
26+
字段|类型|默认值|是否允许为NULL|索引|注释
27+
---|---|---|---|---|---
28+
id|int(11)||不为NULL|PRI|
29+
role|varchar(20)||不为NULL||管理员角色
30+
role_name|varchar(255)||不为NULL||管理员角色名称
31+
32+
33+
## phalapi_portal_menu表结构
34+
字段|类型|默认值|是否允许为NULL|索引|注释
35+
---|---|---|---|---|---
36+
id|int(11)||不为NULL|PRI|
37+
title|varchar(50)||允许NULL||
38+
icon|varchar(50)||允许NULL||
39+
href|varchar(255)||允许NULL||
40+
target|varchar(10)|_self|允许NULL||
41+
sort_num|int(11)|0|允许NULL||
42+
parent_id|int(11)|0|允许NULL||
43+
assign_admin_roles|varchar(1000)||允许NULL||管理员角色分配,多个用竖线分割
44+
assgin_admin_usernames|text||允许NULL||分配的管理员ID,多个用竖线分割
45+
46+
47+
## phalapi_portal_menu_copy表结构
48+
字段|类型|默认值|是否允许为NULL|索引|注释
49+
---|---|---|---|---|---
50+
id|int(11)||不为NULL|PRI|
51+
title|varchar(50)||允许NULL||
52+
icon|varchar(50)||允许NULL||
53+
href|varchar(255)||允许NULL||
54+
target|varchar(10)|_self|允许NULL||
55+
sort_num|int(11)|0|允许NULL||
56+
parent_id|int(11)|0|允许NULL||
57+
assign_admin_roles|varchar(1000)||允许NULL||管理员角色分配,多个用竖线分割
58+
assgin_admin_usernames|text||允许NULL||分配的管理员ID,多个用竖线分割
59+
60+
61+
## phalapi_user表结构
62+
字段|类型|默认值|是否允许为NULL|索引|注释
63+
---|---|---|---|---|---
64+
id|int(10) unsigned||不为NULL|PRI|UID
65+
username|varchar(100)||不为NULL|UNI|用户名
66+
nickname|varchar(50)||允许NULL||昵称
67+
password|varchar(64)||不为NULL||密码
68+
salt|varchar(32)||允许NULL||随机加密因子
69+
reg_time|int(11)|0|允许NULL||注册时间
70+
avatar|varchar(500)||允许NULL||头像
71+
mobile|varchar(20)||允许NULL||手机号
72+
sex|tinyint(4)|0|允许NULL||性别,1男2女0未知
73+
email|varchar(50)||允许NULL||邮箱
74+
75+
76+
## phalapi_user_session表结构
77+
字段|类型|默认值|是否允许为NULL|索引|注释
78+
---|---|---|---|---|---
79+
id|bigint(20) unsigned||不为NULL|PRI|
80+
user_id|bigint(20)|0|允许NULL||用户id
81+
token|varchar(64)||允许NULL||登录token
82+
client|varchar(32)||允许NULL||客户端来源
83+
times|int(6)|0|允许NULL||登录次数
84+
login_time|int(11)|0|允许NULL||登录时间
85+
expires_time|int(11)|0|允许NULL||过期时间
86+
ext_data|text||允许NULL||json data here
87+
88+

0 commit comments

Comments
 (0)