ohjongin / sequelize-validate-schema

This plugin is simple feature. Function validateSchemas will check defined sequelize models and db-schema. If check is ng, promise returned by validateSchemas will be rejected.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sequelize-validate-schema

npm version CircleCI codecov

sequelize-validate-schema is plugin of sequelize;

Purpose

This plugin is simple feature. Function validateSchemas will check defined sequelize models and db-schema. If check is ng, promise returned by validateSchemas will be rejected.

Use Case

If you are worried that dirty migration. For example migration-scripts are correct sql, but migrated db is may not same model-schema. ex) model string field length is 255, but schema string field length 64.

Installation

npm install -save sequelize-validation-schema

Usage

var validateSchemas = require("sequelize-validation-schema").validateSchemas;


// initialize Sequelize
var sequelize = new Sequelize(process.env.DATABASE_URL);


sequelize.sync({force: process.env.NODE_ENV !== 'production'})
    .then(()=>{
      // validateSchemas is Promise based function
      return validateSchemas(sequelize, {logging: false})
        .then(function(){
          console.log("your schema is clean");
        })
        .error(function(error){
          console.log("your schema is wrong between model and db.", error);
        });
    })

TODO for Release v1

  • support dialect MySQL
  • support dialect SQLite
  • support DataTypes
  • check defined at model, but not exists in db-schema
  • refactoring

About

This plugin is simple feature. Function validateSchemas will check defined sequelize models and db-schema. If check is ng, promise returned by validateSchemas will be rejected.

License:MIT License


Languages

Language:TypeScript 98.8%Language:Dockerfile 1.2%