Files
score-backend/README.md
ethan.chen d296108f67 添加数据库自动初始化功能
- 创建 db/init.ts 脚本,可自动创建数据库和表
- 更新 db/index.ts,应用启动时自动检查并创建表结构
- 添加 bun run init-db 命令用于初始化数据库
- 更新 README.md 添加数据库初始化说明
2026-01-08 14:58:04 +08:00

50 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 安装依赖
```bash
bun install
```
## 运行项目
```bash
# 开发模式(带热重载)
bun run dev
# 生产模式
bun run start
```
## 数据库初始化
首次运行前,需要初始化数据库:
```bash
# 方式一:使用初始化脚本(推荐,会自动创建数据库和表)
bun run init-db
# 方式二:手动创建数据库和表
# 1. 创建数据库
createdb media
# 或使用 psql
psql -U postgres -c "CREATE DATABASE media;"
# 2. 创建表结构
psql -U postgres -d media -f db/schema.sql
```
## 环境变量
配置以下环境变量:
- `PORT`: 服务器端口(默认: 8000
- `AUTH_SECRET`: JWT 密钥(默认: it-is-a-secret
- `DATABASE_URL`: PostgreSQL 连接字符串
- 或使用独立变量:
- `DB_USER`: 数据库用户(默认: postgres
- `DB_PASSWORD`: 数据库密码(默认: postgres
- `DB_HOST`: 数据库主机(默认: localhost
- `DB_PORT`: 数据库端口(默认: 5432
- `DB_NAME`: 数据库名称(默认: media
**注意**:应用启动时会自动检查并创建表结构(如果不存在),但不会自动创建数据库。请确保数据库已存在。