Page MenuHomePhabricator

D4153.id13226.diff
No OneTemporary

D4153.id13226.diff

diff --git a/keyserver/src/database/db-version.js b/keyserver/src/database/db-version.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/database/db-version.js
@@ -0,0 +1,31 @@
+// @flow
+
+import type { QueryResults } from 'mysql';
+
+import { dbQuery, SQL } from './database';
+
+async function fetchDBVersion(): Promise<number> {
+ const versionQuery = SQL`
+ SELECT data
+ FROM metadata
+ WHERE name = 'db_version';
+ `;
+ const [[versionResult]] = await dbQuery(versionQuery);
+ if (!versionResult) {
+ return -1;
+ }
+ return versionResult.data;
+}
+
+async function updateDBVersion(dbVersion: number): Promise<QueryResults> {
+ const updateQuery = SQL`
+ INSERT INTO metadata (name, data)
+ VALUES ('db_version', ${dbVersion})
+ ON DUPLICATE KEY
+ UPDATE
+ data = ${dbVersion};
+ `;
+ return dbQuery(updateQuery);
+}
+
+export { fetchDBVersion, updateDBVersion };
diff --git a/keyserver/src/database/migrations.js b/keyserver/src/database/migrations.js
--- a/keyserver/src/database/migrations.js
+++ b/keyserver/src/database/migrations.js
@@ -5,6 +5,7 @@
import { getMessageForException } from 'lib/utils/errors';
import { dbQuery, SQL } from './database';
+import { fetchDBVersion, updateDBVersion } from './db-version';
import { migrations } from './migration-config';
import { setupDB } from './setup-db';
@@ -53,30 +54,6 @@
}
}
-async function fetchDBVersion(): Promise<number> {
- const versionQuery = SQL`
- SELECT data
- FROM metadata
- WHERE name = 'db_version';
- `;
- const [[versionResult]] = await dbQuery(versionQuery);
- if (!versionResult) {
- return -1;
- }
- return versionResult.data;
-}
-
-async function updateDBVersion(dbVersion: number): Promise<QueryResults> {
- const updateQuery = SQL`
- INSERT INTO metadata (name, data)
- VALUES ('db_version', ${dbVersion})
- ON DUPLICATE KEY
- UPDATE
- data = ${dbVersion};
- `;
- return dbQuery(updateQuery);
-}
-
async function startTransaction(): Promise<QueryResults> {
const beginTxnQuery = SQL`
START TRANSACTION;

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 16, 2:32 PM (21 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2498057
Default Alt Text
D4153.id13226.diff (2 KB)

Event Timeline