feat(cli): add migration generate, run, status & undo#18193
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a Sequelize+Umzug migration subsystem to the CLI: dynamic dialect resolution, stricter config types, migration discovery/execution APIs (run/undo/status), oclif commands with JSON output, test fixtures/helpers, and supporting packaging/configuration changes. Changes
Sequence DiagramsequenceDiagram
participant User
participant CLI as CLI Command
participant API as Migration API
participant Umzug
participant Sequelize
participant DB as SQLite DB
participant FS as File System
User->>CLI: migration:run (--step=2)
CLI->>API: runMigrations(options)
API->>API: createUmzug()
API->>Sequelize: new Sequelize(config)
Sequelize->>DB: connect()
API->>FS: scan migrationFolder
FS-->>API: [migration files/dirs]
API->>Umzug: register migrations (SQL / JS modules / dirs)
Umzug->>Sequelize: use SequelizeStorage
API->>Umzug: umzug.up({step: 2})
Umzug->>FS: read up.sql / import module
FS-->>Umzug: SQL / JS migration
Umzug->>Sequelize: execute migration SQL / call up()
Sequelize->>DB: run SQL
DB-->>Sequelize: success
Umzug->>Sequelize: update migrations table
Umzug-->>API: [executed migrations]
API->>Sequelize: close()
API-->>CLI: MigrationMeta[]
CLI-->>User: formatted output (JSON or human)
sequenceDiagram
participant User
participant CLI as CLI Command
participant API as Migration API
participant Umzug
participant Sequelize
participant DB as SQLite DB
participant FS as File System
User->>CLI: migration:undo (--all)
CLI->>API: undoMigrations({to:0})
API->>API: createUmzug()
API->>Sequelize: new Sequelize(config)
Sequelize->>DB: connect()
API->>Umzug: umzug.down({to:0})
loop for each migration (newest → oldest)
Umzug->>FS: read down.sql / import module
FS-->>Umzug: SQL / JS migration down
Umzug->>Sequelize: execute down
Sequelize->>DB: run SQL
DB-->>Sequelize: success
Umzug->>Sequelize: remove migration record
end
Umzug-->>API: [reverted migrations]
API->>Sequelize: close()
API-->>CLI: MigrationMeta[]
CLI-->>User: formatted output (JSON or human)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
|
I'll revert the pin if it passes on your branch :) |
WikiRik
left a comment
There was a problem hiding this comment.
Ran some parts through AI. I am missing some tests for JS/TS migration files and if there's only an up.sql
If you want I can commit the changes I let AI make to another PR (or to this PR directly)
* main: (200 commits) meta: update actions/upload-artifact action to v7.0.1 (sequelize#18212) meta: update sequelize AUTHORS (sequelize#18208) feat(cli): add migration generate, run, status & undo (sequelize#18193) feat(core): Drop the ability to specify the dialect as a string (sequelize#18204) feat: update some dialect adapters (sequelize#18189) feat(postgres): replace pg-hstore with inline hstore parser (sequelize#18151) feat(core): add `sql.random`, improve `Order` typing (sequelize#18203) meta: use Sequelize Bot for drafting PRs (sequelize#18201) meta: automatically mark unfinished PRs as draft (sequelize#18197) meta: update dependency @oclif/test to v4.1.18 (sequelize#18198) fix(core): replace @typeparam with @template in JSDoc (sequelize#18094) feat(core): Add support for UUID v7 (sequelize#17832) meta: update sequelize AUTHORS (sequelize#18190) meta: update dependency @oclif/plugin-help to ^6.2.43 (sequelize#18195) meta: update dependency esbuild to v0.28.0 (sequelize#18192) meta: update dependency @oclif/plugin-help to ^6.2.42 (sequelize#18191) meta: update dependency @oclif/core to ^4.10.5 (sequelize#18187) meta: update sequelize AUTHORS (sequelize#18158) feat: add Node 24 support, drop Node 18 (sequelize#18185) feat(core): add support for readonly attribute arrays (sequelize#18186) ...
Pull Request Checklist
Description of Changes
This PR implements sub-commands for
sequelize migration:run,status, andundorun
Like the others, supports JSON & plain text:
Status
Undo
Other changes
The "dialect" option in the config file does not accept dialect names anymore. Instead it must be either a dialect class (e.g.,
PostgresDialect), or a path to a dialect class (e.g.,'@sequelize/postgres#PostgresDialect', for when using a JSON config file)The interactive mode does not prompt for optional flags anymore
Importing
@sequelize/clidoes not return oclif anymore, but the API filesList of Breaking Changes
database.dialectoption is now either a Dialect class (e.g.PostgresDialect) or a path to a dialect class (e.g.'@sequelize/postgres#PostgresDialect')@sequelize/clinow exposes the JavaScript functions used in the CLI instead of the oclif run functionTODO
Summary by CodeRabbit
New Features
Tests
Chores
Style