Quick Start
What's Emigrate? Learn more about Emigrate and what it can do for you.
Install the Emigrate CLI
npm install @emigrate/clipnpm add @emigrate/cliyarn add @emigrate/clibun add @emigrate/cli{ "scripts": { "emigrate": "emigrate" }, "dependencies": { "@emigrate/cli": "*" }}Pick a storage plugin
Emigrate uses a storage plugin to store the migration history.
Install the plugin you want to use, for example the PostgreSQL Storage:
npm install @emigrate/postgrespnpm add @emigrate/postgresyarn add @emigrate/postgresbun add @emigrate/postgres{ "dependencies": { "@emigrate/cli": "*", "@emigrate/postgres": "*" }}Create your first migration
Baseline your database Learn how to create a baseline of your existing database.
Create a new migration file in your project using:
npx emigrate new --plugin postgres create users tablepnpm emigrate new --plugin postgres create users tableyarn emigrate new --plugin postgres create users tablebunx --bun emigrate new --plugin postgres create users table{ "scripts": { "emigrate": "emigrate" }}deno task emigrate new --plugin postgres create users tableEmigrate new v0.10.0 /your/project/path
✔ migrations/20231215125421364_create_users_table.sql (done) 3ms
1 createdFill the migration file
Open the migration file in your editor and fill it with your SQL query:
-- Migration: create users tableCREATE TABLE users ( id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL);Show migration status
To show both pending and already applied migrations (or previously failed), use the list command:
npx emigrate list --storage postgrespnpm emigrate list --storage postgresyarn emigrate list --storage postgresbunx --bun emigrate list --storage postgres{ "scripts": { "emigrate": "emigrate" }}deno task emigrate list --storage postgresEmigrate list v0.10.0 /your/project/path
✔ migrations/20231211090830577_another_table.sql (done) › migrations/20231215125421364_create_users_table.sql (pending)
1 done | 1 pending (2 total)Running the migrations
A good way to test your configuration is to run the migrations in dry mode:
npx emigrate up --storage postgres --plugin postgres --drypnpm emigrate up --storage postgres --plugin postgres --dryyarn emigrate up --storage postgres --plugin postgres --drybunx --bun emigrate up --storage postgres --plugin postgres --dry{ "scripts": { "emigrate": "emigrate" }}deno task emigrate up --storage postgres --plugin postgres --dry