chore(dev): 添加本地 MySQL seed 环境

This commit is contained in:
2026-05-11 20:51:43 +08:00
parent 3040608959
commit ddd077eb37
6 changed files with 175 additions and 107 deletions
+27 -26
View File
@@ -1,39 +1,40 @@
services:
migrate:
build: .
db:
image: mysql:8.4
ports:
- "3306:3306"
volumes:
- ./volumes/mysql/data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: battery_soh
MYSQL_USER: battery
MYSQL_PASSWORD: battery
healthcheck:
test: [ "CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-ubattery", "-pbattery" ]
interval: 5s
timeout: 5s
retries: 20
seed:
image: oven/bun:1.3.13
restart: "no"
depends_on:
db:
condition: service_healthy
volumes:
- .:/app
environment:
- DATABASE_URL=postgres://postgres:postgres@db:5432/postgres
command: ["./server", "migrate"]
restart: "no"
- DATABASE_URL=mysql://battery:battery@db:3306/battery_soh
command: [ "sh", "-lc", "bun install --frozen-lockfile && bun run seed" ]
working_dir: /app
app:
build: .
depends_on:
db:
condition: service_healthy
migrate:
seed:
condition: service_completed_successfully
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgres://postgres:postgres@db:5432/postgres
db:
image: postgres:18-alpine
volumes:
- postgres_data:/var/lib/postgresql
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
healthcheck:
test: [ "CMD", "pg_isready", "-U", "postgres" ]
interval: 10s
timeout: 5s
retries: 5
volumes:
postgres_data:
- DATABASE_URL=mysql://battery:battery@db:3306/battery_soh