1.0.0 • Published 3 years ago

sequelize-typescript-mysql-migration v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

sequelize-typescript-model-migration

Auto-generate migration script from sequelize-typescript model.

This refers to GitHub - kimjbstar/sequelize-typescript-migration.

This scans models and its decorators by sequelize-typescript to find changes, and generates migration code with this changes so don't need to write up, down function manually. this is like "makemigration" in django framework.

After generate successfully, you can use "migrate" in Sequelize Sequelize Migration Manual.

This also resolve some issues which left for sometimes in the sequelize-typescript-migration, such as:

  1. @Index not working
  2. [SequelizeDatabaseError]: relation "sequelizemeta" does not exist
  3. Table options underscore:true doesn not work with Index fields.

And also add some enhancement, such as:

  1. Upgrade version of sequelize-typescript depedencies to 2.x and version of sequelize to 6.x
  2. Create snapshot files to store latest state instead of adding to SequelizeMetaMigration table.
  3. Add prettier options to format the generated migration files.

Installation

npm i -D sequelize-typescript-model-migration

Usage Example

import { Sequelize } from "sequelize-typescript";
import { generateMigration } from "sequelize-typescript-model-migration";
import prettierOptions from '.prettierrc.json';

const sequelize: Sequelize = new Sequelize(database, username, password,
    {
      // other options
      ...
      //load sequelize-typescript models into sequelize
      models: [path.join(__dirname, '/models')]
    }
});

await generateMigration(sequelize, {
    outDir: path.join(__dirname, "../migrations"),
    snapshotDir: path.join(__dirname, "../snapshots")
    migrationName: "my-migration-file",
    prettierOptions,
});

Please refer this example for more information.

Documentation

not ready yet.