sequelize-typescript-mysql-migration
v1.0.0
Published
Migration tool for sequelize-typescript with MySQL
Downloads
360
Maintainers
Readme
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:
- @Index not working
- [SequelizeDatabaseError]: relation "sequelizemeta" does not exist
- Table options
underscore:true
doesn not work with Index fields.
And also add some enhancement, such as:
- Upgrade version of sequelize-typescript depedencies to 2.x and version of sequelize to 6.x
- Create snapshot files to store latest state instead of adding to SequelizeMetaMigration table.
- 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.