From 5dff56bbb25a72f720e01f86c224b646245272d7 Mon Sep 17 00:00:00 2001 From: guke Date: Wed, 8 Jul 2026 17:52:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(dev):=20docker-compose=20=E8=B5=B7?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=20PostgreSQL(=E5=90=AB=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=BA=93=20initdb)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 22 ++++++++++++++++++++++ docker/initdb/01-create-test-db.sql | 3 +++ 2 files changed, 25 insertions(+) create mode 100644 docker-compose.yml create mode 100644 docker/initdb/01-create-test-db.sql diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d8e778f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +# 本地开发/测试用 PostgreSQL。生产用原生 PG(scripts/init_postgres.py),不使用本文件。 +services: + postgres: + image: postgres:16-alpine + container_name: shaguabijia-pg + environment: + POSTGRES_USER: shaguabijia_app + POSTGRES_PASSWORD: shaguabijia_dev_pw + POSTGRES_DB: shaguabijia + ports: + - "5432:5432" + volumes: + - pgdata:/var/lib/postgresql/data + - ./docker/initdb:/docker-entrypoint-initdb.d:ro + healthcheck: + test: ["CMD-SHELL", "pg_isready -U shaguabijia_app -d shaguabijia"] + interval: 3s + timeout: 3s + retries: 20 + +volumes: + pgdata: diff --git a/docker/initdb/01-create-test-db.sql b/docker/initdb/01-create-test-db.sql new file mode 100644 index 0000000..440ecca --- /dev/null +++ b/docker/initdb/01-create-test-db.sql @@ -0,0 +1,3 @@ +-- 仅在 pgdata 卷首次初始化时执行一次(以 shaguabijia_app 连 shaguabijia 库运行)。 +-- 幂等兜底见 scripts/ensure_pg.py 的 _ensure_test_db()。 +CREATE DATABASE shaguabijia_test OWNER shaguabijia_app;