feat: embedded PostgreSQL — zero-config single-binary startup#77
Open
RyanLee-Dev wants to merge 1 commit into
Open
feat: embedded PostgreSQL — zero-config single-binary startup#77RyanLee-Dev wants to merge 1 commit into
RyanLee-Dev wants to merge 1 commit into
Conversation
When DATABASE_URL is unset and the server is in dev profile, the server automatically downloads a PostgreSQL binary (via embedded-postgres-go), initializes a data directory under ~/.parsar/postgres, runs goose migrations, and connects — no Docker, no external DB, no .env required. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
像 Coder 一样,
DATABASE_URL为空时自动启动内嵌 PostgreSQL,实现 一条命令启动完整 Parsar 服务(后端 + 前端 + 数据库),无需 Docker、无需外部数据库、无需.env文件。改动概览
server/internal/embeddedpg/embeddedpg.goserver/cmd/server/main.goopenPool()前检测空DATABASE_URL,启动内嵌 PG,自动跑 goose migration,接入 graceful shutdownstart.shgo.mod/go.sumgithub.com/fergusstrange/embedded-postgres v1.34.0依赖工作原理
孤儿进程处理
如果上次进程异常退出(如 Ctrl+C 杀了
go run但 PG 子进程未关停),再次启动时会自动检测端口 15432 是否被占用,如果是,先 kill 孤儿 PG 进程再启动新实例。快速启动
方式 1:一键脚本
脚本会:
apps/web/dist是否存在,不存在则先pnpm build前端方式 2:手动启动
方式 3:使用外部 PostgreSQL(生产 / 已有 DB)
# 设了 DATABASE_URL 就走原有逻辑,内嵌 PG 完全不触发 DATABASE_URL=postgres://user:pass@your-pg:5432/parsar \ go run ./server/cmd/server与 Docker Compose 方案对比
docker compose -f docker-compose.local.yml up./start.sh~/.parsar/postgres/两种方案并存,
docker-compose.local.yml不受任何影响。数据目录结构
注意事项
PARSAR_FEISHU_MOCK=true或 loopback PublicURL),生产环境仍强制要求外部DATABASE_URL~/.parsar/postgres/data/,删掉即重置Test plan
go build ./server/cmd/server编译通过DATABASE_URL,./start.sh 19090启动 — PG 自动下载、migration 完成、服务就绪curl http://127.0.0.1:19090/healthz→ 200curl http://127.0.0.1:19090/→ 200 text/html(前端 SPA)DATABASE_URL指向外部 PG → 确认跳过内嵌逻辑,行为不变🤖 Generated with Claude Code