OneTable CLI
raw JSON →The OneTable CLI is a command-line interface tool designed to orchestrate DynamoDB migrations specifically for applications utilizing `dynamodb-onetable` and `onetable-migrate`. Currently at version 1.3.5, it receives frequent minor patch releases for bug fixes and dependency updates, with major feature releases occurring less often to introduce new capabilities like named migrations (v1.3.0). It serves as a crucial utility for development teams to initialize, reset, and evolve DynamoDB schema and data, and for production environments to manage step-wise database upgrades, downgrades, and maintenance tasks. Its key differentiators include supporting reversible, versioned, and named migrations, operating on both local and remote DynamoDB instances, and facilitating the successful evolution of single-table DynamoDB patterns by allowing automated and ordered sequencing of schema changes and data seeding.
Common errors
error Error: Table not found: your-dynamo-table ↓
name property in migrate.json5 matches an existing DynamoDB table. Ensure your AWS credentials (via AWS_PROFILE or environment variables) have the necessary permissions to dynamodb:DescribeTable and other relevant actions. error Error: OneTable configuration missing or invalid in migrate.json5 ↓
migrate.json5 file. Ensure it's valid JSON5 and contains a top-level onetable object with at least a name property for your DynamoDB table. error Error: Migration failed: An outstanding migration must be run first. ↓
onetable status to inspect the migration state. Use onetable up to apply any outstanding migrations sequentially before attempting specific 'down' or 'goto' commands. If the history is corrupted, you might need to manually inspect or reset it (with caution). Warnings
breaking The `onetable-migrate` library (used internally by the CLI) now persists migrations to the DynamoDB table and requires each migration to specify its schema. The `--schema` option and `migrate.json` schema property have been removed as the CLI can now read the schema directly from the table. ↓
gotcha Using `--dir` to specify migration file locations is now the preferred method, as it allows for automatic indexing of both versioned and named migrations, even for AWS-hosted migrations. ↓
gotcha For optimal performance, especially with large migrations, it is recommended to host your migrations (via `onetable-controller`) in the same AWS region and availability zone as your DynamoDB table. Executing locally can incur significant I/O transfer time. ↓
Install
npm install onetable-cli yarn add onetable-cli pnpm add onetable-cli Imports
- loadModel
import { loadModel } from 'onetable-cli/util/model'; - loadSchema
import { loadSchema } from 'onetable-cli/util/schema'; - upgradeSchema
import { upgradeSchema } from 'onetable-cli/util/upgrade';
Quickstart
npm i onetable-cli -g
mkdir ./migrations
echo "{\n onetable: {\n name: 'your-dynamo-table',\n partial: true\n },\n dir: './migrations'\n}" > migrate.json5
onetable init
onetable create my-first-migration
onetable up --dry-run
onetable up