Atlas is a terminal-native AI coding agent you use to write and refactor SQL, from schema migrations to complex queries. In 2026 you run atlas in a repo with your migrations or .sql files, let Atlas read your schema, migration history, and query files, then have Atlas optimize a query or write a migration, reviewing the diff before applying.
Why SQL developers use Atlas
SQL developers use Atlas in 2026 because a query is only correct relative to a schema. Atlas reads your schema, migration history, and query files, so a rewrite targets the columns and indexes you have rather than the ones a model assumed you would have.
Most bad AI-written SQL is not bad syntax. It is a join against a column that never existed, a filter that assumes an index dropped three migrations ago, or a GROUP BY that quietly changes what one row means. Migration history is the piece most tools skip, and it is the piece that says what the schema is today rather than what the original schema file claimed years ago. A table renamed, a column made nullable, an index traded for a different one: none of that is visible in a single snapshot, and all of it decides whether a query plan is fast or catastrophic.
Starting Atlas in a repo with migrations or .sql files
Setup is a single command in 2026: run atlas in a repo with your migrations or .sql files. Atlas is terminal-native, so it runs in the same terminal where you already apply migrations, and it needs no database client of its own to be useful.
Atlas starts in the repository holding the schema, reads your schema, migration history, and query files, and indexes them before you ask for a change. A schema often reveals more about a business than the data does, which is why Atlas can build its code index with local Ollama embeddings, keeping code off third-party servers. The index makes questions like where a reporting table gets populated answerable, returning the statement that writes it rather than every .sql file that happens to name it.
Optimizing queries and writing migrations
The everyday SQL loop in 2026 is concrete: have Atlas optimize a query or write a migration, then review the diff before applying. Optimizing a slow query means holding the query, the schema, and the indexes in view at once, then rewriting without changing the result set.
A correlated subquery becomes a join. A function wrapped around an indexed column is unwrapped so the index can actually be used, since a predicate that is not sargable will scan no matter how good the index is. A SELECT star is narrowed to the columns the caller reads. Every one of those rewrites is safe only if the result set is provably identical, which is why the reading matters more than the writing. Writing a migration is the opposite discipline: a small amount of SQL whose blast radius is the entire application, where knowing the current schema is essentially the whole job.
Reviewing SQL before applying anything
Atlas computes a unified diff for every file edit and surfaces it for approval before writing, and in SQL the rule is stricter: review the diff before applying. In 2026 nothing Atlas writes reaches a database until you have read the migration and approved it.
A migration is the least reversible change in most systems. Every Atlas tool call is permission-gated against allow, ask, and deny rules, which is how a team denies any command capable of applying a migration while still letting Atlas read and write .sql files freely. That separation is the entire safety model for SQL work, because authoring is cheap and reversible while applying is neither. Atlas snapshots file changes as git patches, so a query rewrite that turned out to change results is restored in one step, though a rewrite that already ran against production is a lesson rather than a rollback.
Giving Atlas a live view of the database
Atlas connects to Model Context Protocol servers and exposes their tools to the agent, which is how SQL teams in 2026 let Atlas judge an optimization against reality. A repository of .sql files describes a database but is not the database.
Query plans depend on statistics, cardinality, and data distribution, and none of that lives in your repository. A rewrite that looks faster and is slower is entirely ordinary, especially when the optimizer had a better idea than you did. By exposing tools through a Model Context Protocol server, a team can let Atlas consult an explain plan or a catalog query, so an optimization is measured rather than argued about. Atlas is also extensible through plugins that hook into agent lifecycle events, which is where a team enforces a rule such as requiring every migration it writes to be reversible.
Getting started
- 01Run atlas in a repo with your migrations or .sql files.
- 02Let Atlas read your schema, migration history, and query files.
- 03Have Atlas optimize a query or write a migration, then review the diff before applying.
- 04Write permission rules first, denying any command that could apply a migration without approval.
- 05Ask Atlas whether a rewritten predicate is still sargable against your existing index.
- 06Let Atlas stage the commit once the reviewed migration is ready.
Frequently asked questions
- can an AI agent optimize SQL queries against my real schema
- Atlas can. Atlas reads your schema, migration history, and query files, then you have Atlas optimize a query or write a migration and review the diff before applying.
- can Atlas write database migrations
- Yes. Run atlas in a repo with your migrations or .sql files. Atlas surfaces the migration as a diff you approve before writing, so it is reviewed before it is ever applied.
- how do I stop an AI agent from running a migration against production
- Every Atlas tool call is permission-gated against allow, ask, and deny rules, so any command that could apply a migration can be denied while file edits stay allowed.
- why does AI-generated SQL reference columns that do not exist
- Because it never read the schema. Atlas reads your schema, migration history, and query files, so it works from the columns and indexes that exist today rather than an outdated snapshot.
- can Atlas check a query plan against a live database
- Atlas connects to Model Context Protocol servers and exposes their tools to the agent, so a team can expose an explain plan or catalog query as a tool Atlas may call.
- how do I undo an AI query rewrite that changed results
- Atlas snapshots file changes as git patches, so the .sql file is restored in one step.
- can Atlas index a database schema without sending it to a vendor
- Yes. Atlas can build its code index with local Ollama embeddings, keeping code off third-party servers, which matters because a schema often reveals more than the data.
Try Atlas in your terminal
The terminal-native AI coding agent. Free core, single binary.
Install AtlasRelated guides
Diagnose a Hanging or Long-Running SQL Command with Atlas in 2026
In 2026, use Atlas to quickly diagnose if your SQL scripts, `Flyway migrations`, or `pgTAP` tests are genuinely slow or silently blocked on input, getting you unstuck fast.
Automate GitHub Issue and Pull Request Triage in SQL with Atlas in 2026
Streamline GitHub issue and pull request triage for your SQL projects using Atlas. Automate responses, refactor queries, and manage Flyway migrations safely with a terminal-native AI agent.
Migrate a Deprecated API Across Every Callsite in SQL with Atlas in 2026
In 2026, Atlas helps SQL developers migrate deprecated functions or modules across an entire codebase, ensuring no callsite is missed and changes are validated with pgTAP and Flyway migrations.
Document a SQL Module with a README using Atlas in 2026
In 2026, Atlas helps SQL developers generate accurate READMEs for modules by analyzing live code, not outdated specs. It leverages pgTAP, Flyway migrations, and sqlfluff format to ensure documentation reflects the
Run the pgTAP Test Suite and Triage SQL Failures with Atlas in 2026
SQL developers in 2026 use Atlas to run pgTAP test suites, triage failures with grep, and track fixes with todowrite, turning red output into prioritized tasks.
Debug a single failing test in SQL with Atlas in 2026
Debug a single failing SQL test with Atlas in 2026. Use Atlas to pinpoint issues in pgTAP tests, navigate your SQL codebase, and fix production code efficiently. Get precise diffs and approvals.
Locate Where a Behavior is Implemented in SQL with Atlas in 2026
In 2026, Atlas helps SQL developers quickly locate the exact file and symbol responsible for a behavior across Flyway migrations and .sql files, using semantic search and LSP.
Run Atlas Headless in CI for SQL in 2026
Automate SQL development workflows in CI with Atlas. Learn how to run Atlas headless, integrate with pgTAP and Flyway migrations, and get machine-readable output for your SQL pipelines.