sequelize-auto-migrations
sequelize-auto-migrations copied to clipboard
Postgres ARRAY types not generated correctly
We use ARRAY types and are testing out using sequelize-auto-migrations. ARRAY types don't generate correctly.
Minimal repro below:
- 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;
};
- Generate the migration
Expected: Syntactically valid migration generated
'use strict';
var Sequelize = require('sequelize');
/**
* Actions summary:
*
* createTable "tests", deps: []
*
**/
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');
/**
* Actions summary:
*
* createTable "tests", deps: []
*
**/
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.
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?
Up