Atlas CLI
$ atlas 官方出品 中风险Ariga 开发的 Atlas CLI 支持用 HCL 或 SQL 声明式管理 PostgreSQL、MySQL、SQLite 等数据库结构。提供 atlas schema inspect、atlas migrate diff 与 atlas migrate apply --dry-run,让 Agent 能在落库前安全生成并预览 DDL 变更。
brew install ariga/tap/atlas atlas 原生即可完成确定性 SQL 差异计算、JSON 结构导出与 --dry-run 迁移预览,无需借助 MCP。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
支持 --format '{{ json . }}' 模板输出、--dry-run 预演、非交互参数及声明式 atlas.hcl 配置。
- Supports
--format '{{ json . }}'andmigrate apply --dry-run
migrate apply 与 schema apply 均支持 --dry-run,且可通过 --dev-url 沙箱隔离计算差异。
- Explicit
--dry-runplanning and isolated--dev-urldiff calculation
单文件静态 Go 二进制,支持 Homebrew、npm 封装、Docker 与直接下载,覆盖全平台。
- Static Go binary distributed via
ariga/tap/atlasand@ariga/atlas
用自动化声明式 Schema 规划替代易错的手写迁移脚本。
- Declarative schema inspection, diffing, and migration execution
由 Ariga(ariga/atlas)积极维护,但标准发行版包含专有 Pro 扩展。
- Official
ariga/atlasrepo; split Community vs Pro licensing
atlasgo.io 提供详尽的 CLI 参考与多数据库实战指南。
- Official CLI reference at atlasgo.io/cli-reference
安全边界、鉴权与放权指南
数据库连接串通过 --url 或 atlas.hcl 配置;可选的 Atlas Cloud 令牌通过 atlas login 或 ATLAS_TOKEN 传入。
基础核心功能以 Apache-2.0 开源免费;高级 Pro 驱动、策略检查(migrate lint)与企业能力需付费订阅 Atlas Pro。
# Atlas CLI Agent Rules - Always run `atlas migrate apply --dry-run` before applying migrations. - Use `atlas schema inspect` first to capture current schema state cleanly. - NEVER run `atlas schema clean` or apply destructive `DROP` migrations without human review.
Agent 高频安全命令配方
只读查询(安全推荐)
atlas schema inspect --url "$DB_URL" --format '{{ json . }}' 只读读取表结构、索引和外键并输出标准 JSON。
--dry-run 预览待执行迁移 atlas migrate apply --dir file://migrations --url "$DB_URL" --dry-run
打印将要执行的精确 SQL 语句,但不对数据库做任何修改。
受控写入与预演
atlas migrate diff add_orders --dir file://migrations --to file://schema.hcl --dev-url "docker://postgres/16/dev"
对比目标 Schema 计算迁移脚本并写入本地目录供审阅。
核心优势
- +
migrate apply --dry-run与schema apply --dry-run让 DDL 变更过程对 Agent 完全透明。 - +
schema inspect --format '{{ json . }}'可直接输出标准化 JSON 结构树。 - + 统一支持 PostgreSQL、MySQL、MariaDB 与 SQLite。
注意事项与踩坑点
- !
migrate lint及部分企业数据库驱动需要atlas login/ Pro 商业授权。 - !
atlas migrate diff通常依赖临时--dev-url(如 Docker 容器)以保证 SQL 归一化准确。