Dbmate is a standalone, framework-agnostic command-line tool designed for managing database schema migrations. It supports a variety of databases including MySQL, PostgreSQL, SQLite, ClickHouse, BigQuery, and Spanner. The tool uses plain SQL for writing migrations, employs timestamp-versioning to prevent conflicts in collaborative environments, and runs migrations atomically within transactions. Beyond basic migration, it can also create and drop databases (useful for development/testing workflows) and export a `schema.sql` file to easily track schema changes in version control. Currently at version 2.32.0, Dbmate maintains an active and consistent release cadence, frequently releasing patch updates for bug fixes and dependency bumps, with minor versions arriving every few weeks to months. Its primary differentiator is its independence from any specific programming language or framework, making it an ideal choice for polyglot microservice architectures where a consistent database migration strategy across different technology stacks is desired.
npm install dbmateVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the core workflow of Dbmate, including installation as a development dependency, initializing the migration setup, creating new SQL migration files, applying pending migrations, rolling back the last migration, and dumping the schema. It highlights the crucial role of the `DATABASE_URL` environment variable.
Use `docker run --rm -it --network=host ghcr.io/amacneil/dbmate [command]` or configure explicit Docker networking and ensure the database host is reachable from within the container.
Migrate your import statements from CommonJS `const { Dbmate } = require('dbmate')` to ESM `import { Dbmate } from 'dbmate'`. Ensure your Node.js project is configured to run as an ESM module (e.g., via `"type": "module"` in `package.json`).Before running any Dbmate command, ensure `DATABASE_URL` is correctly set in your shell environment (e.g., `export DATABASE_URL="your_db_connection_string"`) or explicitly pass it with `npx dbmate --url "your_db_connection_string" [command]`.
Upgrade Dbmate to version 2.30.0 or higher, which includes a fix addressing the compatibility issues with `lib/pq` and Supavisor.
Upgrade to Dbmate v2.29.0 or later, which includes specific handling for these new PostgreSQL `pg_dump` commands to ensure correct schema dumping.
Carefully review the complete error message that follows. Common culprits include incorrect `DATABASE_URL`, a non-existent database (run `npx dbmate create`), or syntax errors within your SQL migration files.
Set the `DATABASE_URL` environment variable in your shell (e.g., `export DATABASE_URL="postgres://user:pass@host:port/db"`) or provide it directly to the command: `npx dbmate --url "your_connection_string" up`.
First, execute `npx dbmate create` (ensure `DATABASE_URL` points to the correct server) to create the database, then proceed with applying migrations using `npx dbmate up`.
Inspect the migration file indicated in the error message for any SQL syntax mistakes. Pay close attention to the specific SQL dialect of your target database (e.g., MySQL, PostgreSQL, SQLite).
No dependency data recorded yet.