ClickHouse Local Dev Loop
Overview
Run ClickHouse in Docker for local development with fast schema iteration, seed
data, and integration testing using vitest. This skill scaffolds a
Docker-Compose-based dev loop: an auto-migrating init script, a seed generator,
a reusable client singleton, and a truncate-between-tests integration harness —
so schema changes and query work stay a docker compose up away.
Prerequisites
- Docker or Docker Compose installed and running (
docker info succeeds).
- Node.js 18+ with the
@clickhouse/client package for the seed/test scripts.
- A local project directory you can Write files into. No cloud account or
network access is required — everything runs on
localhost.
Authentication
This is a local dev setup with no external ClickHouse Cloud service. The
container's credentials are declared inline in docker-compose.yml
(CLICKHOUSE_USER: default, CLICKHOUSE_PASSWORD: dev_password) and consumed by
the client via env vars (CLICKHOUSE_USER, CLICKHOUSE_PASSWORD,
CLICKHOUSE_HOST, CLICKHOUSE_DATABASE). Keep real per-developer overrides in a
git-ignored .env.local; commit only a .env.example. Never reuse
dev_password outside local development.
Instructions
Follow the seven-step build. The lean skeleton is below; the
full walkthrough carries the complete file
contents for every step.
Docker Compose setup — Write a docker-compose.yml exposing 8123
(HTTP) and 9000 (native TCP), mounting ./init-db for auto-migration and a
named volume for persistence:
services:
clickhouse:
image: clickhouse/clickhouse-server:latest
ports: ["8123:8123", "9000:9000"]
volumes:
- clickhouse-data:/var/lib/clickhouse
- ./init-db:/docker-entrypoint-initdb.d
environment:
CLICKHOUSE_PASSWORD: dev_password
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
volumes:
clickhouse-data:
Then docker compose up -d and verify with
curl http://localhost:8123/ping → Ok.
Init script — Write init-db/001-schema.sql with your
CREATE DATABASE / CREATE TABLE ... ENGINE = MergeTree() DDL. ClickHouse
auto-runs it on the container's first start.
Seed data — Write scripts/seed.ts that batch-inserts synthetic rows via
client.insert({ format: 'JSONEachRow' }).
Project structure — lay out init-db/, scripts/, src/, tests/, and
the .env.local / .env.example pair.
Client singleton — Write src/db.ts exposing a memoized getClient()
that reads connection settings from env vars with localhost fallbacks.
Integration testing — Write a vitest tests/setup.ts that TRUNCATEs
tables in beforeEach and closes the client in afterAll, then write
per-feature test files.
Package scripts — Edit package.json to add db:up, db:down,
db:reset, db:seed, db:shell, and test scripts.
Read the full walkthrough for the exact,
copy-pasteable contents of each file.
Output
Running this skill produces a working local ClickHouse dev loop:
- A running
clickhouse-server container reachable at http://localhost:8123
(HTTP) and localhost:9000 (native), answering curl .../ping with Ok.
- An auto-created
app database and schema from init-db/001-schema.sql.
- Seedable data via
npm run db:seed (default: 1000 synthetic events).
- A green vitest integration suite that inserts and queries against the live
container, resetting table state between tests.
- One-command lifecycle scripts (
db:up, db:down, db:reset, db:seed,
db:shell, test) wired into package.json.
Error Handling
| Error |
Cause |
Solution |
Connection refused :8123 |
Container not running |
docker compose up -d |
READONLY |
User lacks write perms |
Set CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1 |
Too many parts |
Tiny frequent inserts |
Batch inserts or increase parts_to_throw_insert |
Memory limit exceeded |
Large query on small container |
Add --memory 4g to Docker |
Examples
Bring the stack up, seed it, and confirm the rows landed:
docker compose up -d
curl http://localhost:8123/ping # → "Ok.\n"
npm run db:seed # seeds 1000 events
curl 'http://localhost:8123/?query=SELECT+count()+FROM+app.events' # → 1000
Open an interactive SQL shell:
docker exec -it <container> clickhouse-client --password dev_password
See more examples — server-state inspection, HTTP
queries, environment reset, and a passing integration-test run.
Resources
Next Steps
Once the local loop is green, see the clickhouse-sdk-patterns skill for
production-ready client patterns (connection pooling, retries, typed query
helpers, and async inserts) that build on the getClient() singleton above.
Source: jeremylongshore/claude-code-plugins-plus-skills → plugins/saas-packs/clickhouse-pack/skills/clickhouse-local-dev-loop/SKILL.md
1---2name: clickhouse-local-dev-loop3description: "| Run ClickHouse locally with Docker, configure test fixtures, and iterate fast. Use when setting up a local ClickHouse dev environment, writing integration tests against ClickHouse, or running ClickHouse in Docker Compose for local work. Trigger with \"clickhouse local dev\", \"clickhouse docker\", \"clickhouse dev environment\", \"run clickhouse locally\", \"clickhouse docker compose\"."4allowed-tools: "Read, Write, Edit, Bash(docker:*), Bash(docker-compose:*)"5category: testing-and-qa6source_repo: jeremylongshore/claude-code-plugins-plus-skills7source_path: "plugins/saas-packs/clickhouse-pack/skills/clickhouse-local-dev-loop/SKILL.md"8source_url: https://github.com/jeremylongshore/claude-code-plugins-plus-skills/blob/HEAD/plugins/saas-packs/clickhouse-pack/skills/clickhouse-local-dev-loop/SKILL.md9metadata:10 source: https://skillmd.com/skills/thedixitjain/clickhouse-local-dev-loop11---121314# ClickHouse Local Dev Loop1516## Overview1718Run ClickHouse in Docker for local development with fast schema iteration, seed19data, and integration testing using vitest. This skill scaffolds a20Docker-Compose-based dev loop: an auto-migrating init script, a seed generator,21a reusable client singleton, and a truncate-between-tests integration harness —22so schema changes and query work stay a `docker compose up` away.2324## Prerequisites2526- Docker or Docker Compose installed and running (`docker info` succeeds).27- Node.js 18+ with the `@clickhouse/client` package for the seed/test scripts.28- A local project directory you can Write files into. No cloud account or29 network access is required — everything runs on `localhost`.3031## Authentication3233This is a **local dev** setup with no external ClickHouse Cloud service. The34container's credentials are declared inline in `docker-compose.yml`35(`CLICKHOUSE_USER: default`, `CLICKHOUSE_PASSWORD: dev_password`) and consumed by36the client via env vars (`CLICKHOUSE_USER`, `CLICKHOUSE_PASSWORD`,37`CLICKHOUSE_HOST`, `CLICKHOUSE_DATABASE`). Keep real per-developer overrides in a38git-ignored `.env.local`; commit only a `.env.example`. Never reuse39`dev_password` outside local development.4041## Instructions4243Follow the seven-step build. The lean skeleton is below; the44[full walkthrough](references/implementation.md) carries the complete file45contents for every step.46471. **Docker Compose setup** — Write a `docker-compose.yml` exposing `8123`48 (HTTP) and `9000` (native TCP), mounting `./init-db` for auto-migration and a49 named volume for persistence:5051 ```yaml52 services:53 clickhouse:54 image: clickhouse/clickhouse-server:latest55 ports: ["8123:8123", "9000:9000"]56 volumes:57 - clickhouse-data:/var/lib/clickhouse58 - ./init-db:/docker-entrypoint-initdb.d59 environment:60 CLICKHOUSE_PASSWORD: dev_password61 CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 162 volumes:63 clickhouse-data:64 ```6566 Then `docker compose up -d` and verify with67 `curl http://localhost:8123/ping` → `Ok.`68692. **Init script** — Write `init-db/001-schema.sql` with your70 `CREATE DATABASE` / `CREATE TABLE ... ENGINE = MergeTree()` DDL. ClickHouse71 auto-runs it on the container's first start.723. **Seed data** — Write `scripts/seed.ts` that batch-inserts synthetic rows via73 `client.insert({ format: 'JSONEachRow' })`.744. **Project structure** — lay out `init-db/`, `scripts/`, `src/`, `tests/`, and75 the `.env.local` / `.env.example` pair.765. **Client singleton** — Write `src/db.ts` exposing a memoized `getClient()`77 that reads connection settings from env vars with `localhost` fallbacks.786. **Integration testing** — Write a vitest `tests/setup.ts` that TRUNCATEs79 tables in `beforeEach` and closes the client in `afterAll`, then write80 per-feature test files.817. **Package scripts** — Edit `package.json` to add `db:up`, `db:down`,82 `db:reset`, `db:seed`, `db:shell`, and `test` scripts.8384Read the [full walkthrough](references/implementation.md) for the exact,85copy-pasteable contents of each file.8687## Output8889Running this skill produces a working local ClickHouse dev loop:9091- A running `clickhouse-server` container reachable at `http://localhost:8123`92 (HTTP) and `localhost:9000` (native), answering `curl .../ping` with `Ok.`93- An auto-created `app` database and schema from `init-db/001-schema.sql`.94- Seedable data via `npm run db:seed` (default: 1000 synthetic events).95- A green vitest integration suite that inserts and queries against the live96 container, resetting table state between tests.97- One-command lifecycle scripts (`db:up`, `db:down`, `db:reset`, `db:seed`,98 `db:shell`, `test`) wired into `package.json`.99100## Error Handling101102| Error | Cause | Solution |103|-------|-------|----------|104| `Connection refused :8123` | Container not running | `docker compose up -d` |105| `READONLY` | User lacks write perms | Set `CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1` |106| `Too many parts` | Tiny frequent inserts | Batch inserts or increase `parts_to_throw_insert` |107| `Memory limit exceeded` | Large query on small container | Add `--memory 4g` to Docker |108109## Examples110111Bring the stack up, seed it, and confirm the rows landed:112113```bash114docker compose up -d115curl http://localhost:8123/ping # → "Ok.\n"116npm run db:seed # seeds 1000 events117curl 'http://localhost:8123/?query=SELECT+count()+FROM+app.events' # → 1000118```119120Open an interactive SQL shell:121122```bash123docker exec -it <container> clickhouse-client --password dev_password124```125126See [more examples](references/examples.md) — server-state inspection, HTTP127queries, environment reset, and a passing integration-test run.128129## Resources130131- [Full implementation walkthrough](references/implementation.md) — all seven132 build steps with complete file contents.133- [Examples](references/examples.md) — cold-start, shell, HTTP query, reset, and134 test-run recipes.135- [ClickHouse Docker Image](https://hub.docker.com/r/clickhouse/clickhouse-server)136- [clickhouse-client CLI](https://clickhouse.com/docs/interfaces/cli)137- [Vitest Documentation](https://vitest.dev/)138139## Next Steps140141Once the local loop is green, see the `clickhouse-sdk-patterns` skill for142production-ready client patterns (connection pooling, retries, typed query143helpers, and async inserts) that build on the `getClient()` singleton above.144145---146147**Source:** [`jeremylongshore/claude-code-plugins-plus-skills`](https://github.com/jeremylongshore/claude-code-plugins-plus-skills) → `plugins/saas-packs/clickhouse-pack/skills/clickhouse-local-dev-loop/SKILL.md`