Skip to main content

Schema Change Workflow

With your project set up, let's walk through the workflow you'll use day-to-day.

Step 1: Make a Schema Change

Edit your schema files to make a change. For example, add a phone column to the users table:

schema/users.hcl
table "users" {
schema = schema.public
column "id" {
type = serial
}
column "name" {
type = varchar(100)
}
column "phone" {
type = varchar(20)
null = true
}
primary_key {
columns = [column.id]
}
}
Using AI agents?

AI coding tools like Claude Code, GitHub Copilot, and Cursor can edit your schema files directly. Atlas provides Agent Skills so agents can also generate migrations, run linting, and apply changes. The agent edits code, Atlas plans and validates deterministically. See the AI Tools page for setup instructions.

Step 2: Generate a Migration

Run atlas migrate diff to generate a migration file that reflects your change:

atlas migrate diff add_phone --env local

Atlas compares your schema files against the current migration directory, calculates the diff, and writes a new migration file:

migrations/
├── 20240604131146_baseline.sql
├── 20260410120000_add_phone.sql ← new
└── atlas.sum

Review the generated SQL:

migrations/20260410120000_add_phone.sql
-- Add column "phone" to table: "users"
ALTER TABLE "public"."users" ADD COLUMN "phone" character varying(20) NULL;

Step 3: Apply

Apply the migration to your local database:

atlas migrate apply --env local

Atlas reports which migrations were applied:

Migrating to version 20260410120000 (1 migration in total):

-- migrating version 20260410120000
-> ALTER TABLE "public"."users" ADD COLUMN "phone" character varying(20) NULL;
-- ok (1.234ms)

-------------------------
-- 1 migration
-- 1 sql statement

Step 4: Verify

Check the migration status of your database:

atlas migrate status --env local
Migration Status: OK
-- Current Version: 20260410120000
-- Next Version: Already at latest version
-- Executed Files: 2
-- Pending Files: 0

This is the core loop: edit schema, migrate diff, review, apply. Each change produces a new migration file that can be reviewed in a pull request.