SQL to Sequelize Models

Paste one or more SQL CREATE TABLE statements and get ready-to-use Sequelize model definitions back. The converter maps every standard SQL column type to the right DataTypes.*, carries over NOT NULL, PRIMARY KEY, UNIQUE, AUTO_INCREMENT/SERIAL, and DEFAULT values so your models reflect the real schema without manual retyping.

How to use the SQL to Sequelize Models

Paste your CREATE TABLE DDL into the input box — multiple tables separated by semicolons are supported. Click Generate Models (or press Example to load a demo) and the output area fills with sequelize.define() calls, one per table.

  1. Paste DDL — supports MySQL and Postgres syntax, including IF NOT EXISTS and backtick/double-quote identifiers.
  2. Review output — each column is represented as an attribute object with type, allowNull, primaryKey, autoIncrement, unique, and defaultValue where applicable.
  3. Copy — paste directly into your Sequelize project. Add const { Sequelize, DataTypes } = require('sequelize'); and a sequelize connection at the top of the file.

Foreign key columns are emitted as plain INTEGER/BIGINT attributes. To add the actual association call User.hasMany(Post, { foreignKey: 'user_id' }) separately after model definition — that is the Sequelize idiomatic approach.

What is Sequelize and why generate models from SQL?

Sequelize is a promise-based ORM for Node.js that supports PostgreSQL, MySQL, MariaDB, SQLite, and SQL Server. Every table you want to query through Sequelize must have a corresponding model — a JavaScript object that describes the table's columns, their data types, and constraints. Writing these models by hand from an existing schema is tedious and error-prone: a single mismatched type or a missing allowNull: false can cause subtle validation failures or incorrect generated queries.

The canonical Sequelize pattern uses sequelize.define('ModelName', attributes, options) where attributes is a map of column names to descriptor objects and options carries settings like tableName, timestamps, and underscored. SQL types map to DataTypes members: INTDataTypes.INTEGER, VARCHAR(n)DataTypes.STRING(n), TEXTDataTypes.TEXT, BOOLEANDataTypes.BOOLEAN, TIMESTAMPDataTypes.DATE, DECIMAL(p,s)DataTypes.DECIMAL(p,s), JSON/JSONBDataTypes.JSON, and UUIDDataTypes.UUID.

This tool automates that mechanical translation. It is especially useful when inheriting a legacy database, working database-first rather than code-first, or syncing models after a migration adds new columns. It does not replace Sequelize Migrations — for schema changes in production always use queryInterface migrations — but it gives you a correct model baseline to work from.

Common use cases

  • Legacy database adoption — inherit an existing MySQL or Postgres schema and need Sequelize models without writing each one by hand.
  • Database-first development — your team keeps the SQL schema as the source of truth and generates application code from it.
  • Model synchronization after migrations — a DBA adds columns; regenerate models instead of hunting down every attribute to update.
  • Onboarding documentation — generated models serve as readable, typed documentation of a schema for new developers joining the project.
  • Multi-dialect projects — the same DDL runs on MySQL and Postgres; the converter produces Sequelize models that work on both without change.

Frequently asked questions

Does the output include model associations (hasMany, belongsTo)?

No — Sequelize associations are defined separately from column attributes. The converter emits foreign key columns as plain integer attributes. Add association methods (User.hasMany(Post), Post.belongsTo(User)) in a separate associations file after model definition.

What happens to SERIAL or AUTO_INCREMENT columns?

They are emitted with autoIncrement: true and primaryKey: true. On Postgres, SERIAL is treated the same as INTEGER AUTO_INCREMENT since Sequelize handles the sequence automatically when autoIncrement is set.

Are DEFAULT values preserved?

Yes — simple literal defaults (numbers, strings, TRUE/FALSE) are captured as defaultValue. Function-based defaults like NOW() or uuid_generate_v4() are emitted as a comment since Sequelize defaultValue does not support raw SQL functions; use a beforeCreate hook or Sequelize.fn() for those.

Does it handle composite primary keys?

Table-level PRIMARY KEY(a, b) constraints are noted in a comment — Sequelize supports composite keys but requires a different setup (set primaryKey: true on each column and pass { timestamps: false } to sequelize.define). The converter flags these rather than silently emitting incorrect code.

Can I use the output with Sequelize TypeScript?

The output is plain JavaScript sequelize.define() syntax. For TypeScript, you would additionally define an interface extending Model and use the Model.init() API instead. Consider using sequelize-typescript or the official Sequelize CLI --typescript flag to finish the conversion.