Registry / database / sequelize-migreat

sequelize-migreat

JSON →
library7.0.0jsnpmunverified

Migreat is a migration tool for Sequelize that simplifies schema management by allowing you to define models and associations declaratively, then automatically generating TypeScript migration files. Current stable version is 7.0.0, with a focus on type safety and developer experience. Unlike raw Sequelize migrations, Migreat provides a higher-level abstraction to define schemas and generate migrations programmatically, reducing boilerplate and manual SQL. It supports both initial schema generation and incremental migration from existing schemas.

npm install sequelize-migreat
INSTALL
IMPORT
SIG · SEQUELIZE-MIGREAT
S
sequelize-migreat
databasejavascriptv7.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Migreat
import { Migreat } from 'sequelize-migreat'
import Migreat from 'sequelize-migreat'
Named export, not default. Must use {} for import.
Migration
import { Migration, Migreat } from 'sequelize-migreat'
import { Migration } from 'sequelize-migreat' alone without Migreat
Migration type is returned by Migreat functions. Only import if needed for type annotations.
SchemaDef
import { SchemaDef, Migreat } from 'sequelize-migreat'
const { SchemaDef } = require('sequelize-migreat')
ESM-only since v7.0.0. CommonJS require will error.

Shows how to define a model, create a schema, generate a migration, and execute it using Sequelize.

import { Migreat, SchemaDef, Attribute, Association } from 'sequelize-migreat'; import { Sequelize } from 'sequelize'; // Define a model const UserModel = Migreat.defineModel({ name: 'users', attributes: { id: Attribute.uuid(), name: Attribute.string(), }, associations: {}, }); // Define a schema const schemaDef = new SchemaDef([UserModel]); // Generate initial migration const migration = Migreat.generateMigrationFromSchema(schemaDef); // Execute migration (requires Sequelize instance) const sequelize = new Sequelize(process.env.DATABASE_URL ?? ''); Migreat.executeMigration(migration, sequelize);
Debug
Known issues
breakingv7.0.0 migrated from CommonJS to ESM. require() will throw ERR_REQUIRE_ESM.
fix
Use import syntax or dynamic import() instead of require()
affects: >=7.0.0
deprecatedMigreat.Attr and Migreat.Assoc are deprecated in favor of standalone Attribute and Association exports.
fix
Import Attribute and Association directly from 'sequelize-migreat'
affects: >=7.0.0
gotchaSchemaDef expects an array of models; passing a single model object will fail silently or throw.
fix
Always wrap in array: new SchemaDef([model])
affects: >=0.0.0
gotchagenerateMigrationFromMigration requires a targetSchemaDef, not a previous migration.
fix
Pass the new schema definition as the second argument
affects: >=0.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module not supported
Using CommonJS require with sequelize-migreat v7.0.0+ which is ESM-only
fix
Change to import syntax or set { "type": "module" } in package.json
TypeError: Migreat.defineModel is not a function
Importing Migreat as default instead of named export
fix
Use import { Migreat } from 'sequelize-migreat'
Upgrade
Version history
7.0.0latest on npm
Audit
Dependencies
sequelizeoptionalSequelize is used as the ORM for database operations in generated migrations.
Agent activity
11 hits · last 30 days
node
8
Meta
2
Resources
sequelize-migreat — npm install sequelize-migreat · libregistry