sequelize-typescript-migration-lts is a migration tool designed for Sequelize ORM users who leverage TypeScript for defining their database models. It automates the generation of database migration files by detecting schema changes based on the current state of Sequelize TypeScript models (which use decorators like `@Table` and `@Column`). The package then creates `up` and `down` functions for these changes, eliminating the need for manual migration script writing, similar to Django's `makemigration` feature. The current stable version is 3.2.5, with recent updates focusing on bug fixes and supporting features like snake-case column names. It's important to note that this tool is specifically built for `sequelize-typescript` models and does not support plain `sequelize` model definitions. The project is an LTS (Long-Term Support) fork, integrating improvements from various community forks of the original `sequelize-auto-migrations` project.
npm install sequelize-typescript-migration-ltsVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to programmatically generate a new database migration file using `SequelizeTypescriptMigration.makeMigration`. It sets up a Sequelize instance, specifies an output directory for the migration, and names the migration file. This code should be executed after defining your Sequelize TypeScript models.
Refer to the compatibility section in the package's documentation to ensure the correct version of `sequelize-typescript-migration-lts` is installed for your `sequelize` ORM version.
Before applying `down` migrations in production or critical environments, review the generated `down` functions for complex relational changes and manually adjust the order of operations if necessary.
Ensure all models intended for migration generation are defined using `sequelize-typescript` decorators (`@Table`, `@Column`, etc.) and are registered correctly with your `sequelize-typescript` instance.
Always review the generated migration files (both `up` and `down` functions) before applying them, especially for significant schema alterations, to catch any potential issues or inefficiencies.
Ensure your `Sequelize` instance is configured with the correct `models` path, typically using `models: [path.join(__dirname, 'models')]`, and that all models have `@Table` and `@Column` decorators.
Verify the installation with `npm i sequelize-typescript-migration-lts` and ensure the import statement is `import { SequelizeTypescriptMigration } from 'sequelize-typescript-migration-lts';`.Inspect the failing `down` function in the generated migration file. Manually adjust the SQL or Sequelize queries to ensure proper reversal of changes, paying close attention to relational dependencies and data integrity.