Handle a couple more edge cases more gracefully.

This commit is contained in:
Sam Rose 2023-10-24 18:06:25 +01:00
parent a8ae16852c
commit 0f5c2cff00
No known key found for this signature in database
1 changed files with 23 additions and 1 deletions

View File

@ -30,7 +30,15 @@ export async function migrate(
table.schema[newColumn.name] = newColumn
table = await sdk.tables.saveTable(table)
await migrator.doMigration()
try {
await migrator.doMigration()
} catch (e) {
// If the migration fails then we need to roll back the table schema
// change.
delete table.schema[newColumn.name]
await sdk.tables.saveTable(table)
throw e
}
delete table.schema[oldColumn.name]
table = await sdk.tables.saveTable(table)
@ -133,6 +141,13 @@ class SingleUserColumnMigrator implements ColumnMigrator {
let userId = dbCore.getGlobalIDFromUserMetadataID(link.doc2.rowId)
let row = rowsById[link.doc1.rowId]
if (!row) {
// This can happen if the row has been deleted but the link hasn't,
// which was a state that was found during the initial testing of this
// feature. Not sure exactly what can cause it, but best to be safe.
continue
}
row[this.newColumn.name] = userId
}
@ -171,6 +186,13 @@ class MultiUserColumnMigrator implements ColumnMigrator {
let userId = dbCore.getGlobalIDFromUserMetadataID(link.doc2.rowId)
let row = rowsById[link.doc1.rowId]
if (!row) {
// This can happen if the row has been deleted but the link hasn't,
// which was a state that was found during the initial testing of this
// feature. Not sure exactly what can cause it, but best to be safe.
continue
}
if (!row[this.newColumn.name]) {
row[this.newColumn.name] = []
}