Skip to content

dsh-db-migration

Verified

dsh-db-migration · v0.1.0 · MIT

数据库迁移生成:对比两个 SQL DDL 文件(CREATE TABLE),检测新增/删除/变更的表与列,生成 ALTER TABLE 迁移 SQL

Install

dsh plugin add dsh-db-migration

Confirm the layer applied with dsh --profile default --dump-config — see the install guide.

Source

Published to npm without a public repository. Inspect the package contents before installing.

Tags

Readme

dsh-db-migration · 数据库迁移生成

对比两个 SQL DDL 文件(CREATE TABLE 集合),检测新增/删除/变更的表与列,并生成 ALTER TABLE / DROP TABLE 迁移 SQL。纯 Node 实现,无网络、无外部服务。

提供的工具

工具 作用
diff_schema 对比旧版/新版 DDL,返回结构差异统计 + 迁移 SQL

安装

dsh plugin add dsh-db-migration

安装后在 profile 的 package.jsondsh.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 是起点,涉及线上数据时请务必人工复核后再执行。