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

Commit 30aee8d

Browse files
authored
Update migrate.js
Update to support index additions/removals to existing columns
1 parent 226eb25 commit 30aee8d

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

lib/migrate.js

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ const parseIndex = function(idx)
142142

143143
let options = { };
144144

145-
if (idx.name)
146-
options.indexName = idx.name; // The name of the index. Default is __
145+
if (idx.name)
146+
options.name = options.indexName = idx.name; // The name of the index. Default is __
147147

148148
// @todo: UNIQUE|FULLTEXT|SPATIAL
149-
if (idx.unique)
150-
options.indicesType = 'UNIQUE';
151-
149+
if (idx.unique)
150+
options.type = options.indicesType = 'UNIQUE';
151+
152152
if (idx.method)
153153
options.indexType = idx.type; // Set a type for the index, e.g. BTREE. See the documentation of the used dialect
154154

@@ -461,6 +461,42 @@ const parseDifference = function(previousState, currentState)
461461
depends: depends
462462
});
463463
}
464+
465+
// updated index
466+
// only support updating and dropping indexes
467+
if (df.path[1] === 'indexes')
468+
{
469+
let tableName = df.path[0];
470+
let keys = Object.keys(df.rhs)
471+
472+
for (let k in keys) {
473+
let key = keys[k]
474+
let index = _.clone(df.rhs[key]);
475+
actions.push({
476+
actionType: 'addIndex',
477+
tableName: tableName,
478+
fields: df.rhs[key].fields,
479+
options: df.rhs[key].options,
480+
depends: [ tableName ]
481+
});
482+
break;
483+
}
484+
485+
keys = Object.keys(df.lhs)
486+
for (let k in keys) {
487+
let key = keys[k]
488+
let index = _.clone(df.lhs[key]);
489+
actions.push({
490+
actionType: 'removeIndex',
491+
tableName: tableName,
492+
fields: df.lhs[key].fields,
493+
options: df.lhs[key].options,
494+
depends: [ tableName ]
495+
});
496+
break;
497+
}
498+
}
499+
464500
}
465501
break;
466502

0 commit comments

Comments
 (0)