Registry / database / sequelize-replace-enum-postgres

sequelize-replace-enum-postgres

JSON →
library1.6.0jsnpmunverified

Utility for replacing PostgreSQL ENUM values in Sequelize migrations. Version 1.6.0 is current, with irregular release cadence. It provides a single function to safely add/remove enum values without dropping and recreating the column, avoiding common pitfalls. Key differentiator: handles complex cases like columns with default values and custom enum names, unlike raw SQL approaches. Only supports PostgreSQL with Sequelize.

npm install sequelize-replace-enum-postgres
INSTALL
IMPORT
SIG · SEQUELIZE-REPLACE-
S
sequelize-replace-enum-postgres
databasejavascriptv1.6.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.

replaceEnum
import replaceEnum from 'sequelize-replace-enum-postgres'
const replaceEnum = require('sequelize-replace-enum-postgres'); // This works but is not the default import
ESM default export. Also available via require with .default property.
default
const replaceEnum = require('sequelize-replace-enum-postgres').default;
const replaceEnum = require('sequelize-replace-enum-postgres'); // Function will be the module.exports object, not the function itself
CommonJS usage requires accessing .default property.

Migration using replaceEnum to add 'on-demand' to an existing ENUM column.

import replaceEnum from 'sequelize-replace-enum-postgres'; export default { up: (queryInterface, Sequelize) => { return replaceEnum({ queryInterface, tableName: 'eventRecurrence', columnName: 'recurrenceType', defaultValue: 'weekly', newValues: ['weekly', 'monthly', 'yearly', 'on-demand'], enumName: 'enum_event_recurrence_recurrence_type' }); }, down: (queryInterface, Sequelize) => { return replaceEnum({ queryInterface, tableName: 'eventRecurrence', columnName: 'recurrenceType', defaultValue: 'weekly', newValues: ['weekly', 'monthly', 'yearly'], enumName: 'enum_event_recurrence_recurrence_type' }); } };
Debug
Known issues
gotchaEnum name parameter (enumName) is required but often omitted, causing unexpected errors.
fix
Always provide the exact PostgreSQL enum name as shown in the database schema.
affects: >=1.0.0
gotchaDefault value (defaultValue) must match one of the existing enum values, otherwise the migration will fail.
fix
Ensure defaultValue is among the current enum values (not an empty string or invalid).
affects: >=1.0.0
gotchaThe function does not support altering columns with dependencies (views, other tables) referencing the enum type.
fix
Manually drop dependencies before running the migration, or use a transactional approach.
affects: >=1.0.0
gotchaThe newValues array must include all existing values plus new ones, not just the ones to add.
fix
Ensure newValues is the complete set of enum values after migration.
affects: >=1.0.0
Errors
Common errors & fixes
const replaceEnum = require('sequelize-replace-enum-postgres'); replaceEnum(...) is not a function
CommonJS import returns the module.exports object, which has a default property.
fix
Use require('sequelize-replace-enum-postgres').default to get the function.
replaceEnum is not defined
ESM import statement missing or incorrect path.
fix
Use 'import replaceEnum from "sequelize-replace-enum-postgres"'
column "columnName" of relation "tableName" does not exist
Incorrect columnName or tableName passed to function.
fix
Double-check the exact column and table names from your Sequelize models.
Upgrade
Version history
1.6.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Meta
2
Resources
sequelize-replace-enum-postgres — npm install sequelize-replace-enum-postgres · libregistry