fix readme docker compose commands and remove duplicate content
This commit is contained in:
59
README.md
59
README.md
@@ -15,10 +15,11 @@ Reusable SQLModel + PostgreSQL kit with src layout, sync/async engines, and gene
|
|||||||
- Run tests: `uv pip install pytest && pytest -q`
|
- Run tests: `uv pip install pytest && pytest -q`
|
||||||
|
|
||||||
## Local Postgres (Docker)
|
## Local Postgres (Docker)
|
||||||
- Start the container: `docker compose -f docker/docker-compose.yml up -d`
|
- Start the container: `docker compose up -d`
|
||||||
- Stop when done: `docker compose -f docker/docker-compose.yml down`
|
- Stop when done: `docker compose down`
|
||||||
- Default credentials match `DatabaseConfig`: user `appuser`, password `changeme`, database `appdb`
|
- Default credentials match `DatabaseConfig`: user `appuser`, password `changeme`, database `appdb`
|
||||||
- Export `SQL_SSLMODE=disable` (container does not use TLS by default)
|
- Export `SQL_SSLMODE=disable` (container does not use TLS by default)
|
||||||
|
- Port: 5433 (mapped from container 5432)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
- Configure environment (either `SQL_*` or Postgres `PG*` vars). Example for container ADDR:
|
- 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.
|
- 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.
|
- Bring your own Alembic migrations; set `target_metadata = SQLModel.metadata` in env.py.
|
||||||
|
|
||||||
## apple container start command
|
## Tests via Makefile
|
||||||
|
|
||||||
```shell
|
- `make test-sqlite`: run fast smoke tests on SQLite (no Postgres needed)
|
||||||
# 停止并删除现有容器
|
- `make test`: run all tests found by pytest
|
||||||
container stop pg-app
|
- `make test-pg`: run Postgres integration once on current Python (requires SQL_*/PG* env)
|
||||||
container delete pg-app
|
- `make test-pg-once`: run Postgres integration across Python 3.10–3.13 (requires `uv` and SQL_*/PG* env)
|
||||||
|
|
||||||
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;`
|
|
||||||
|
|||||||
Reference in New Issue
Block a user