mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 14:03:48 +03:00
Fixed migration util dropping foreign keys before columns
- if we add a column with a foreign key reference, the `down` migration will try to remove that column - you can't remove a column without deleting the foreign key reference first - our migration utils didn't take that into account and there's nothing in Knex to do this for us - this commit deletes the foreign key before removing the column if we have one referenced in the column spec - also updates the code to pass the column spec into the util
This commit is contained in:
parent
08701aa7a8
commit
eddb77e204
@ -375,7 +375,8 @@ function createAddColumnMigration(table, column, columnDefinition) {
|
||||
column,
|
||||
dbIsInCorrectState: hasColumn => hasColumn === false,
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
operationVerb: 'Removing',
|
||||
columnDefinition
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@ -65,7 +65,12 @@ function addColumn(tableName, column, transaction = db.knex, columnSpec) {
|
||||
});
|
||||
}
|
||||
|
||||
function dropColumn(tableName, column, transaction = db.knex) {
|
||||
async function dropColumn(tableName, column, transaction = db.knex, columnSpec = {}) {
|
||||
if (Object.prototype.hasOwnProperty.call(columnSpec, 'references')) {
|
||||
const [toTable, toColumn] = columnSpec.references.split('.');
|
||||
await dropForeign({fromTable: tableName, fromColumn: column, toTable, toColumn, transaction});
|
||||
}
|
||||
|
||||
return transaction.schema.table(tableName, function (table) {
|
||||
table.dropColumn(column);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user