Giter Site home page Giter Site logo

sequelize-auto-migrations-ng's Introduction

NPM

sequelize-auto-migrations-ng

Migration generator for sequelize.

This package provides one tool:

  • makemigration - tool for create new migrations

Install

npm install sequelize-auto-migrations-ng

Usage

  • Init sequelize, with sequelize-cli, using sequelize init
  • Create your models
  • Create initial migration - run:

node ./node_modules/sequelize-auto-migrations/bin/makemigration --name <migration name>

  • Change models and run it again, the migration file will be modified, it won't create a new one until you actually execute the migration.

    You can change this behavior using -k option and a different name for the migration.

  • To preview new migration, without writing any changes, you can run:

node ./node_modules/sequelize-auto-migrations/bin/makemigration --preview

makemigration tool creates a table, SequelizeMetaMigrations in your database, that is used to calculate difference to the next migration. Do not remove it!

Executing migrations

  • Use standard sequelize-cli sequelize db:migrate
  • To start from a revision, use --from <name>

Reverting migrations

  • Use standard sequelize-cli sequelize db:migrate:undo

For more information, use makemigration --help, sequelize --help db:migrate

TODO:

  • Migration action sorting procedure need some fixes. When many foreign keys in tables, there is a bug with action order. For now, please check it manually (--preview option)
  • Need to check (and maybe fix) field types: BLOB, RANGE, GEOMETRY, GEOGRAPHY
  • This module has been tested with postgresql (I use it with my projects). Test with mysql and sqlite.

Credits

This is a fork from https://github.com/flexxnn/sequelize-auto-migrations

sequelize-auto-migrations-ng's People

Contributors

flexxnn avatar jihokoo avatar manuelvillar avatar obecny avatar thalpha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sequelize-auto-migrations-ng's Issues

Crashes on MS SQL Server

It is caused by sequelize/sequelize#8761. I don't know what should be done - waiting for sequelize to fix that, changing your project to avoid JSON data type usage, etc. But let it be here so this information can be found in advance.

The error is:

