mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-06-02 11:00:17 +00:00
* 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 aa8db759d380ba58ac90304c786b3eba5004b1bd. * 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
26 lines
850 B
JavaScript
26 lines
850 B
JavaScript
import nconf from 'nconf';
|
|
import mongoose from 'mongoose';
|
|
import logger from './logger';
|
|
import {
|
|
getDevelopmentConnectionUrl,
|
|
getDefaultConnectionOptions,
|
|
} from './mongodb';
|
|
|
|
const IS_PROD = nconf.get('IS_PROD');
|
|
const MAINTENANCE_MODE = nconf.get('MAINTENANCE_MODE');
|
|
const POOL_SIZE = nconf.get('MONGODB_POOL_SIZE');
|
|
|
|
// Do not connect to MongoDB when in maintenance mode
|
|
if (MAINTENANCE_MODE !== 'true') {
|
|
const mongooseOptions = getDefaultConnectionOptions();
|
|
|
|
if (POOL_SIZE) mongooseOptions.poolSize = Number(POOL_SIZE);
|
|
|
|
const DB_URI = nconf.get('IS_TEST') ? nconf.get('TEST_DB_URI') : nconf.get('NODE_DB_URI');
|
|
const connectionUrl = IS_PROD ? DB_URI : getDevelopmentConnectionUrl(DB_URI);
|
|
|
|
mongoose.connect(connectionUrl, mongooseOptions, err => {
|
|
if (err) throw err;
|
|
logger.info('Connected with Mongoose.');
|
|
});
|
|
}
|