In DSH workflows, maintaining database schema changes is a common requirement. Manually writing ALTER TABLE statements or comparing two DDL files can be error-prone and time-consuming. dsh-db-migration aims to automate this process by comparing two SQL DDL files to generate migration scripts.

This plugin is maintained by uckkk and is a pure Node.js tool with no network dependencies. It focuses on detecting differences in table structure and column definitions between two DDL files, then outputting the corresponding ALTER TABLE or DROP TABLE statements.

Core Features

This plugin primarily handles DDL-level change detection and SQL generation:

  1. DDL Comparison and Statistics: Compares old and new DDL files, returning structural difference statistics and the generated migration SQL.
  2. Table-Level Changes: Detects added or removed tables and generates CREATE TABLE or DROP TABLE statements.
  3. Column-Level Changes: Detects added or removed columns and generates ALTER TABLE ADD/DROP COLUMN statements.
  4. Column Type Changes: Detects changes to column types and generates ALTER TABLE MODIFY COLUMN statements.
  5. Type Support: Supports common types, including types with parentheses, such as DECIMAL(10,2), VARCHAR(255), and ENUM('a','b').

Installation and Enabling

Installing this plugin requires the DeepSeek Harness command-line tool.

dsh plugin add github:uckkk/dsh-db-migration

After installation, you need to enable this bundle in the profile’s package.json configuration file. Add the following to the dsh.profile.bundles field:

"dsh-db-migration"

Typical Usage

After successful installation, you can invoke the tools registered by this plugin in a session. The core tool is diff_schema.

Example: Compare schema_v1.sql and schema_v2.sql, and write the generated migration SQL to migrations/20260816_up.sql.

diff_schema(oldFile="schema_v1.sql", newFile="schema_v2.sql", outFile="migrations/20260816_up.sql")

Use Cases and Notes

Use Cases: Suitable for scenarios where database schema migration scripts need to be generated quickly, especially when comparing two versions of DDL files to identify differences.

Scope and Caveats:
* The plugin covers common CREATE TABLE syntax (basic column definitions for MySQL/PostgreSQL/SQLite).
* It does not handle foreign keys, indexes, composite primary keys, complex default values, or triggers.
* The generated migration SQL is only a starting point. When online data is involved, please manually review it before execution.
* Installing the plugin runs third-party code on your local machine. Please review the source code and license (MIT) yourself.