Operations and CLI
Apply reviewed collection, index, search, and Eventing plans from the CLI.
The couchset CLI is an explicit admin surface: plan and apply against a trusted config that exports your client. It never discovers projects, never provisions on import, and never silently drops indexes or Eventing functions.
Install and help
npx couchset --help
# or, after npm install -g / local bin:
couchset --helpcouchset model User only prints a starter defineModel snippet — it does not write files.
Config
Admin commands require --config ./couchset.config.cjs. The file is trusted application code. It must export db as a CouchsetClient with models registered. Export eventing for eventing plan.
// couchset.config.cjs — illustrative; keep free of provisioning side effects
const { createCouchsetClient, defineModel } = require('couchset/next');
const users = defineModel({
name: 'User',
scope: 'app',
collection: 'users',
indexes: [{ name: 'idx_user_email', fields: ['email'] }],
});
const db = createCouchsetClient({
connectionString: process.env.COUCHBASE_URL,
username: process.env.COUCHBASE_USERNAME,
password: process.env.COUCHBASE_PASSWORD,
bucketName: process.env.COUCHBASE_BUCKET || 'app',
models: [users],
});
module.exports = { db };
// module.exports = { db, eventing }; // when using Eventing planLoading the config can run your application code. Keep it free of ensure* / apply* at import time. The CLI always shutdown()s the client when finished.
Commands
npx couchset inspect --config ./couchset.config.cjs
npx couchset collections plan --config ./couchset.config.cjs
npx couchset collections apply --config ./couchset.config.cjs
npx couchset indexes plan --config ./couchset.config.cjs
npx couchset indexes apply --config ./couchset.config.cjs --plan ./plan.json
npx couchset search-indexes plan --config ./couchset.config.cjs
npx couchset search-indexes apply --config ./couchset.config.cjs --plan ./search-plan.json --allow-replace
npx couchset eventing plan --config ./couchset.config.cjs| Command | Behavior |
|---|---|
inspect | Model names, scopes, collections, index / Search index names — no secrets |
collections plan | Read-only { scope, collection, status: 'create' | 'matching' }[] |
collections apply | Create-only ensure; no --plan file |
indexes plan | JSON GSI plan (create / matching / replace, physical createAs, optional replaces) |
indexes apply --plan | Apply exactly the reviewed JSON; CLI does not expose GSI old-index drop |
search-indexes plan | Search create/match/replace with catalog identity (stale plans fail) |
search-indexes apply --plan | Apply reviewed Search plan; replacement also needs --allow-replace |
eventing plan | Definition drift / stale owned names only — not deploy/lifecycle readiness |
Plan/apply commands print JSON. Index/Search apply requires --plan ./plan.json (reviewed file). There is no CLI Eventing apply / prune — deploy through the Eventing application API after review.
Recommended workflow
inspect— confirm the config sees the models you expect.collections planthencollections applyif anything iscreate.indexes plan→ save JSON → review →indexes apply --plan ….- Same for Search when you use Search indexes.
eventing planfor definition drift; deploy witheventing.apply()in app code.
Programmatic equivalents live under Provisioning and transactions and Search, vector, and geospatial.
Pitfalls
- Pointing
--configat code that provisions on load. - Applying an unreviewed or stale Search plan (catalog UUID mismatch).
- Expecting Search replace without
--allow-replace. - Expecting the CLI to drop old GSI indexes or deploy Eventing.
See also
- Provisioning and transactions — ensure/plan/apply in code
- Search, vector, and geospatial — Search plans
- Eventing —
plan/apply/ pause / remove - API reference — client helpers the CLI wraps