flexxnn / sequelize-auto-migrations

Migration generator && runner for sequelize
MIT License
259 stars 166 forks source link

Postgres ARRAY types not generated correctly #1

Open dylanlingelbach opened 7 years ago

dylanlingelbach commented 7 years ago

We use ARRAY types and are testing out using sequelize-auto-migrations. ARRAY types don't generate correctly.

Minimal repro below:

  1. Define a new schema that uses an ARRAY type
    
    'use strict';

const Sequelize = require('sequelize');

module.exports = function (sequelize) { const Test = sequelize.define('test', { array: { type: Sequelize.ARRAY(Sequelize.TEXT), allowNull: false, defaultValue: [] } }, { });

return Test;

};

2. Generate the migration

**Expected:** Syntactically valid migration generated

'use strict';

var Sequelize = require('sequelize');

/**

var info = { "revision": 2, "name": "testSchema", "created": "2017-08-02T16:42:10.042Z", "comment": "" };

var migrationCommands = [{ fn: "createTable", params: [ "tests", { "id": { "type": Sequelize.INTEGER, "autoIncrement": true, "primaryKey": true, "allowNull": false }, "array": { "type": Sequelize.ARRAY(Sequelize.TEXT), // This line is wrong in the generated migration "defaultValue": [], "allowNull": false }, "createdAt": { "type": Sequelize.DATE, "allowNull": false }, "updatedAt": { "type": Sequelize.DATE, "allowNull": false } }, {} ] } ];

module.exports = { pos: 0, up: function(queryInterface, Sequelize) { var index = this.pos; return new Promise(function(resolve, reject) { function next() { if (index < migrationCommands.length) { let command = migrationCommands[index]; console.log("[#"+index+"] execute: " + command.fn); index++; queryInterface[command.fn].apply(queryInterface, command.params).then(next, reject); } else resolve(); } next(); }); }, info: info };


**Actual:**

'use strict';

var Sequelize = require('sequelize');

/**

var info = { "revision": 2, "name": "testSchema", "created": "2017-08-02T16:42:10.042Z", "comment": "" };

var migrationCommands = [{ fn: "createTable", params: [ "tests", { "id": { "type": Sequelize.INTEGER, "autoIncrement": true, "primaryKey": true, "allowNull": false }, "array": { "type": TEXT[], // This syntax is incorrect "defaultValue": [], "allowNull": false }, "createdAt": { "type": Sequelize.DATE, "allowNull": false }, "updatedAt": { "type": Sequelize.DATE, "allowNull": false } }, {} ] } ];

module.exports = { pos: 0, up: function(queryInterface, Sequelize) { var index = this.pos; return new Promise(function(resolve, reject) { function next() { if (index < migrationCommands.length) { let command = migrationCommands[index]; console.log("[#"+index+"] execute: " + command.fn); index++; queryInterface[command.fn].apply(queryInterface, command.params).then(next, reject); } else resolve(); } next(); }); }, info: info };



Thank you so much for this package. It's been a big help so far.
apapacy commented 5 years ago

This is a great library. But a bug with the type of ARRAY does not allow it to use with PostgreSQL. Are there any plans to fix this?

but1head commented 5 years ago

Up