0.0.4 • Published 8 months ago

sequelize-mtm-cli v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Sequelize Migration Generator Helper

supports createTable, removeTable, addColumn, modifyColumn, removeColumn migrations.

Installation

Using npm:

npm i sequelize-mtm-cli --save-dev

Getting started

  • Create sequelize init script

    create a file that exports a function that return a promise with the updated sequelize object.

    // ./models/init.js
    const {Sequelize} = require('sequelize');
    
    module.exports = async () => {
      const sequelize = new Sequelize({
        dialect: 'sqlite',
        storage: './db.sqlite',
      });
    
      await sequelize.authenticate();
    
      return sequelize;
    };
  • Use sequelize-mtm-cli cli

    add make:migration script to your package.json

    {
      ...
      "scripts": {
        ...
        "make:migrations": "sequelize-mtm-cli -s ./models/init.js -m ./db/migrations",
        "run:migrations": "sequelize-cli db:migrate"
      }
    }
    Options:
    -V, --version                 output the version number
    -s, --sequelize-path <path>   Path for init sequelize, models and associations (default: "./models/index.js")
    -m, --migrations-path <path>  Folder to save the generated migrations (default: "./migrations")

Typescripts

Currently sequelize-path can only handle js file. So it recomended to compile your ts files and run the cli after.

example:

{
    ...
    "scripts": {
        ...
        "compile": "tsc",
        "premake:migrations": "npm compile",
        "make:migrations": "sequelize-mtm-cli -s ./dist/db/models/init.js -m ./db/migrations",
        "run:migrations": "sequelize-cli db:migrate"
    }
}

OR with a model file provided:

{
    ...
    "scripts": {
        ...
        "compile": "tsc",
        "premake:migrations": "npm compile",
        "make:migrations": "sequelize-mtm-cli -s ./dist/db/models/init.js -m ./db/migrations/model.json",
        "run:migrations": "sequelize-cli db:migrate"
    }
}
0.0.4

8 months ago

0.0.3

8 months ago

0.0.2

8 months ago