Skip to content

Commit 1fcb2a0

Browse files
committed
Enable more clash codes
1 parent 6f1217a commit 1fcb2a0

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/migrate.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ export async function runMigration(
9797
const error = coerceError(rawError);
9898
await event.client.query("rollback");
9999
await hooks.process("migrationError", { ...event, error });
100-
if (!migrationInsertComplete && error.code === "23505") {
100+
if (
101+
!migrationInsertComplete &&
102+
CLASH_CODES.includes(error.code as string)
103+
) {
101104
// Someone else did this migration! Success!
102105
logger.debug(
103106
`Some other worker has performed migration ${migrationFile}; continuing.`,
@@ -146,13 +149,13 @@ select current_setting('server_version_num') as server_version_num,
146149
break;
147150
} catch (rawE) {
148151
const e = coerceError(rawE);
149-
if (attempts === 0 && (e.code === "42P01" || e.code === "42703")) {
152+
if (attempts === 0 && NX_CODES.includes(e.code as string)) {
150153
try {
151154
await installSchema(compiledSharedOptions, event);
152155
break;
153156
} catch (rawE2) {
154157
const e2 = coerceError(rawE2);
155-
if (e2.code === "23505") {
158+
if (CLASH_CODES.includes(e2.code as string)) {
156159
// Another instance installed this concurrently? Go around again.
157160
} else {
158161
throw e2;
@@ -208,3 +211,8 @@ select current_setting('server_version_num') as server_version_num,
208211
await hooks.process("postmigrate", event);
209212
});
210213
}
214+
215+
/** Doesn't exist */
216+
const NX_CODES = ["42P01", "42703"];
217+
/** Someone else created */
218+
const CLASH_CODES = ["23505", "42P06", "42P07", "42710"];

0 commit comments

Comments
 (0)