Added extra handling for errors when adding foreign key

- this section of code handles the errors that arise when we add a
  foreign key to a table
- locally, I get different errors than the one listed - `ER_FK_DUP_KEY`
  and `ER_FK_DUP_NAME`
- I've been trying to find a good source for what each code is but it
  looks highly likely to be differences in DB engines
- we should probably handle these errors anyway because we don't want
  migrations to error out
This commit is contained in:
Daniel Lockyer 2022-03-02 12:37:39 +01:00
parent 1cc38733ba
commit 11f64e91c0
No known key found for this signature in database
GPG Key ID: D21186F0B47295AD

View File

@ -197,7 +197,7 @@ async function addForeign({fromTable, fromColumn, toTable, toColumn, cascadeDele
}
}
} catch (err) {
if (err.code === 'ER_DUP_KEY') {
if (err.code === 'ER_DUP_KEY' || err.code === 'ER_FK_DUP_KEY' || err.code === 'ER_FK_DUP_NAME') {
logging.warn(`Skipped adding foreign key from ${fromTable}.${fromColumn} to ${toTable}.${toColumn} - foreign key already exists`);
return;
}