feat: migrate database from SQLite to MySQL with .env configuration

- Replace go-sqlite3 with go-sql-driver/mysql (pure Go, no CGO needed)
- Add joho/godotenv for .env file loading
- Rewrite database/db.go with MySQL-compatible DDL (BIGINT AUTO_INCREMENT, InnoDB, utf8mb4)
- Convert all SQLite-specific SQL: INSERT OR IGNORE → INSERT IGNORE,
  INSERT OR REPLACE → INSERT ... ON DUPLICATE KEY UPDATE,
  datetime('now') → NOW(), date arithmetic → DATE_SUB()
- Add MySQL config fields to config.go (host/port/user/password/database)
- Add .env.example with connection parameter template
- Update Dockerfile: remove CGO/gcc/musl dependency, smaller build
- Update docker-compose.yml: add MySQL service container with healthcheck
- Update CLAUDE.md documentation
This commit is contained in:
2026-06-20 22:40:46 +08:00
parent 6c60b767df
commit 00c1839635
14 changed files with 130 additions and 102 deletions
+12 -8
View File
@@ -8,7 +8,7 @@ PR-Helper is a self-hosted web service that auto-generates PR descriptions from
## Tech Stack
- **Backend**: Go + Gin + SQLite (go-sqlite3) + go-git
- **Backend**: Go + Gin + MySQL + go-git
- **Frontend**: Go html/template + HTMX + D3.js + diff2html + Tailwind CSS
- **LLM**: OpenAI-compatible API (SSE streaming)
- **Deploy**: Docker
@@ -16,14 +16,17 @@ PR-Helper is a self-hosted web service that auto-generates PR descriptions from
## Build & Run
```bash
# Build (CGO required for SQLite)
CGO_ENABLED=1 go build -o pr-helper .
# Build
go build -o pr-helper .
# Run
# Configure — copy .env.example to .env and set MySQL credentials
cp .env.example .env
# Run (requires MySQL server)
./pr-helper
# Server listens on :8080
# Docker
# Docker (includes MySQL container)
docker compose up --build
```
@@ -33,13 +36,13 @@ docker compose up --build
handlers/ → HTTP handlers (pages + JSON API + SSE endpoints)
services/ → Business logic (git ops, LLM calls, PDF gen, cache management)
models/ → Data models (repository, settings, analysis)
database/ → SQLite init and migrations
database/ → MySQL init and migrations
config/ → Configuration loading
templates/ → Go HTML templates (layouts/, pages/, partials/)
static/ → CSS (Tailwind output), JS (graph, diff-viewer, sse), vendor libs
```
**Data flow**: Browser ↔ Gin handlers → services (git/llm) → SQLite + filesystem (`data/`)
**Data flow**: Browser ↔ Gin handlers → services (git/llm) → MySQL + filesystem (`data/`)
**Key service layer responsibilities**:
- `services/git.go` — clone, diff, graph data extraction via go-git
@@ -63,8 +66,9 @@ static/ → CSS (Tailwind output), JS (graph, diff-viewer, sse), vendor libs
## Data Storage
- SQLite DB at `data/pr-helper.db` — settings (KV), repositories, analyses, review_notes
- MySQL database `pr_helper` — settings (KV), repositories, analyses, review_notes
- Cloned repos cached at `data/repos/` with configurable expiry (default 7 days)
- Database connection configured via `.env` file (see `.env.example`)
## Development Notes