Node.js

Sequelize migrations, drawn as a database diagram

sequelize-cli migrations: JavaScript files with up and down using the queryInterface. SchemaDrawer runs Sequelize 6.37 with sequelize-cli 6.6 against a throw-away database of the engine you choose and returns an SVG of the schema it produces.

What to upload

Upload the migration files directly at the top level. Each exports up(queryInterface, Sequelize) and down, as sequelize-cli migration:generate writes them.

The sample below is the PetClinic schema written for Sequelize, one of the sets SchemaDrawer's own tests draw on every engine:

migrations/
├── 20240101000001-create-owners-and-pets.js
├── 20240101000002-create-vets.js
└── 20240101000003-create-visits.js

Formats

.js, .cjs, .ts and .cts files.

How it runs

sequelize db:migrate with a configuration generated for the chosen engine; your own .sequelizerc is not used. The database is a fresh PostgreSQL, MySQL, MariaDB, SQL Server, Oracle or SQLite container in the version you ask for; nothing of yours is touched.

Databases you can draw Sequelize on

PostgreSQL 10, 11, 12, 13, 14, 15, 16, 17, 18 MySQL 8.0, 8.4, 9 MariaDB 10.6, 11.4, 11.8, 12 SQL Server 2017, 2019, 2022, 2025 Oracle 21, 23 SQLite

At a glance

Runs
Sequelize 6.37 with sequelize-cli 6.6
API value
migrationType=SEQUELIZE
Engines
6 of 6: PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite
Output
SVG diagram with tables, columns and types, primary and foreign keys
Price
Free today; enterprise plans are coming
Example

The PetClinic schema in Sequelize

Owners, pets, types, vets, specialties and visits: the same seven tables every sample set on this site creates. These are the exact files the tests upload.

'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable('owners', {
      id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true },
      first_name: { type: Sequelize.STRING(50), allowNull: false },
      last_name: { type: Sequelize.STRING(50), allowNull: false },
      address: { type: Sequelize.STRING(255), allowNull: true },
      city: { type: Sequelize.STRING(80), allowNull: true },
      telephone: { type: Sequelize.STRING(20), allowNull: true },
    });

    await queryInterface.createTable('types', {
      id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true },
      name: { type: Sequelize.STRING(80), allowNull: false },
    });

    await queryInterface.createTable('pets', {
      id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true },
      name: { type: Sequelize.STRING(50), allowNull: false },
      birth_date: { type: Sequelize.DATEONLY, allowNull: true },
      type_id: {
        type: Sequelize.INTEGER,
        allowNull: false,
        references: { model: 'types', key: 'id' },
      },
      owner_id: {
        type: Sequelize.INTEGER,
        allowNull: false,
        references: { model: 'owners', key: 'id' },
      },
    });
  },

  async down(queryInterface) {
    await queryInterface.dropTable('pets');
    await queryInterface.dropTable('types');
    await queryInterface.dropTable('owners');
  },
};
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable('vets', {
      id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true },
      first_name: { type: Sequelize.STRING(50), allowNull: false },
      last_name: { type: Sequelize.STRING(50), allowNull: false },
    });

    await queryInterface.createTable('specialties', {
      id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true },
      name: { type: Sequelize.STRING(80), allowNull: false },
    });

    await queryInterface.createTable('vet_specialties', {
      vet_id: {
        type: Sequelize.INTEGER,
        allowNull: false,
        primaryKey: true,
        references: { model: 'vets', key: 'id' },
      },
      specialty_id: {
        type: Sequelize.INTEGER,
        allowNull: false,
        primaryKey: true,
        references: { model: 'specialties', key: 'id' },
      },
    });
  },

  async down(queryInterface) {
    await queryInterface.dropTable('vet_specialties');
    await queryInterface.dropTable('specialties');
    await queryInterface.dropTable('vets');
  },
};
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable('visits', {
      id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true },
      pet_id: {
        type: Sequelize.INTEGER,
        allowNull: false,
        references: { model: 'pets', key: 'id' },
      },
      visit_date: { type: Sequelize.DATEONLY, allowNull: true },
      description: { type: Sequelize.STRING(255), allowNull: true },
    });
  },

  async down(queryInterface) {
    await queryInterface.dropTable('visits');
  },
};
diagram.svg
ER diagram of the PetClinic schema drawn by SchemaDrawer: owners, pets, types, vets, specialties, vet_specialties and visits with their columns, primary keys and foreign keys

Every variant of the sample produces these seven tables. This diagram was drawn from the Flyway variant on PostgreSQL 18; on MySQL the types read INT and VARCHAR, on Oracle the names are upper case.

Run it

Draw your Sequelize migrations

One multipart request queues the drawing; poll the job until it succeeds and download the SVG. Or let the GitHub Action do it and open a pull request with the diagram.

With curl

curl -X POST https://schemadrawer.com/api/v1/drawing \
  -H "Request-Id: $(uuidgen)" \
  -F "userId=5f0c1d2e-3a4b-4c5d-8e6f-7a8b9c0d1e2f" \
  -F "migrationType=SEQUELIZE" \
  -F "databaseType=POSTGRESQL" \
  -F "version=18" \
  -F "files=@migrations/20240101000001-create-owners-and-pets.js" \
  -F "files=@migrations/20240101000002-create-vets.js" \
  -F "files=@migrations/20240101000003-create-visits.js"
# {"jobId":"0b6e2f4c-8d1a-4c3e-9f7a-2a5b6c7d8e9f"}

Then poll GET https://schemadrawer.com/api/v1/drawing/{jobId} until status is SUCCESS and fetch diagramUrl. Details in the getting started guide and the API reference.

With the GitHub Action

- uses: schemadrawercom/action@v1
  with:
    sql-directory: migrations
    output-path: docs/schema-diagram.svg
    migration-type: SEQUELIZE
    database-type: POSTGRESQL
    database-version: '18'
    github-token: ${{ secrets.GITHUB_TOKEN }}

The action uploads the directory, waits for the diagram and opens a pull request with the SVG. See the action reference.

Good to know

  • The SequelizeMeta table is left out of the diagram.
  • On SQLite a single-column integer key becomes INTEGER PRIMARY KEY and is reported as nullable; that is SQLite, not the diagram.
  • A drawing may take up to 120 seconds; a job that waits in the queue longer than 10 minutes fails rather than draws. Uploads of up to 100 MB and 2000 files are accepted.
From the blog

Reading about Sequelize and migrations

Draw your Sequelize schema now

Upload the migration directory, get an SVG back. Free while we build it.