Skip to content

Commit 5def572

Browse files
committed
feat: allow continuing on failures when deleting old DBs
1 parent c79f989 commit 5def572

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

import.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const importGtfsAtomically = async (cfg) => {
4141
tmpDir,
4242
gtfstidyBeforeImport,
4343
determineDbsToRetain,
44+
continueOnFailureDeletingOldDb,
4445
gtfsPostprocessingDPath,
4546
} = {
4647
logger: console,
@@ -64,6 +65,7 @@ const importGtfsAtomically = async (cfg) => {
6465
? [prevImport, ...latestTwo.slice(-1)]
6566
: latestTwo
6667
},
68+
continueOnFailureDeletingOldDb: process.env.GTFS_IMPORTED_CONTINUE_ON_FAILURE_DELETING_OLD_DB === 'true',
6769
gtfsPostprocessingDPath: null,
6870
...cfg,
6971
}
@@ -164,8 +166,19 @@ const importGtfsAtomically = async (cfg) => {
164166
}
165167
logger.info(`dropping database "${oldDb.name}" containing an older or unfinished import`)
166168
// todo: `WITH (FORCE)`? – https://stackoverflow.com/a/68982312/1072129
167-
await dbMngmtClient.query(pgFormat('DROP DATABASE %I', oldDb.name))
168-
result.deletedDatabases.push(oldDb)
169+
try {
170+
await dbMngmtClient.query(pgFormat('DROP DATABASE %I', oldDb.name))
171+
result.deletedDatabases.push(oldDb)
172+
} catch (err) {
173+
if (continueOnFailureDeletingOldDb) {
174+
logger.warn({
175+
error: err,
176+
dbName: oldDb.name,
177+
}, `failed to delete old database "${oldDb.name}"`)
178+
} else {
179+
throw err
180+
}
181+
}
169182
}
170183
}
171184

0 commit comments

Comments
 (0)