Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Commit ce506c3

Browse files
authored
Adding support postgresql ARRAY support
1 parent 226eb25 commit ce506c3

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

lib/migrate.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ const reverseSequelizeColType = function(col, prefix = 'Sequelize.')
9999
return prefix + 'GEOGRAPHY';
100100

101101
case DataTypes.ARRAY.key:
102+
const _type = attrObj.toString();
103+
let arrayType;
104+
if(_type === 'INTEGER[]' || _type === 'STRING[]') {
105+
arrayType = prefix + _type.replace('[]', '');
106+
} else {
107+
arrayType = (col.seqType === 'Sequelize.ARRAY(Sequelize.INTEGER)') ? prefix + 'INTEGER' : prefix + 'STRING';
108+
}
109+
return prefix + `ARRAY(${arrayType})`;
110+
102111
case DataTypes.RANGE.key:
103112
console.warn(attrName + ' type not supported, you should make it by')
104113
return prefix + attrObj.toSql()
@@ -204,12 +213,24 @@ const reverseModels = function(sequelize, models)
204213
delete attributes[column][property];
205214
}
206215

207-
if(typeof attributes[column]['type'] === 'undefined')
216+
if(typeof attributes[column]['type'] === 'undefined')
208217
{
218+
if(!attributes[column]['seqType'])
219+
{
209220
log(`[Not supported] Skip column with undefined type ${model}:${column}`);
210221
delete attributes[column];
211222
continue;
223+
} else {
224+
if(!['Sequelize.ARRAY(Sequelize.INTEGER)', 'Sequelize.ARRAY(Sequelize.STRING)'].includes(attributes[column]['seqType'])) {
225+
delete attributes[column];
226+
continue;
227+
}
228+
attributes[column]['type'] = {
229+
key: Sequelize.ARRAY.key
230+
}
231+
}
212232
}
233+
213234
let seqType = reverseSequelizeColType(attributes[column]);
214235

215236
// NO virtual types in migration
@@ -787,4 +808,3 @@ const executeMigration = function(queryInterface, filename, pos, cb)
787808
};
788809

789810
module.exports = { writeMigration, getMigration, sortActions, parseDifference, reverseModels, executeMigration };
790-

0 commit comments

Comments
 (0)