fix readme docker compose commands and remove duplicate content

This commit is contained in:
2026-02-24 13:06:24 +08:00
parent 09a45095fa
commit bf42f97424

View File

@@ -15,10 +15,11 @@ Reusable SQLModel + PostgreSQL kit with src layout, sync/async engines, and gene
- Run tests: `uv pip install pytest && pytest -q`
## Local Postgres (Docker)
- Start the container: `docker compose -f docker/docker-compose.yml up -d`
- Stop when done: `docker compose -f docker/docker-compose.yml down`
- Start the container: `docker compose up -d`
- Stop when done: `docker compose down`
- Default credentials match `DatabaseConfig`: user `appuser`, password `changeme`, database `appdb`
- Export `SQL_SSLMODE=disable` (container does not use TLS by default)
- Port: 5433 (mapped from container 5432)
## Usage
- Configure environment (either `SQL_*` or Postgres `PG*` vars). Example for container ADDR:
@@ -398,53 +399,9 @@ Then open one of the notebooks under `notebooks/` to follow along.
- For production, prefer `sslmode=verify-full`, least-privileged DB users, and consider PgBouncer.
- Bring your own Alembic migrations; set `target_metadata = SQLModel.metadata` in env.py.
## apple container start command
## Tests via Makefile
```shell
# 停止并删除现有容器
container stop pg-app
container delete pg-app
container run \
--name pg-app \
--detach \
--mount type=tmpfs,target=/var/lib/postgresql/data \
--volume ./docker-init:/docker-entrypoint-initdb.d \
--env POSTGRES_USER=postgres \
--env POSTGRES_PASSWORD=change-me-strong \
--env POSTGRES_INITDB_ARGS="--encoding=UTF8 --locale=en_US.UTF-8" \
postgres:16
container ls --all
container logs pg-app
```
## set environment variables
```bash
export SQL_HOST=192.168.64.8
export SQL_PORT=5432
export SQL_USER=postgres
export SQL_PASSWORD=change-me-strong
export SQL_DATABASE=appdb
export SQL_SSLMODE=disable
```
## make test with uv
测试连接
现在您可以使用psql测试PostgreSQL连接
```bash
psql -h $SQL_HOST -p $SQL_PORT -U $SQL_USER -d $SQL_DATABASE -c '\l'
```
```bash
make test-pg-once
```
## Verify data with psql
- List tables: `\dt`
- Inspect example tables (depending on the example you ran), e.g.:
- `SELECT * FROM hero ORDER BY id DESC LIMIT 10;`
- `SELECT * FROM dataset ORDER BY id DESC LIMIT 10;`
- `make test-sqlite`: run fast smoke tests on SQLite (no Postgres needed)
- `make test`: run all tests found by pytest
- `make test-pg`: run Postgres integration once on current Python (requires SQL_*/PG* env)
- `make test-pg-once`: run Postgres integration across Python 3.103.13 (requires `uv` and SQL_*/PG* env)