| name | testing |
| description | Run and test the example-app against a local PostgreSQL database. USE FOR: starting Postgres via Docker Compose, running SQL migrations, building with code generation, running the example app, verifying generated queries work end-to-end. DO NOT USE FOR: writing unit tests, CI/CD pipeline setup. |
| argument-hint | Describe what you want to test or verify |
Testing the Example App
Prerequisites
- Docker (with Compose v2)
- Rust toolchain (cargo)
psql CLI (from postgresql-client or equivalent)
1. Start PostgreSQL
From the workspace root:
docker compose up -d
This starts PostgreSQL 17 on port 55432 with:
- User:
postgres
- Password:
password
- Database:
postgres
Wait for healthy status:
docker compose ps
2. Set the Database URL
export AUTOMODEL_DATABASE_URL="postgresql://postgres:password@automodel-testdb:5432/postgres"
set -x AUTOMODEL_DATABASE_URL "postgresql://postgres:password@automodel-testdb:5432/postgres"
Note, if you are developing from a container, database URL need to be asjusted to connect to the Postgres container directly
3. Run Migrations
bash scripts/migrate.sh
4. Build the Example App (Code Generation)
The build script in example-app/build.rs connects to the database at compile time to introspect queries and generate typed Rust code:
cargo build -p example-app
If AUTOMODEL_DATABASE_URL is not set, the build will fail with an error. This is expected — the code generator requires a live database connection.
5. Run the Example App
cargo run -p example-app
This executes all the test functions in example-app/src/main.rs against the database.
6. Run the Test Suite
cargo test -p example-app
Runs all integration tests in example-app/tests/.
7. Full Regeneration (Invalidate + Rebuild + Test)
To force a complete regeneration of all generated code and verify everything works:
rm example-app/src/generated/mod.rs
cargo build -p example-app
cargo test -p example-app
This is useful before releases or after changes to the codegen logic. AutoModel detects the missing mod.rs and regenerates all files.
8. Tear Down
Stop and remove the container (data preserved in volume):
docker compose down
To also wipe the database volume:
docker compose down -v
Quick One-Liner (bash)
docker compose up -d && \
sleep 2 && \
export AUTOMODEL_DATABASE_URL="postgresql://postgres:password@automodel-testdb:5432/postgres" && \
bash scripts/migrate.sh && \
cargo run -p example-app
Troubleshooting