{ SequelizeDatabaseError: Column, parameter, or variable #3: Cannot find data type JSON.
    at Query.formatError (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\sequelize\lib\dialects\mssql\query.js:315:12)
    at Request.connection.lib.Request [as userCallback] (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\sequelize\lib\dialects\mssql\query.js:107:25)
    at Request._this.callback (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\request.js:60:27)
    at Connection.endOfMessageMarkerReceived (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\connection.js:1922:20)
    at Connection.dispatchEvent (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\connection.js:1004:38)
    at Parser.<anonymous> (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\connection.js:805:18)
    at emitOne (events.js:116:13)
    at Parser.emit (events.js:211:7)
    at Parser.<anonymous> (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\token-stream-parser.js:54:15)
    at emitOne (events.js:116:13)
    at Parser.emit (events.js:211:7)
    at addChunk (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_readable.js:291:12)
    at readableAddChunk (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_readable.js:278:11)
    at Parser.Readable.push (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_readable.js:245:10)
    at Parser.Transform.push (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_transform.js:148:32)
    at Parser.afterTransform (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_transform.js:91:10)
    at Parser._transform (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:69:9)
    at Parser.Transform._read (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_transform.js:184:10)
    at Parser.Transform._write (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_transform.js:172:83)
    at doWrite (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_writable.js:428:64)
    at writeOrBuffer (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_writable.js:417:5)
    at Parser.Writable.write (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_writable.js:334:11)
  name: 'SequelizeDatabaseError',
  parent: 
   { RequestError: Column, parameter, or variable #3: Cannot find data type JSON.
    at RequestError (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\errors.js:34:12)
    at Parser.<anonymous> (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\connection.js:614:36)
    at emitOne (events.js:116:13)
    at Parser.emit (events.js:211:7)
    at Parser.<anonymous> (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\token-stream-parser.js:54:15)
    at emitOne (events.js:116:13)
    at Parser.emit (events.js:211:7)
    at addChunk (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_readable.js:291:12)
    at readableAddChunk (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_readable.js:278:11)
    at Parser.Readable.push (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_readable.js:245:10)
    at Parser.Transform.push (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_transform.js:148:32)
    at doneParsing (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:110:18)
    at C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\infoerror-token-parser.js:46:5
    at C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\infoerror-token-parser.js:13:19
    at C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:247:9
    at Parser.awaitData (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:144:9)
    at Parser.readUInt32LE (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:244:12)
    at C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\infoerror-token-parser.js:12:90
    at C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:446:11
    at C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:433:9
    at Parser.awaitData (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:144:9)
    at Parser.readBuffer (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:430:12)
     message: 'Column, parameter, or variable #3: Cannot find data type JSON.',
     code: 'EREQUEST',
     number: 2715,
     state: 6,
     class: 16,
     serverName: 'ZARUBKIN-NOTE',
     procName: '',
     lineNumber: 1,
     sql: 'IF OBJECT_ID(\'[SequelizeMetaMigrations]\', \'U\') IS NULL CREATE TABLE [SequelizeMetaMigrations] ([revision] INTEGER NOT NULL UNIQUE , [name] NVARCHAR(255) NOT NULL, [state] JSON NOT NULL, PRIMARY KEY ([revision]));' },
  original: 
   { RequestError: Column, parameter, or variable #3: Cannot find data type JSON.
    at RequestError (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\errors.js:34:12)
    at Parser.<anonymous> (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\connection.js:614:36)
    at emitOne (events.js:116:13)
    at Parser.emit (events.js:211:7)
    at Parser.<anonymous> (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\token-stream-parser.js:54:15)
    at emitOne (events.js:116:13)
    at Parser.emit (events.js:211:7)
    at addChunk (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_readable.js:291:12)
    at readableAddChunk (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_readable.js:278:11)
    at Parser.Readable.push (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_readable.js:245:10)
    at Parser.Transform.push (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\readable-stream\lib\_stream_transform.js:148:32)
    at doneParsing (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:110:18)
    at C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\infoerror-token-parser.js:46:5
    at C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\infoerror-token-parser.js:13:19
    at C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:247:9
    at Parser.awaitData (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:144:9)
    at Parser.readUInt32LE (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:244:12)
    at C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\infoerror-token-parser.js:12:90
    at C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:446:11
    at C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:433:9
    at Parser.awaitData (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:144:9)
    at Parser.readBuffer (C:\Users\Зарубкин\Documents\React Projects\uno\backend\node_modules\tedious\lib\token\stream-parser.js:430:12)
     message: 'Column, parameter, or variable #3: Cannot find data type JSON.',
     code: 'EREQUEST',
     number: 2715,
     state: 6,
     class: 16,
     serverName: 'ZARUBKIN-NOTE',
     procName: '',
     lineNumber: 1,
     sql: 'IF OBJECT_ID(\'[SequelizeMetaMigrations]\', \'U\') IS NULL CREATE TABLE [SequelizeMetaMigrations] ([revision] INTEGER NOT NULL UNIQUE , [name] NVARCHAR(255) NOT NULL, [state] JSON NOT NULL, PRIMARY KEY ([revision]));' },
  sql: 'IF OBJECT_ID(\'[SequelizeMetaMigrations]\', \'U\') IS NULL CREATE TABLE [SequelizeMetaMigrations] ([revision] INTEGER NOT NULL UNIQUE , [name] NVARCHAR(255) NOT NULL, [state] JSON NOT NULL, PRIMARY KEY ([revision]));' }

INTEGER type of SequelizeMetaMigrations revision column cannot accept revision id

I guess I'm doing something wrong, but it seems like the migration datetime identifier is too big for the integer column assigned to it in the meta migrations table in postgres 10...

original: error: value "20200107231058" is out of range for type integer

According to postgres docs, integer type is -2147483648 to +2147483647

# select 20200107231058 > 2147483647;

 ?column? 
----------
 t
(1 row)

From makemigrations.js, line 84

  queryInterface.createTable('SequelizeMetaMigrations', {
    revision: {
      type: Sequelize.INTEGER,
      allowNull: false,
      unique: true,
      primaryKey: true,
    },
    name: {
      type: Sequelize.STRING,
      allowNull: false,
    },
    state: {
      type: Sequelize.JSON,
      allowNull: false,
    },

Perhaps you would like a pull request to change the type of that column, or maybe there's a configuration that lets me change those identifiers to something smaller?

ERROR: Unexpected identifier at migration

I have created a "order.js" model, then a first migration using
$ node ./node_modules/sequelize-auto-migrations-ng/bin/makemigration --name=order

And launch migration using sequelize
$ sequelize db:migrate

Sequelize CLI [Node: 10.5.0, CLI: 4.0.0, ORM: 3.33.0]
Loaded configuration file "config/config.json".
Using environment "development".
(node:19721) DeprecationWarning: Using the automatically created return value from client.query as an event emitter is deprecated and will be removed in [email protected]. Please see the upgrade guide at https://node-postgres.com/guides/upgrading
== 00001-order: migrating =======

ERROR: Unexpected identifier

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.