Skip to content

Quick Start

What's Emigrate? Learn more about Emigrate and what it can do for you.

Install the Emigrate CLI

Terminal window
npm install @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:

Terminal window
npm install @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:

Create a new migration file
npx emigrate new --plugin postgres create users table
emigrate new
Emigrate new v0.10.0 /your/project/path
✔ migrations/20231215125421364_create_users_table.sql (done) 3ms
1 created

Fill the migration file

Open the migration file in your editor and fill it with your SQL query:

migrations/20231215125421364_create_users_table.sql
-- Migration: create users table
CREATE 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:

Show all migrations
npx emigrate list --storage postgres
emigrate list
Emigrate 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:

Show pending migrations
npx emigrate up --storage postgres --plugin postgres --dry