Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3249415
D4153.id13226.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D4153.id13226.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D4153: [keyserver] Extract DB version functions to separate file
Attached
Detach File
Event Timeline
Log In to Comment