2024-02-28 08:32:35 +08:00
|
|
|
|
|
|
|
## 环境要求
|
|
|
|
|
|
|
|
- `nodejs` `16.20.2`+
|
|
|
|
- `docker` `20.x`+ ,其中 `docker compose`版本需要 `2.17.0`+
|
|
|
|
- `mysql` `8.x`+
|
|
|
|
- 使用 [`pnpm`](https://pnpm.io/zh/) 包管理器安装项目依赖
|
|
|
|
|
|
|
|
|
|
|
|
| 账号 | 密码 | 权限 |
|
|
|
|
| :-------: | :----: | :--------: |
|
|
|
|
| admin | a123456 | 超级管理员 |
|
|
|
|
|
|
|
|
|
|
|
|
## 本地开发
|
|
|
|
|
|
|
|
- 【可选】如果你是新手,还不太会搭建`mysql/redis`,你可以使用 `Docker` 启动指定服务供本地开发时使用, 例如:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# 启动MySql服务
|
|
|
|
docker compose --env-file .env --env-file .env.development run -d --service-ports mysql
|
|
|
|
# 启动Redis服务
|
|
|
|
docker compose --env-file .env --env-file .env.development run -d --service-ports redis
|
|
|
|
```
|
|
|
|
|
|
|
|
- 安装依赖
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
|
|
pnpm install
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
- 运行
|
|
|
|
启动成功后,通过 <http://localhost:7001/api-docs/> 访问。
|
|
|
|
|
|
|
|
```bash
|
|
|
|
pnpm dev
|
|
|
|
```
|
|
|
|
|
|
|
|
- 打包
|
|
|
|
|
|
|
|
```bash
|
|
|
|
pnpm build
|
|
|
|
```
|
|
|
|
|
|
|
|
2.使用docker运行
|
|
|
|
|
|
|
|
```bash
|
|
|
|
docker compose up -d
|
|
|
|
```
|
|
|
|
|
|
|
|
停止并删除所有容器
|
|
|
|
|
|
|
|
```bash
|
|
|
|
pnpm docker:down
|
|
|
|
# or
|
|
|
|
docker compose --env-file .env --env-file .env.production down
|
|
|
|
```
|
|
|
|
|
|
|
|
删除镜像
|
|
|
|
|
|
|
|
```bash
|
|
|
|
pnpm docker:rmi
|
|
|
|
# or
|
2024-02-28 16:12:34 +08:00
|
|
|
docker rmi huaxin-admin-server:stable
|
2024-02-28 08:32:35 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
查看实时日志输出
|
|
|
|
|
|
|
|
```bash
|
|
|
|
pnpm docker:logs
|
|
|
|
# or
|
|
|
|
docker compose --env-file .env --env-file .env.production logs -f
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
## 数据库迁移
|
|
|
|
|
|
|
|
1. 更新数据库(或初始化数据)
|
|
|
|
|
|
|
|
```bash
|
|
|
|
pnpm migration:run
|
|
|
|
```
|
|
|
|
|
|
|
|
2. 生成迁移
|
|
|
|
|
|
|
|
```bash
|
|
|
|
pnpm migration:generate
|
|
|
|
```
|
|
|
|
|
|
|
|
3. 回滚到最后一次更新
|
|
|
|
|
|
|
|
```bash
|
|
|
|
pnpm migration:revert
|
|
|
|
```
|
2024-03-01 16:54:21 +08:00
|
|
|
4.执行sql覆盖docker中的数据库
|
|
|
|
|
|
|
|
```bash
|
2024-03-28 12:48:22 +08:00
|
|
|
docker exec -i huaxin-admin-mysql mysql -h 127.0.0.1 -u root -phuaxin123 hxoa < huaxinoa0327.sql
|
2024-03-01 16:54:21 +08:00
|
|
|
```
|
2024-02-28 08:32:35 +08:00
|
|
|
|
|
|
|
更多细节,请移步至[官方文档](https://typeorm.io/migrations)
|
|
|
|
|
|
|
|
> [!TIP]
|
|
|
|
> 如果你的`实体类`或`数据库配置`有更新,请执行`npm run build`后再进行数据库迁移相关操作。
|
|
|
|
|
2024-03-01 16:54:21 +08:00
|
|
|
### 部署
|
|
|
|
chmod +x deploy.sh
|
|
|
|
./deploy.sh
|