mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05: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
2 changed files with 8 additions and 2 deletions
|
@ -375,7 +375,8 @@ function createAddColumnMigration(table, column, columnDefinition) {
|
||||||
column,
|
column,
|
||||||
dbIsInCorrectState: hasColumn => hasColumn === false,
|
dbIsInCorrectState: hasColumn => hasColumn === false,
|
||||||
operation: commands.dropColumn,
|
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) {
|
return transaction.schema.table(tableName, function (table) {
|
||||||
table.dropColumn(column);
|
table.dropColumn(column);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue