@ariga/atlas-provider-typeorm

中文文档
0.3.2发布于 2026/02/10构建来源已验证近 30 天下载 13.8万

Load Typeorm models into an Atlas project.

原始使用文档
文档目录10 节
  1. Use-cases
  2. Installation
  3. Standalone
  4. As a library
  5. Usage
  6. Apply
  7. Diff
  8. Supported Databases
  9. Issues
  10. License

atlas-provider-typeorm

CI

Use Atlas with TypeORM to manage your database schema as code. By connecting your TypeORM models to Atlas, you can define and edit your schema directly in TypeScript or JavaScript. Atlas will then automatically plan and apply database schema migrations for you, eliminating the need to write migrations manually.

Atlas brings automated CI/CD workflows to your database, along with built-in support for testing, linting, schema drift detection, and schema monitoring. It also allows you to extend TypeORM with advanced database objects such as triggers, row-level security, and custom functions that are not supported natively.

Use-cases

  1. Declarative migrations - Use the Terraform-like atlas schema apply --env typeorm command to apply your TypeORM schema to the database.
  2. Automatic migration planning - Use atlas migrate diff --env typeorm to automatically plan database schema changes and generate a migration from the current database version to the desired version defined by your TypeORM schema.

Installation

Install Atlas from macOS or Linux by running:

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

See atlasgo.io for more installation options.

Install the provider by running:

npm i @ariga/atlas-provider-typeorm

Make sure all your Node dependencies are installed by running:

npm i

Standalone

If all of your TypeORM entities exist in a single Node module, you can use the provider directly to load your TypeORM schema into Atlas.

In your project directory, create a new file named atlas.hcl with the following contents:

data "external_schema" "typeorm" {
  program = [
    "npx",
    "@ariga/atlas-provider-typeorm",
    "load",
    "--path", "./path/to/entities",
    "--dialect", "mysql", // mariadb | postgres | sqlite | mssql
  ]
}

env "typeorm" {
  src = data.external_schema.typeorm.url
  dev = "docker://mysql/8/dev"
  migration {
    dir = "file://migrations"
  }
  format {
    migrate {
      diff = "{{ sql . \"  \" }}"
    }
  }
}

As a library

In TS Script

If you want to use the provider as TS program, you can use the provider as follows:

Create a new file named load.ts with the following contents:

#!/usr/bin/env ts-node-script

import { loadEntities } from "@ariga/atlas-provider-typeorm/build/load";

// import typeorm entities you want to load
import { User } from "./entities/User";
import { Blog } from "./entities/Blog";

loadEntities("mysql", [User, Blog]).then((sql) => {
  console.log(sql);
});

In JS Script

If you want to use the provider as JS program, you can use the provider as follows:

Create a new file named load.js with the following contents:

#!/usr/bin/env node

const loadEntities = require("@ariga/atlas-provider-typeorm/build/load").loadEntities;
const EntitySchema = require("typeorm").EntitySchema;

// require typeorm entities you want to load
const post = new EntitySchema(require("./entities/Post"));
const category = new EntitySchema(require("./entities/Category"));

loadEntities("mysql", [post, category]).then((sql) => {
  console.log(sql);
});

Next, in your project directory, create a new file named atlas.hcl with the following contents:

data "external_schema" "typeorm" {
    program = [
        "ts-node",
        "load.ts", // for javascript: "node", "load.js"
    ]
}

env "typeorm" {
    src = data.external_schema.typeorm.url
    dev = "docker://mysql/8/dev"
    migration {
        dir = "file://migrations"
    }
    format {
        migrate {
            diff = "{{ sql . \"  \" }}"
        }
    }
}

Usage

Once you have the provider installed, you can use it to apply your TypeORM schema to the database:

Apply

You can use the atlas schema apply command to plan and apply a migration of your current TypeORM schema to your database. This works by inspecting the target database and comparing it to the TypeORM schema and creating a migration plan. Atlas will prompt you to confirm the migration plan before applying it to the database.

atlas schema apply --env typeorm -u "mysql://root:password@localhost:3306/mydb"

Where the -u flag accepts the URL to the target database.

Diff

Atlas supports a version migration workflow, where each change to the database is versioned and recorded in a migration file. You can use the atlas migrate diff command to automatically generate a migration file that will migrate the database from its latest revision to the current TypeORM schema.

atlas migrate diff --env typeorm 

Supported Databases

The provider supports the following databases:

  • MySQL
  • MariaDB
  • PostgreSQL
  • SQLite
  • Microsoft SQL Server

Issues

Please report any issues or feature requests in the ariga/atlas repository.

License

This project is licensed under the Apache License 2.0.

版本与发布记录

@ariga/atlas-provider-typeorm 共发布 24 个版本,首次发布于 2023/10/03;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.2latest2026/02/108 个月前
0.3.12025/06/121.4 年前
0.3.02025/05/281.4 年前
0.2.12025/05/261.5 年前
0.2.02025/03/061.7 年前
0.1.12023/12/102 年前

关于 @ariga/atlas-provider-typeorm 的常见问题

@ariga/atlas-provider-typeorm 是什么?

Load Typeorm models into an Atlas project.

如何安装 @ariga/atlas-provider-typeorm?

在项目目录运行 npm install @ariga/atlas-provider-typeorm,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 atlas-provider-typeorm,可以用 npx atlas-provider-typeorm 直接运行。

@ariga/atlas-provider-typeorm 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/ariga__atlas-provider-typeorm 是否存在。

@ariga/atlas-provider-typeorm 可以商用吗?

@ariga/atlas-provider-typeorm 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@ariga/atlas-provider-typeorm 的下载量有多少?

根据 npm 官方下载统计,@ariga/atlas-provider-typeorm 在 2026/10/07 – 2026/11/05 这 30 天内被下载 137,667 次,日均约 4,589 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ariga/atlas-provider-typeorm 还在维护吗?

最新版本 0.3.2 发布于 2026/02/10(8 个月前);至今共发布 24 个版本,其中过去 12 个月发布了 1 个;首次发布于 2023/10/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。