Skip to content

Commit

Permalink
[keyserver] Extract database error codes
Browse files Browse the repository at this point in the history
Summary:
Keep all the db error codes in a single place.

Depends on D8494

Test Plan: Flow. Searched for all the `errno` usages to find all the codes we might use.

Reviewers: kamil, inka

Reviewed By: inka

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D8608
  • Loading branch information
palys-swm committed Jul 28, 2023
1 parent 89ddf78 commit 9143e12
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions keyserver/src/database/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { getScriptContext } from '../scripts/script-context.js';
const SQLStatement: SQLStatementType = SQL.SQLStatement;

const MYSQL_DUPLICATE_ENTRY_FOR_KEY_ERROR_CODE = 1062;
const MYSQL_TABLE_DOESNT_EXIST_ERROR_CODE = 1146;
const MYSQL_DEADLOCK_ERROR_CODE = 1213;

let migrationConnection;
async function getMigrationConnection() {
Expand Down Expand Up @@ -107,8 +109,6 @@ const fakeResult: QueryResults = (() => {
return result;
})();

const MYSQL_DEADLOCK_ERROR_CODE = 1213;

type ConnectionContext = {
+migrationsActive?: boolean,
};
Expand Down Expand Up @@ -206,4 +206,5 @@ export {
dbQuery,
rawSQL,
MYSQL_DUPLICATE_ENTRY_FOR_KEY_ERROR_CODE,
MYSQL_TABLE_DOESNT_EXIST_ERROR_CODE,
};
9 changes: 6 additions & 3 deletions keyserver/src/database/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { isDev } from 'lib/utils/dev-utils.js';
import { getMessageForException } from 'lib/utils/errors.js';
import sleep from 'lib/utils/sleep.js';

import { dbQuery, SQL, setConnectionContext } from './database.js';
import {
dbQuery,
SQL,
setConnectionContext,
MYSQL_TABLE_DOESNT_EXIST_ERROR_CODE,
} from './database.js';
import { fetchDBVersion, updateDBVersion } from './db-version.js';
import { migrations } from './migration-config.js';
import { setupDB } from './setup-db.js';
Expand Down Expand Up @@ -50,8 +55,6 @@ async function migrate(): Promise<boolean> {
return true;
}

const MYSQL_TABLE_DOESNT_EXIST_ERROR_CODE = 1146;

async function setUpDBAndReturnVersion(): Promise<number> {
try {
return await fetchDBVersion();
Expand Down

0 comments on commit 9143e12

Please sign in to comment.