Registry / database / sequelize-migration

sequelize-migration

JSON →
library1.0.1jsnpmunverified

A module for handling database migrations using raw SQL scripts with Sequelize. This package allows you to manage versioned SQL script executions for MySQL and PostgreSQL. It creates a tracking table (`sph_script_execution`) to record which scripts have been applied, ensuring idempotent upgrades. The module takes a Sequelize instance and a module configuration including version, script directory, and per-dialect upgrade scripts. Designed for simple, file-based migration workflows. Version 1.0.1 is the latest stable release. Alternatives like Umzug or Sequelize's built-in migration CLI offer more features, but this package provides a lightweight approach for projects that prefer pure SQL. Low maintenance cadence.

npm install sequelize-migration
INSTALL
IMPORT
SIG · SEQUELIZE-MIGRATIO
S
sequelize-migration
databasejavascriptv1.0.1
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.

SequelizeMigration
const SequelizeMigration = require('sequelize-migration');
import SequelizeMigration from 'sequelize-migration';
Package uses CommonJS. ESM import may fail in Node environments without transpilation.
SequelizeMigration constructor
new SequelizeMigration(sequelize);
new SequelizeMigration();
Must pass a valid Sequelize instance (not a Sequelize constructor or options object).
addModule method
migration.addModule({ module: 'my-module', version: '1.0.0', dir: './scripts', dialects: { mysql: [ { version: '1.0.0', upgrade: ['upgrade.sql'] } ] } });
migration.addModule({ module: 'my-module' });
Requires full config object including version, dir, and dialects. Missing fields cause silent failures or runtime errors.

Creates a Sequelize instance, initializes the migration module, adds an upgrade script, and runs pending migrations.

const Sequelize = require('sequelize'); const SequelizeMigration = require('sequelize-migration'); const sequelize = new Sequelize(process.env.DB_NAME ?? 'test', process.env.DB_USER ?? 'root', process.env.DB_PASS ?? '', { host: process.env.DB_HOST ?? 'localhost', dialect: 'mysql' }); const migration = new SequelizeMigration(sequelize); migration.addModule({ module: 'my-app', version: '1.0.0', dir: './scripts', dialects: { mysql: [ { version: '1.0.0', upgrade: ['create_users.sql'] } ], postgres: [] } }); migration.sync().then(() => { console.log('Migrations applied successfully'); }).catch(err => { console.error('Migration failed:', err); });
Debug
Known issues
gotchaIf no upgrades are defined for a dialect, the module may still query the database and create tracking tables. Ensure all dialects used are explicitly listed with at least an empty array.
fix
Always include entries for every dialect you support even if no scripts exist: dialects: { mysql: [], postgres: [] }
affects: >=1.0.0
gotchaThe migration module name must be unique across all modules. Duplicate module names will cause conflicts in the tracking table 'sph_script_execution'.
fix
Use a unique identifier for the 'module' field, e.g., 'my-org/my-app' or a UUID.
affects: >=1.0.0
breakingThe module only supports MySQL and PostgreSQL. Using other dialects may produce unexpected errors.
fix
If you need SQLite or MSSQL, consider alternatives like Umzug.
affects: >=1.0.0
deprecatedThe package has seen no updates since version 1.0.1 and its GitHub repository is archived. No future maintenance expected.
fix
Evaluate switching to actively maintained migration tools like Umzug, Sequelize CLI migrations, or Knex.
affects: >=1.0.0
gotchaThe upgrade script paths are relative to the 'dir' option. If scripts are not found, the migration may silently skip or throw a cryptic error.
fix
Ensure the script directory structure matches expectations: [dir]/[dialect]/[filename]. Test with an absolute path if relative fails.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'sequelize-migration'
Package not installed or not in node_modules
fix
Run 'npm install sequelize-migration --save' to add it as a dependency.
TypeError: SequelizeMigration is not a constructor
Using import or incorrect require path
fix
Use correct CommonJS require: const SequelizeMigration = require('sequelize-migration');
SequelizeMigration is not a constructor
Probably using ES6 import which doesn't work with this CommonJS module
fix
Switch to require() instead of import.
Cannot read property 'sync' of undefined
Forgot to instantiate SequelizeMigration with the new keyword
fix
Create instance: const migration = new SequelizeMigration(sequelize);
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
sequelizerequiredRequired as a peer dependency to create Sequelize instance and interact with the database.
Agent activity
22 hits · last 30 days
node
16
Meta
1
Amazon
1
Resources
sequelize-migration — npm install sequelize-migration · libregistry