MCPcopy Index your code
hub / github.com/ariga/atlas

github.com/ariga/atlas @v1.2.0 sqlite

repository ↗ · DeepWiki ↗ · release v1.2.0 ↗
8,789 symbols 22,398 edges 196 files 3,732 documented · 42%
README

Atlas - Manage Your Database Schema as Code

Twitter Discord

Atlas banner

Atlas is a language-agnostic tool for managing and migrating database schemas using modern DevOps principles. It offers two workflows:

  • Declarative: Similar to Terraform, Atlas compares the current state of the database to the desired state, as defined in an [HCL], [SQL], or [ORM] schema. Based on this comparison, it generates and executes a migration plan to transition the database to its desired state.

  • Versioned: Unlike other tools, Atlas automatically plans schema migrations for you. Users can describe their desired database schema in [HCL], [SQL], or their chosen [ORM], and by utilizing Atlas, they can plan, lint, and apply the necessary migrations to the database.

Supported Databases

PostgreSQL · MySQL · MariaDB · SQL Server · SQLite · ClickHouse · Redshift · Oracle · Snowflake · CockroachDB · TiDB · Databricks · Spanner · Aurora DSQL · Azure Fabric

Installation

macOS + Linux:

curl -sSf https://atlasgo.sh | sh

Homebrew:

brew install ariga/tap/atlas

Docker:

docker pull arigaio/atlas

NPM:

npx @ariga/atlas

See installation docs for all platforms.

Key Features

Getting Started

Get started with Atlas by following the Getting Started docs.

Inspect an existing database schema:

atlas schema inspect -u "postgres://localhost:5432/mydb"

Apply your desired schema to the database:

atlas schema apply \
  --url "postgres://localhost:5432/mydb" \
  --to file://schema.hcl \
  --dev-url "docker://postgres/16/dev"

📖 Getting Started docs

Migration Linting

Atlas ships with 50+ built-in analyzers that review your migration files and catch issues before they reach production. Analyzers detect destructive changes like dropped tables or columns, data-dependent modifications such as adding non-nullable columns without defaults, and database-specific risks like table locks and table rewrites that can cause downtime on busy tables. You can also define your own custom policy rules.

atlas migrate lint --dev-url "docker://postgres/16/dev"

Schema Testing

Test database logic (functions, views, triggers, procedures) and data migrations with .test.hcl files:

test "schema" "postal" {
  # Valid postal codes pass
  exec {
    sql = "SELECT '12345'::us_postal_code"
  }
  # Invalid postal codes fail
  catch {
    sql = "SELECT 'hello'::us_postal_code"
  }
}

test "schema" "seed" {
  for_each = [
    {input: "hello", expected: "HELLO"},
    {input: "world", expected: "WORLD"},
  ]
  exec {
    sql    = "SELECT upper('${each.value.input}')"
    output = each.value.expected
  }
}
atlas schema test --dev-url "docker://postgres/16/dev"

📖 Testing docs

Security-as-Code

Manage database roles, permissions, and row-level security as version-controlled code:

role "app_readonly" {
  comment = "Read-only access for reporting"
}

role "app_writer" {
  comment   = "Read-write access for the application"
  member_of = [role.app_readonly]
}

user "api_user" {
  password   = var.api_password
  conn_limit = 20
  comment    = "Application API service account"
  member_of  = [role.app_writer]
}

permission {
  for_each   = [table.orders, table.products, table.users]
  for        = each.value
  to         = role.app_readonly
  privileges = [SELECT]
}

policy "tenant_isolation" {
  on    = table.orders
  for   = ALL
  to    = ["app_writer"]
  using = "(tenant_id = current_setting('app.current_tenant')::integer)"
  check = "(tenant_id = current_setting('app.current_tenant')::integer)"
}

📖 Security-as-Code docs

Data Management

Manage seed and lookup data declaratively alongside your schema:

CREATE TABLE countries (
  id INT PRIMARY KEY,
  code VARCHAR(2) NOT NULL,
  name VARCHAR(100) NOT NULL
);

INSERT INTO countries (id, code, name) VALUES
  (1, 'US', 'United States'),
  (2, 'IL', 'Israel'),
  (3, 'DE', 'Germany');

📖 Data management docs

ORM Support

Define your schema in any of the 16 supported ORMs. Atlas reads your models and generates migrations:

Language ORMs
Go GORM, Ent, Bun, Beego, sqlc
TypeScript Prisma, Drizzle, TypeORM, Sequelize
Python Django, SQLAlchemy
Java Hibernate
.NET EF Core
PHP Doctrine

📖 ORM integration docs

Integrations

Lint, test, and apply migrations automatically in your CI/CD pipeline or infrastructure-as-code workflow:

Integration Docs
GitHub Actions Versioned guide · Declarative guide
GitLab CI Versioned guide · Declarative guide
CircleCI Versioned guide · Declarative guide
Bitbucket Pipes Versioned guide · Declarative guide
Azure DevOps GitHub repos · Azure repos
Terraform Provider atlasgo.io/integrations/terraform-provider
Kubernetes Operator atlasgo.io/integrations/kubernetes
ArgoCD atlasgo.io/guides/deploying/k8s-argo
Flux atlasgo.io/guides/deploying/k8s-flux
Crossplane atlasgo.io/guides/deploying/crossplane
Go SDK pkg.go.dev/ariga.io/atlas-go-sdk/atlasexec

AI Agent Integration

Atlas provides Agent Skills, an open standard for packaging migration expertise for AI coding assistants: Claude Code, GitHub Copilot, Cursor, OpenAI Codex. Learn more at AI tools docs.

CLI Usage

schema inspect

