mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Refactored createTable migration utility
refs https://github.com/TryGhost/Ghost/issues/12567 - The method was using unneeded lodash dependency and was too complex for what it was doing - Reshuffled internal code to use native JS filter/forEach iterators
This commit is contained in:
parent
6b61bcf123
commit
4b74230624
1 changed files with 9 additions and 24 deletions
|
@ -103,31 +103,16 @@ function createTable(table, transaction, tableSpec = schema[table]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (transaction || db.knex).schema.createTable(table, function (t) {
|
return (transaction || db.knex).schema.createTable(table, function (t) {
|
||||||
let tableIndexes = [];
|
Object.keys(tableSpec)
|
||||||
let tableUniqueConstraints = [];
|
.filter(column => !(column.startsWith('@@')))
|
||||||
|
.forEach(column => addTableColumn(table, t, column, tableSpec[column]));
|
||||||
|
|
||||||
const columnKeys = _.keys(tableSpec);
|
if (tableSpec['@@INDEXES@@']) {
|
||||||
_.each(columnKeys, function (column) {
|
tableSpec['@@INDEXES@@'].forEach(index => t.index(index));
|
||||||
if (column === '@@INDEXES@@') {
|
|
||||||
tableIndexes = tableSpec['@@INDEXES@@'];
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
if (tableSpec['@@UNIQUE_CONSTRAINTS@@']) {
|
||||||
if (column === '@@UNIQUE_CONSTRAINTS@@') {
|
tableSpec['@@UNIQUE_CONSTRAINTS@@'].forEach(unique => t.unique(unique));
|
||||||
tableUniqueConstraints = tableSpec['@@UNIQUE_CONSTRAINTS@@'];
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return addTableColumn(table, t, column, tableSpec[column]);
|
|
||||||
});
|
|
||||||
|
|
||||||
_.each(tableIndexes, function (index) {
|
|
||||||
t.index(index);
|
|
||||||
});
|
|
||||||
|
|
||||||
_.each(tableUniqueConstraints, function (unique) {
|
|
||||||
t.unique(unique);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue