feat: update docs (#47)

This commit is contained in:
vran
2022-03-13 22:15:23 +08:00
committed by GitHub
parent 6e798f4d97
commit 4b36dda6c2
35 changed files with 177 additions and 166 deletions

117
docs/README/build.md Normal file
View File

@@ -0,0 +1,117 @@
# 构建指南
## 前言
Databasir 采用了前后端分离的模式进行开发和部署,项目仓库地址分别位于
- 后端应用: https://github.com/vran-dev/databasir
- 前端应用: https://github.com/vran-dev/databasir-frontend
## 后端
**一、环境要求**
1. Java 11+
2. Mysql
3. Intellij IDEA
**二、主要框架**
1. Gradle构建工具
2. Spring-boot核心框架
1. Web
2. Security
3. Quartz定时任务调度
4. JOOQORM 框架
5. Lombok代码生成
6. Mapstruct代码生成
7. Flyway数据库脚本管理
**三、项目结构**
项目结构采用了分层结构
- api所有的 http 接口、定时任务都在该模块下
- common主要包含通用异常定义、加解密算法工具
- core包含了所有的业务核心逻辑包括 service、request/response data、converter 等
- dao针对数据库的操作类都在该模块下其中 generated-src 包含了 jooq 生成的代码src 主要包含了 dao 的实现类
- plugin主要包含了 JDBC 工具类,包括但不限于将数据库的元数据解析为 Java 对象 、PDF 导出等
项目配置都放在 api/src/main/resources 目录下
前端静态文件放在 api/src/main/resources/static 目录下
项目数据库脚本放在 dao/src/main/resources/db/migration 目录下
**四、项目启动**
1、通过 Java Main 方法启动
修改或创建配置文件 `api/src/main/resources/application-local.properties`
```properties
server.port=8080
logging.level.org.jooq=INFO
# 必须:数据库配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.url=jdbc:mysql://localhost:3306/databasir
spring.jooq.sql-dialect=mysql
# 可选flyway 配置
spring.flyway.enabled=true
spring.flyway.baseline-on-migrate=true
spring.flyway.locations=classpath:db/migration
```
启动 DatabasirApplicationcom.databasir.DatabasirApplication 类,启动时需要加参数 `-Dspring.profiles.active=local`
启动完成后,可以通过 http://localhost:8080 访问
2、通过 Gradle 启动
与 Java 启动模式一样,首先需要准备配置文件
修改或创建配置文件 `api/src/main/resources/application-local.properties`
```properties
server.port=8080
logging.level.org.jooq=INFO
# 必须:数据库配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.url=jdbc:mysql://localhost:3306/databasir
spring.jooq.sql-dialect=mysql
# 可选flyway 配置
spring.flyway.enabled=true
spring.flyway.baseline-on-migrate=true
spring.flyway.locations=classpath:db/migration
```
执行 Gradle 命令
```shell
./gradlew bootRun --args='--spring.profiles.active=local'
```
启动完成后,可以通过 http://localhost:8080 访问
## 前端
一、依赖
1. vue
2. vuex
3. element-plus
4. axios
二、运行
```shell
npm run serve
```
默认端口为 3000

View File

@@ -0,0 +1,11 @@
# 扩展数据库类型
## 说明
[Databasir](https://github.com/vran-dev/databasir) 理论上是支持所有**拥有 JDBC 驱动的数据库**,系统已为 Mysql、Postgresql 提供了内置的支持,这两种数据库可以开箱即用。
对于其它数据库(有 JDBC 驱动),用户也只需要简单的配置就可以支持
## 配置

View File

@@ -0,0 +1,57 @@
# Docker 部署
[Databasir](https://github.com/vran-dev/databasir) 现在已经准备好了开箱即用的 Docker Image你只需要简单两步就可以完成一个 Databasir 应用的构建
## 环境要求
1. Docker
2. Mysql
## 部署流程
1. 拉取最新版镜像,当然你也可以将 latest 替换成你想要得版本号,具体有哪些镜像版本可以拉取可以在[这里](https://registry.hub.docker.com/r/vrantt/databasir)查看
```shell
docker pull vrantt/databasir:latest
```
2. 镜像下载完成以后就可以直接启动了
```shell
docker run --name my-databasir -e DATABASIR_DB_URL=127.0.0.1:3306 -e DATABASIR_DB_USERNAME=root -e DATABASIR_DB_PASSWORD=123456 databasir:latest -p 8888:8080
```
这里解释一下各个命令参数
- `--name` 代表镜像启动后的名称,你可以随意命名
- `-e` 指定环境变量databasir 需要依赖 3 个环境变量,所以用 `-e` 指定了 3 个变量,它们分别是
1. DATABASIR_DB_URL 数据库地址
2. DATABASIR_DB_USERNAME 数据库账号名称
3. DATABASIR_DB_PASSWORD 数据库密码
- `-p` 暴露端口databasir 默认在容器内部开放了 8080 端口,这里将宿主机的 8888 端口映射到了容器的 8080 端口
启动后Databasir 会默认创建一个超级管理员账户
- 用户名databasir
- 密码databasir
这时候访问 http://localhost:8888 进入登录页,输入上面的账号和密码即可成功登入。
## 登录验证
应用启动完成后会默认创建 Databasir 管理员用户
- 用户名databasir
- 密码databasir
通过该账号登录应用既可以进行管理

View File

@@ -0,0 +1,34 @@
# Jar 包部署
## 环境要求
1. Java 11+
2. Mysql
## 部署流程
1. 在 [Github RELEASE](https://github.com/vran-dev/databasir/releases) 页面下载最新版应用 Databasir.jar (你也可以选择克隆项目后自行构建)
2. 将 Databasir.jar 上传到服务器
3. 在 Databasir.jar 所在目录创建 config 目录,并在目录下创建 `application.properties` 配置,配置中配置 MYSQL 的用户名、密码和连接
```properties
# 端口号,默认 8080
server.port=8080
# 数据库用户名
databasir.db.username=root
# 数据库密码
databasir.db.password=123456
# 数据库地址
databasir.db.url=127.0.0.1:3306
```
4. 通过 `java -jar Databasir.jar` 启动应用即可
## 登录验证
应用启动完成后会默认创建 Databasir 管理员用户
- 用户名databasir
- 密码databasir
通过该账号登录应用既可以进行管理

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

@@ -0,0 +1,56 @@
# Databasir 配置 Github OAuth2 登录
1. **创建 Github OAuth Application**
![github-app-create](img/1-github-oauth2-app-create.png)
2. **填写 Github 应用资料**
Homepage URL 填写你部署 databasir 后,可访问的公网域名。
Authorization callback URL 你可以先填写 {{ databasir 域名 }}/login/oauth2/{{ registrationId }},这里的 registrationId 你可以任意填写,只需要稍后在 Databasir 中配置时保持一致即可,我这里填写了 vran_github
![github-oauth2](img/2-github-oauth2-create.png)
3. 申请 client secret
点击 `Generate a new client secret`,生成秘钥以后记得复制暂存一下,以后是看不见原始秘钥的了
![oauth2-github](img/3-github-oauth2-create.png)
4. 保存 Client Id 和刚刚生成的 Client Secret
![oauth2-github](img/4-github-oauth2-create.png)
5. 进入 Databasir 系统管理 -> 登录设置
![databasir](img/5-github-oauth-create.png)
6. 最后一步,创建并保存登录应用
还记得我在第 2 步时候说的 `registrationId` 吗?那个就对应 databasir 中的 `应用 ID` ,只要两者保持一致就可以成功接受 github 的回调,要是前面配错了也可以在当前页面复制自动生成的 URL 去 github 重新填写 Authorization callback URL 就可以了。
注意授权地址和资源地址
- 授权地址:获取 access_token 的请求地址
- 资源地址:获取用户信息的请求地址
这里填写不一样是因为 github 官方将授权和资源地址分开的,如果你使用的时 github enterprise 版本,授权地址和资源地址其实是一样的。
![](img/6-github-oauth-create.png)
配置完成以后,注销登录后再次进入登录页面就会发现多了一个 github 的小图标,点击就可以使用 github 进行登录
![](img/7-github-oauth-create.png)
点击就会进入授权页面,授权完成就会创建一个新的 databasir 用户,并直接登录成功
![](img/8-github-oauth-create.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View File

@@ -0,0 +1,38 @@
# Databasir 配置 Github OAuth2 登录
1. 创建 Gitlab 应用,填写应用名称、回调地址等信息,注意下面授权一定记得勾选上 **read_user**
回调地址填写你访问 databasir 的公网地址 {{ databasir 地址 }}/login/oauth2/{{ 应用ID }}
这里我的应用 id 为 vran-gitlab后面在 databasir 配置的时候需要用上
![](img/1-gitlab-oauth2.png)
2. 保存好应用以后,就可以看见 Application Id 和 Secret复制这两个值
![](img/2-gitlab-oauth2.png)
3. 进入 Databasir 系统管理 -> 登录设置页面
![](img/3-gitlab-oauth2.png)
4. 创建并保存应用信息
- client Id 就对应申请到的 Application Id
- client secret 就对应申请到的 Application secret
- 应用 id 记得和我们第一步填写 redirect uri 时的应用 id 保持一致
![image-20220303225811673](img/4-gitlab-oauth2.png)
5. 保存完成以后注销登录,进入登录页面就可以看见多了一个 gitlab 的登录图标,点击就可以使用 gitlab 来登录了
![](img/5-gitlab-oauth2.png)
注意:如果登录出现 The redirect URI included is not valid. 这样的错误,请检查回调地址是否与 databasir 的地址一致,以及协议是否一致(比如 http 和 https
点击登录以后就会进入授权页面,授权完成以后就会新建一个 databasir 用户并自动完成登录
![](img/6-gitlab-oauth2.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 958 KiB

BIN
docs/README/log-list.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 380 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 893 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 KiB

BIN
docs/README/user-create.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 806 KiB

BIN
docs/README/user-detail.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 535 KiB