Convert SQL DEFAULT Values to Sequelize defaultValue

Learn how SQL DEFAULT clauses including constants, booleans, timestamps, and function calls are mapped to Sequelize's defaultValue option in model definitions.

Advanced Features

Detailed Explanation

DEFAULT Values in Sequelize

SQL columns can have default values that are applied when no explicit value is provided during INSERT. Sequelize maps these to the defaultValue option on field definitions.

Constant Defaults

String and numeric constants are converted directly:

status VARCHAR(20) DEFAULT 'active'
-- becomes -->
status: { type: DataTypes.STRING(20), defaultValue: 'active' }

retry_count INTEGER DEFAULT 3
-- becomes -->
retry_count: { type: DataTypes.INTEGER, defaultValue: 3 }

Boolean Defaults

The converter normalizes various boolean representations:

is_active BOOLEAN DEFAULT TRUE       --> defaultValue: true
is_deleted BOOLEAN DEFAULT FALSE     --> defaultValue: false
is_verified BOOLEAN DEFAULT 1        --> defaultValue: true

Timestamp Defaults

SQL timestamp functions are mapped to Sequelize constants:

SQL Default Sequelize Default
CURRENT_TIMESTAMP DataTypes.NOW
NOW() DataTypes.NOW
CURRENT_TIMESTAMP() DataTypes.NOW

UUID Generation

UUID generation functions map to Sequelize's built-in UUID generators:

SQL Default Sequelize Default
gen_random_uuid() DataTypes.UUIDV4
uuid_generate_v4() DataTypes.UUIDV4
UUID() DataTypes.UUIDV4
NEWID() (SQL Server) DataTypes.UUIDV4

Database Functions

For other database functions, the converter uses sequelize.literal():

score DECIMAL DEFAULT RANDOM()
-- becomes -->
score: { type: DataTypes.DECIMAL, defaultValue: sequelize.literal('RANDOM()') }

Sequelize Behavior

When defaultValue is set, Sequelize includes it in the JavaScript model instance immediately upon Model.build() — you don't need to save to the database first to see the default. However, database-level defaults (via sequelize.literal) are only resolved after the INSERT executes.

Use Case

You are migrating a database with columns that use various default strategies: static values, boolean flags, timestamps, and UUID generation. The converter maps each pattern to the appropriate Sequelize constant or literal.

Try It — SQL to Sequelize Model

Open full tool