From 50587c53cb2340c1bdffaf96b6fc9a256567a9db Mon Sep 17 00:00:00 2001
From: Hai Liang Wang
Date: Wed, 28 Dec 2022 15:13:13 +0800
Subject: [PATCH] https://github.com/cskefu/cskefu/issues/779 add design folder
and store schema info
Signed-off-by: Hai Liang Wang
---
design/schema/.gitignore | 37 +
design/schema/README.md | 15 +
design/schema/app/generator.php | 123 ++++
design/schema/assets/standalone.html | 88 +++
design/schema/bin/gen-mysql-table-dicts.sh | 66 ++
design/schema/sample.env | 8 +
docs/index.html | 16 +
docs/mysql-dicts.html | 819 +++++++++++++++++++++
8 files changed, 1172 insertions(+)
create mode 100644 design/schema/.gitignore
create mode 100644 design/schema/README.md
create mode 100644 design/schema/app/generator.php
create mode 100644 design/schema/assets/standalone.html
create mode 100644 design/schema/bin/gen-mysql-table-dicts.sh
create mode 100644 design/schema/sample.env
create mode 100644 docs/index.html
create mode 100644 docs/mysql-dicts.html
diff --git a/design/schema/.gitignore b/design/schema/.gitignore
new file mode 100644
index 00000000..d35f24c5
--- /dev/null
+++ b/design/schema/.gitignore
@@ -0,0 +1,37 @@
+.vscode
+*.swp
+*.swo
+*.sublime-*
+*.pyc
+jmeter.log
+__pycache__
+tmp/
+package-lock.json
+node_modules/
+sftp-config.json
+.DS_Store
+*.iml
+*.ipr
+*.iws
+*.idea
+~$*.xls*
+~$*.ppt*
+~$*.doc*
+nohup.out
+
+CMakeLists.txt.user
+CMakeCache.txt
+CMakeFiles
+CMakeScripts
+Testing
+Makefile
+build
+build-*
+cmake_install.cmake
+install_manifest.txt
+compile_commands.json
+CTestTestfile.cmake
+_deps
+.env
+.fid
+_build
diff --git a/design/schema/README.md b/design/schema/README.md
new file mode 100644
index 00000000..41a876b6
--- /dev/null
+++ b/design/schema/README.md
@@ -0,0 +1,15 @@
+# 数据字典
+
+生成春松客服数据库数据字典。
+
+## Prerequisite
+
+* Php
+* pandoc
+
+## Generate
+
+```
+cp sample.env .env
+./bin/gen-mysql-table-dicts.sh
+```
\ No newline at end of file
diff --git a/design/schema/app/generator.php b/design/schema/app/generator.php
new file mode 100644
index 00000000..8f85bc00
--- /dev/null
+++ b/design/schema/app/generator.php
@@ -0,0 +1,123 @@
+ $v){
+ $sql = 'SELECT * FROM ';
+ $sql .= 'INFORMATION_SCHEMA.TABLES ';
+ $sql .= 'WHERE ';
+ $sql .= "table_name = '{$v['TABLE_NAME']}' AND table_schema = '".DB_NAME."'";
+ $table_result = mysqli_query($conn, $sql);
+ while($t = mysqli_fetch_array($table_result)) {
+ $tables [$k] ['TABLE_COMMENT'] = $t ['TABLE_COMMENT'];
+ }
+
+ $sql = 'SELECT * FROM ';
+ $sql .= 'INFORMATION_SCHEMA.COLUMNS ';
+ $sql .= 'WHERE ';
+ $sql .= "table_name = '{$v['TABLE_NAME']}' AND table_schema = '".DB_NAME."'";
+
+ $fields = array();
+ $field_result = mysqli_query($conn, $sql);
+ while($t = mysqli_fetch_array($field_result)) {
+ $fields [] = $t;
+ }
+ $tables [$k] ['COLUMN'] = $fields;
+}
+mysqli_close($conn);
+
+$content = '';
+// 循环所有表
+foreach($tables as $k => $v){
+ $content .= ''. $v['TABLE_NAME'] . '
';
+ $content .= '';
+ $content .= '' . ' ' . $v ['TABLE_COMMENT'] . '';
+ $content .= '字段名 | 数据类型 | 默认值 |
+ 允许非空 |
+ 自动递增 | 备注 |
';
+ $content .= '';
+
+ foreach($v ['COLUMN'] as $f){
+ $content .= '' . $f ['COLUMN_NAME'] . ' | ';
+ $content .= '' . $f ['COLUMN_TYPE'] . ' | ';
+ $content .= ' ' . $f ['COLUMN_DEFAULT'] . ' | ';
+ $content .= ' ' . $f ['IS_NULLABLE'] . ' | ';
+ $content .= '' . ($f ['EXTRA'] == 'auto_increment' ? '是' : ' ') . ' | ';
+ $content .= ' ' . $f ['COLUMN_COMMENT'] . ' | ';
+ $content .= '
';
+ }
+ $content .= '
';
+}
+
+// 输出
+$date = date('Y-m-d');
+$html = <<
+
+
+$title
+
+
+
+$title(生成日期: $date)
+版本:$version,SQL:下载链接,Models PDF:下载链接
+$content
+
+
+ - 春松客服, https://www.cskefu.com -
+
+