Bundle
dsh-db-migration
数据库迁移生成:对比两个 SQL DDL 文件(CREATE TABLE),检测新增/删除/变更的表与列,生成 ALTER TABLE 迁移 SQL
- Source
- uckkk
- License
- MIT
- Updated
- Updated 7 days ago
Readme
# dsh-db-migration · 数据库迁移生成
对比两个 SQL DDL 文件(`CREATE TABLE` 集合),检测新增/删除/变更的表与列,并生成 `ALTER TABLE` / `DROP TABLE` 迁移 SQL。纯 Node 实现,无网络、无外部服务。
## 提供的工具
| 工具 | 作用 |
|---|---|
| `diff_schema` | 对比旧版/新版 DDL,返回结构差异统计 + 迁移 SQL |
## 安装
```bash
dsh plugin add dsh-db-migration
```
安装后在 profile 的 `package.json` 的 `dsh.profile.bundles` 中加入 `"dsh-db-migration"`。
## 用法示例
```
对比旧版和新版数据库结构,生成迁移 SQL
→ 调用 diff_schema(oldFile="schema_v1.sql", newFile="schema_v2.sql", outFile="migrations/20260816_up.sql")
```
## 识别范围
- 新增/删除表(生成 `CREATE TABLE` / `DROP TABLE`)
- 新增/删除列(生成 `ALTER TABLE ADD/DROP COLUMN`)
- 列类型变更(生成 `ALTER TABLE MODIFY COLUMN`)
- 支持常见类型(含 `DECIMAL(10,2)`、`VARCHAR(255)`、`ENUM('a','b')` 等带括号/逗号类型)
## 说明
- 覆盖常见 `CREATE TABLE`(MySQL/PostgreSQL/SQLite 基础列定义);**外键、索引、复合主键、复杂默认值/触发器不在处理范围**。
- 生成的迁移 SQL 是**起点**,涉及线上数据时请务必人工复核后再执行。
## 安装
```bash
dsh plugin add github:uckkk/dsh-db-migration
```
> 安装即在本机运行第三方代码,请自行审阅源码。
## 安装
```bash
dsh plugin add github:uckkk/dsh-db-migration
```
## 使用
安装后在会话中调用该插件注册的工具即可。
## 许可
MIT
> 安装即在本机运行第三方代码,请自行审阅源码。
Install
dsh plugin --profile web add github:uckkk/dsh-db-migration
Profile: web
With the hub plugin installed, ask your agent to install it by name — it resolves the same plan shown here.
dsh plugin --profile web add github:stvlynn/dsh.fish#path:packages/dsh-plugin-hub
install dsh-db-migration from the hub
- This source has no pinned commit, so a later push upstream changes what installs. Prefer pinning a commit.