Easily inspect your database schema by providing a database URL and convert it to HCL, JSON, SQL, ERD, or other formats.

Inspect a specific MySQL schema and get its representation in Atlas DDL syntax:

atlas schema inspect -u "mysql://root:pass@localhost:3306/example" > schema.hcl

Result

table "users" {
  schema = schema.example
  column "id" {
    null = false
    type = int
  }
  ...
}

Inspect the entire MySQL database and get its JSON representation:

atlas schema inspect \
  --url "mysql://root:pass@localhost:3306/" \
  --format '{{ json . }}' | jq

Result

{
  "schemas": [
    {
      "name": "example",
      "tables": [
        {
          "name": "users",
          "columns": [
            ...
          ]
        }
      ]
    }
  ]
}

Inspect a specific PostgreSQL schema and get its ERD representation in Mermaid syntax:

atlas schema inspect \
  --url "postgres://root:pass@:5432/test?search_path=public&sslmode=disable" \
  --format '{{ mermaid . }}'
erDiagram
    users {
      int id PK
      varchar name
    }
    blog_posts {
      int id PK
      varchar title
      text body
      int author_id FK
    }
    blog_posts }o--o| users : author_fk

Use the split format for one-file-per-object output:

atlas schema inspect -u '<url>' --format '{{ sql . | split | write }}'
├── schemas
│   └── public
│       ├── public.sql
│       ├── tables
│       │   ├── profiles.sql
│       │   └── users.sql
│       ├── functions
│       └── types
└── main.sql

📖 Schema inspection docs

schema diff

Compare two schema states and get a migration plan to transform one into the other. A state can be specified using a database URL, HCL, SQL, or ORM schema, or a migration directory.

atlas schema diff \
  --from "postgres://postgres:pass@:5432/test?search_path=public&sslmode=disable" \
  --to file://schema.hcl \
  --dev-url "docker://postgres/15/test"

📖 Declarative workflow docs

`schem

Extension points exported contracts — how you extend this code

PlanApplier (Interface)
PlanApplier wraps the methods for planning and applying changes on the database. [6 implementers]
sql/migrate/migrate.go
SchemaObject (Interface)
SchemaObject describes a top-level schema object that might be qualified, e.g. a table or a view. [6 implementers]
sql/internal/specutil/spec.go
Inspector (Interface)
Inspector is the interface implemented by the different database drivers for inspecting schema or databases. [8 implementers]
sql/schema/inspect.go
NamedAnalyzer (Interface)
A NamedAnalyzer describes an Analyzer that has a name. [19 implementers]
sql/sqlcheck/sqlcheck.go
Tx (Interface)
Tx wraps schema.ExecQuerier with the transaction methods. [5 implementers]
sql/sqlite/driver.go
Committer (Interface)
Committer is the interface that wraps the Commit method. [5 implementers]
cmd/atlas/internal/migrate/ent/tx.go
Opener (Interface)
Opener opens a migration driver by the given URL. [4 implementers]
sql/sqlclient/client.go
Evaluator (Interface)
Evaluator is the interface that wraps the Eval function. [4 implementers]
schemahcl/schemahcl.go

Core symbols most depended-on inside this repo

Equal
called by 873
sql/postgres/inspect.go
NewTable
called by 358
sql/schema/dsl.go
New
called by 311
sql/schema/dsl.go
AddColumns
called by 310
sql/schema/dsl.go
NewIntColumn
called by 296
sql/schema/dsl.go
P
called by 246
sql/internal/sqlx/sqlx.go
Run
called by 242
sdk/tmplrun/tmplrun.go
Has
called by 187
sql/internal/sqlx/diff.go

Shape

Method 5,794
Function 1,976
Struct 724
Interface 196
FuncType 63
TypeAlias 36

Languages

Go100%

Modules by API surface

cmd/atlas/internal/sqlparse/sqliteparse/parser.go3,860 symbols
cmd/atlas/internal/sqlparse/sqliteparse/parser_base_listener.go231 symbols
cmd/atlas/internal/sqlparse/sqliteparse/parser_listener.go227 symbols
sql/schema/dsl.go136 symbols
cmd/atlas/internal/migrate/ent/revision/where.go135 symbols
cmd/atlas/internal/migrate/ent/revision_create.go128 symbols
sql/migrate/migrate.go127 symbols
cmd/atlas/internal/sqlparse/sqliteparse/parser_visitor.go114 symbols
cmd/atlas/internal/sqlparse/sqliteparse/parser_base_visitor.go114 symbols
sql/schema/schema.go108 symbols
sql/schema/migrate.go105 symbols
sql/migrate/dir.go102 symbols

Dependencies from manifests, versioned

ariga.io/atlasv0.32.1-0.2025032510 · 1×
ariga.io/atlas/cmd/atlasv0.13.2-0.2023122013 · 1×
cloud.google.com/go/auth/oauth2adaptv0.2.8 · 1×
cloud.google.com/go/compute/metadatav0.9.0 · 1×
cloud.google.com/go/longrunningv0.6.7 · 1×
cloud.google.com/go/secretmanagerv1.15.0 · 1×
entgo.io/entv0.14.5-0.2025052308 · 1×
filippo.io/edwards25519v1.1.1 · 1×
github.com/1lann/promptuiv0.8.1-0.20220708222 · 1×

Datastores touched

(mysql)Database · 1 repos
dbnameDatabase · 1 repos
my_dbDatabase · 1 repos
adminDatabase · 1 repos
atlasDatabase · 1 repos
dbDatabase · 1 repos
db1Database · 1 repos
devDatabase · 1 repos

For agents

$ claude mcp add atlas \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact