Knex.js CLI
$ knex Official Med RiskKnex.js CLI (knex) manages JavaScript/TypeScript schema migrations and database seed scripts via knexfile.js or knexfile.ts. Provides straightforward migrate:status, migrate:list, migrate:latest, migrate:rollback, and seed:run commands for Node.js services.
npm install -D knex knex executes project-local knexfile migrations and TypeScript/JS seed modules directly inside the repository.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Runs headlessly without TTY prompts via npx knex, though it lacks --json output and --dry-run flags.
- Non-interactive
migrate:statusandmigrate:latest - No
--jsonor--dry-runflag
--env scopes target databases and migrate:rollback steps back one batch by default, but lacks dry-run SQL preview.
- Batch-scoped rollback by default;
--allis destructive
Standard npm package (npx knex), but requires Node.js plus the project's database driver (pg, mysql2, sqlite3) installed in node_modules.
- Requires Node.js and project-local DB driver packages
Simple imperative migration and seed runner for Node.js codebases without heavyweight ORM schemas.
- Covers migration scaffolding, execution, rollback, and seeds
Long-standing knex/knex official repository under MIT license.
- Official
knex/knexGitHub repository
Clear migrations CLI guide on knexjs.org, though TypeScript knexfile.ts flags and ESM nuances can require extra setup.
- Migration CLI documentation at knexjs.org
Security, Auth & Guardrails
Reads connection objects and env vars (such as DATABASE_URL) from knexfile.js / knexfile.ts keyed by --env.
MIT open-source npm package; free to use.
# Knex.js CLI Agent Rules - Always pass `--env <target>` explicitly and run `npx knex migrate:status` first. - Never run `npx knex migrate:rollback --all` on shared or production environments without explicit confirmation.
Agent-Ready Command Recipes
Safe Read-Only Queries
npx knex migrate:status
Prints a list of completed and pending migration files against the configured database.
npx knex migrate:list
Displays completed and pending migrations from the knex_migrations tracking table.
Controlled Writes & Previews
npx knex migrate:latest --env development
Applies all pending migrations against the explicitly scoped --env target.
Strengths for Agents
- + Zero-prompt CLI commands (
migrate:status,migrate:latest,seed:run) work reliably in CI. - + Explicit
--envflag separates local, test, and productionknexfileconfigs. - + Supports both JavaScript and TypeScript migration files.
Caveats & Pitfalls
- ! No
--jsonoutput or built-in--dry-runSQL preview mode. - ! Requires project
node_modulesand matching DB driver packages (pg,mysql2, etc.) to run.