mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
MongoDB Transactions (#12335)
* add run-rs to dependencies
* wip: add replica set to api unit github action
* wip: add replica set to api unit github action
* wip: fix gh actions mongodb replica set setting
* usa replica set for integration tests
* add correct mongodb version matrix for integration tests
* use different db connection on gh actions
* Revert "use different db connection on gh actions"
This reverts commit aa8db759d3.
* add example transaction
* add mongo script to package.json
* abstract mongodb utils, connect using hostname on windows
* npm scripts: mongo -> mongo:dev
* add setup script for run-rs on windows
* gh actions: run in test environment
* remove test files
* better error handling, use cross-spawn to avoid issues on windows
* fix lint
This commit is contained in:
37
website/server/libs/mongodb.js
Normal file
37
website/server/libs/mongodb.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import os from 'os';
|
||||
import nconf from 'nconf';
|
||||
|
||||
const IS_PROD = nconf.get('IS_PROD');
|
||||
|
||||
// Due to some limitation in the `run-rs` module that is used in development
|
||||
// In order to connect to the database on Windows the hostname must be used
|
||||
// instead of `localhost`.
|
||||
// See https://github.com/vkarpov15/run-rs#notes-on-connecting
|
||||
// for more info.
|
||||
//
|
||||
// This function takes in a connection string and in case it's being run on Windows
|
||||
// it replaces `localhost` with the hostname.
|
||||
export function getDevelopmentConnectionUrl (originalConnectionUrl) {
|
||||
const isWindows = os.platform() === 'win32';
|
||||
|
||||
if (isWindows) {
|
||||
const hostname = os.hostname();
|
||||
return originalConnectionUrl.replace('mongodb://localhost', `mongodb://${hostname}`);
|
||||
}
|
||||
|
||||
return originalConnectionUrl;
|
||||
}
|
||||
|
||||
export function getDefaultConnectionOptions () {
|
||||
const commonOptions = {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
};
|
||||
|
||||
return !IS_PROD ? commonOptions : {
|
||||
// See https://mongoosejs.com/docs/connections.html#keepAlive
|
||||
keepAlive: true,
|
||||
keepAliveInitialDelay: 300000,
|
||||
...commonOptions,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user