| name | atlas-full |
| description | Comprehensive Atlas database schema management. Use when working with Atlas migrations, schema inspection, diffing, linting, or applying database changes. |
Atlas Database Schema Management
Atlas is a language-independent tool for managing and migrating database schemas using modern DevOps principles.
Quick Reference
atlas schema inspect --env <name> --url file://migrations
atlas migrate status --env <name>
atlas migrate diff --env <name>
atlas migrate lint --env <name> --latest 1
atlas migrate apply --env <name>
atlas whoami
Core Concepts and Configurations
Configuration File Structure
Atlas uses atlas.hcl configuration files with the following structure:
// Basic environment configuration
env "<name>" {
url = getenv("DATABASE_URL")
dev = "docker://postgres/15/dev?search_path=public"
migration {
dir = "file://migrations"
}
schema {
src = "file://schema.hcl"
}
}
Dev database
Atlas utilizes a "dev-database", which is a temporary and locally running database, usually bootstrapped by Atlas. Atlas will use the dev database to process and validate users' schemas, migrations, and more.
Examples of dev-database configurations:
# When working on a single database schema
--dev-url "docker://mysql/8/dev"
--dev-url "docker://postgres/15/db_name?search_path=public"
--dev-url "sqlite://dev?mode=memory"
# When working on multiple database schemas.
--dev-url "docker://mysql/8"
--dev-url "docker://postgres/15/dev"
Configure the dev database using HCL:
env "<name>" {
dev = "docker://mysql/8"
}
Environment Variables and Security
โ
DO: Use secure configuration patterns
// Using environment variables (recommended)
env "<name>" {
url = getenv("DATABASE_URL")
}
โ DON'T: Hardcode sensitive values
// Never do this
env "prod" {
url = "postgres://user:password123@prod-host:5432/database"
}
Schema Sources
External Schema (ORM Integration)
The external_schema data source enables the import of an SQL schema from an external program into Atlas' desired state.
data "external_schema" "gorm" {
program = [
"go", "run", "-mod=mod",
"ariga.io/atlas-provider-gorm",
"load", "--path", "./models", "--dialect", "sqlite"
]
}
env "gorm" {
src = data.external_schema.gorm.url
dev = "sqlite://dev?mode=memory"
migration {
dir = "file://migrations"
}
}
Common Workflows
1. Schema Inspection / Visualization
- Always start by listing tables, don't immediately try to inspect the entire schema.
- If you see there are many tables, don't inspect the entire schema at once.
atlas schema inspect --env <name> --url file://migrations --format "{{ json . }}" | jq ".schemas[].tables[].name"
atlas schema inspect --env <name> --url file://migrations --format "{{ sql . }}"
2. Migration Status
atlas migrate status --env <name>
3. Migration Generation / Diffing
atlas migrate diff --env <name> "add_user_table"
4. Migration Linting
atlas migrate lint --env <name> --latest 1
5. Applying Migration
atlas migrate apply --env <name> --dry-run
atlas migrate apply --env <name>
6. Making Changes to the Schema
โ ๏ธ CRITICAL: ALL schema changes MUST follow this exact workflow. NO EXCEPTIONS.
- Start by inspecting the schema, understand the current state
- After making changes to the schema/models, run
atlas migrate diff --env <name> <migration_name> to generate a migration file
- Run
atlas migrate lint --env <name> --latest 1 to validate the migration file
- If there are issues, fix them and run
atlas migrate hash --env <name> to recalculate the hash
- Run
atlas migrate validate --env <name> to ensure migrations are valid
Important for applied migrations: Never edit directly. Create a new corrective migration instead.
Troubleshooting Commands
atlas version
atlas migrate hash --env <name>
atlas migrate validate --env <name>
Key Reminders
- Always read
atlas.hcl first before running any Atlas commands
- Use environment names from the config file
- Never hardcode database URLs
- Run
atlas migrate hash after manually editing migration files
- Use
atlas migrate lint to validate migrations before applying
- Never modify applied migrations - create new ones instead
- Always use
--dry-run before applying migrations
- Prefer
atlas schema inspect over reading migration files directly