|
@@ -30,16 +30,6 @@ const READ_PREFERENCE_SECONDARY = Settings.mongo.hasSecondaries
|
|
|
? ReadPreference.secondary.mode
|
|
? ReadPreference.secondary.mode
|
|
|
: ReadPreference.secondaryPreferred.mode
|
|
: ReadPreference.secondaryPreferred.mode
|
|
|
|
|
|
|
|
-let setupDbPromise
|
|
|
|
|
-async function waitForDb() {
|
|
|
|
|
- if (!setupDbPromise) {
|
|
|
|
|
- setupDbPromise = setupDb()
|
|
|
|
|
- }
|
|
|
|
|
- await setupDbPromise
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-const db = {}
|
|
|
|
|
-
|
|
|
|
|
const mongoClient = new mongodb.MongoClient(
|
|
const mongoClient = new mongodb.MongoClient(
|
|
|
Settings.mongo.url,
|
|
Settings.mongo.url,
|
|
|
Settings.mongo.options
|
|
Settings.mongo.options
|
|
@@ -49,67 +39,60 @@ addConnectionDrainer('mongodb', async () => {
|
|
|
await mongoClient.close()
|
|
await mongoClient.close()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-async function setupDb() {
|
|
|
|
|
- const internalDb = mongoClient.db()
|
|
|
|
|
-
|
|
|
|
|
- db.contacts = internalDb.collection('contacts')
|
|
|
|
|
- db.deletedFiles = internalDb.collection('deletedFiles')
|
|
|
|
|
- db.deletedProjects = internalDb.collection('deletedProjects')
|
|
|
|
|
- db.deletedSubscriptions = internalDb.collection('deletedSubscriptions')
|
|
|
|
|
- db.deletedUsers = internalDb.collection('deletedUsers')
|
|
|
|
|
- db.dropboxEntities = internalDb.collection('dropboxEntities')
|
|
|
|
|
- db.dropboxProjects = internalDb.collection('dropboxProjects')
|
|
|
|
|
- db.docHistory = internalDb.collection('docHistory')
|
|
|
|
|
- db.docHistoryIndex = internalDb.collection('docHistoryIndex')
|
|
|
|
|
- db.docSnapshots = internalDb.collection('docSnapshots')
|
|
|
|
|
- db.docs = internalDb.collection('docs')
|
|
|
|
|
- db.feedbacks = internalDb.collection('feedbacks')
|
|
|
|
|
- db.githubSyncEntityVersions = internalDb.collection(
|
|
|
|
|
- 'githubSyncEntityVersions'
|
|
|
|
|
- )
|
|
|
|
|
- db.githubSyncProjectStates = internalDb.collection('githubSyncProjectStates')
|
|
|
|
|
- db.githubSyncUserCredentials = internalDb.collection(
|
|
|
|
|
- 'githubSyncUserCredentials'
|
|
|
|
|
- )
|
|
|
|
|
- db.globalMetrics = internalDb.collection('globalMetrics')
|
|
|
|
|
- db.grouppolicies = internalDb.collection('grouppolicies')
|
|
|
|
|
- db.institutions = internalDb.collection('institutions')
|
|
|
|
|
- db.messages = internalDb.collection('messages')
|
|
|
|
|
- db.migrations = internalDb.collection('migrations')
|
|
|
|
|
- db.notifications = internalDb.collection('notifications')
|
|
|
|
|
- db.oauthAccessTokens = internalDb.collection('oauthAccessTokens')
|
|
|
|
|
- db.oauthApplications = internalDb.collection('oauthApplications')
|
|
|
|
|
- db.oauthAuthorizationCodes = internalDb.collection('oauthAuthorizationCodes')
|
|
|
|
|
- db.projectAuditLogEntries = internalDb.collection('projectAuditLogEntries')
|
|
|
|
|
- db.projectHistoryChunks = internalDb.collection('projectHistoryChunks')
|
|
|
|
|
- db.projectHistoryFailures = internalDb.collection('projectHistoryFailures')
|
|
|
|
|
- db.projectHistoryLabels = internalDb.collection('projectHistoryLabels')
|
|
|
|
|
- db.projectHistoryMetaData = internalDb.collection('projectHistoryMetaData')
|
|
|
|
|
- db.projectHistorySyncState = internalDb.collection('projectHistorySyncState')
|
|
|
|
|
- db.projectInvites = internalDb.collection('projectInvites')
|
|
|
|
|
- db.projects = internalDb.collection('projects')
|
|
|
|
|
- db.publishers = internalDb.collection('publishers')
|
|
|
|
|
- db.rooms = internalDb.collection('rooms')
|
|
|
|
|
- db.samlCache = internalDb.collection('samlCache')
|
|
|
|
|
- db.samlLogs = internalDb.collection('samlLogs')
|
|
|
|
|
- db.spellingPreferences = internalDb.collection('spellingPreferences')
|
|
|
|
|
- db.splittests = internalDb.collection('splittests')
|
|
|
|
|
- db.ssoConfigs = internalDb.collection('ssoConfigs')
|
|
|
|
|
- db.subscriptions = internalDb.collection('subscriptions')
|
|
|
|
|
- db.surveys = internalDb.collection('surveys')
|
|
|
|
|
- db.systemmessages = internalDb.collection('systemmessages')
|
|
|
|
|
- db.tags = internalDb.collection('tags')
|
|
|
|
|
- db.teamInvites = internalDb.collection('teamInvites')
|
|
|
|
|
- db.tokens = internalDb.collection('tokens')
|
|
|
|
|
- db.userAuditLogEntries = internalDb.collection('userAuditLogEntries')
|
|
|
|
|
- db.users = internalDb.collection('users')
|
|
|
|
|
- db.onboardingDataCollection = internalDb.collection(
|
|
|
|
|
- 'onboardingDataCollection'
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- await mongoClient.connect()
|
|
|
|
|
|
|
+const internalDb = mongoClient.db()
|
|
|
|
|
+const db = {
|
|
|
|
|
+ contacts: internalDb.collection('contacts'),
|
|
|
|
|
+ deletedFiles: internalDb.collection('deletedFiles'),
|
|
|
|
|
+ deletedProjects: internalDb.collection('deletedProjects'),
|
|
|
|
|
+ deletedSubscriptions: internalDb.collection('deletedSubscriptions'),
|
|
|
|
|
+ deletedUsers: internalDb.collection('deletedUsers'),
|
|
|
|
|
+ dropboxEntities: internalDb.collection('dropboxEntities'),
|
|
|
|
|
+ dropboxProjects: internalDb.collection('dropboxProjects'),
|
|
|
|
|
+ docHistory: internalDb.collection('docHistory'),
|
|
|
|
|
+ docHistoryIndex: internalDb.collection('docHistoryIndex'),
|
|
|
|
|
+ docSnapshots: internalDb.collection('docSnapshots'),
|
|
|
|
|
+ docs: internalDb.collection('docs'),
|
|
|
|
|
+ feedbacks: internalDb.collection('feedbacks'),
|
|
|
|
|
+ githubSyncEntityVersions: internalDb.collection('githubSyncEntityVersions'),
|
|
|
|
|
+ githubSyncProjectStates: internalDb.collection('githubSyncProjectStates'),
|
|
|
|
|
+ githubSyncUserCredentials: internalDb.collection('githubSyncUserCredentials'),
|
|
|
|
|
+ globalMetrics: internalDb.collection('globalMetrics'),
|
|
|
|
|
+ grouppolicies: internalDb.collection('grouppolicies'),
|
|
|
|
|
+ institutions: internalDb.collection('institutions'),
|
|
|
|
|
+ messages: internalDb.collection('messages'),
|
|
|
|
|
+ migrations: internalDb.collection('migrations'),
|
|
|
|
|
+ notifications: internalDb.collection('notifications'),
|
|
|
|
|
+ oauthAccessTokens: internalDb.collection('oauthAccessTokens'),
|
|
|
|
|
+ oauthApplications: internalDb.collection('oauthApplications'),
|
|
|
|
|
+ oauthAuthorizationCodes: internalDb.collection('oauthAuthorizationCodes'),
|
|
|
|
|
+ projectAuditLogEntries: internalDb.collection('projectAuditLogEntries'),
|
|
|
|
|
+ projectHistoryChunks: internalDb.collection('projectHistoryChunks'),
|
|
|
|
|
+ projectHistoryFailures: internalDb.collection('projectHistoryFailures'),
|
|
|
|
|
+ projectHistoryLabels: internalDb.collection('projectHistoryLabels'),
|
|
|
|
|
+ projectHistoryMetaData: internalDb.collection('projectHistoryMetaData'),
|
|
|
|
|
+ projectHistorySyncState: internalDb.collection('projectHistorySyncState'),
|
|
|
|
|
+ projectInvites: internalDb.collection('projectInvites'),
|
|
|
|
|
+ projects: internalDb.collection('projects'),
|
|
|
|
|
+ publishers: internalDb.collection('publishers'),
|
|
|
|
|
+ rooms: internalDb.collection('rooms'),
|
|
|
|
|
+ samlCache: internalDb.collection('samlCache'),
|
|
|
|
|
+ samlLogs: internalDb.collection('samlLogs'),
|
|
|
|
|
+ spellingPreferences: internalDb.collection('spellingPreferences'),
|
|
|
|
|
+ splittests: internalDb.collection('splittests'),
|
|
|
|
|
+ ssoConfigs: internalDb.collection('ssoConfigs'),
|
|
|
|
|
+ subscriptions: internalDb.collection('subscriptions'),
|
|
|
|
|
+ surveys: internalDb.collection('surveys'),
|
|
|
|
|
+ systemmessages: internalDb.collection('systemmessages'),
|
|
|
|
|
+ tags: internalDb.collection('tags'),
|
|
|
|
|
+ teamInvites: internalDb.collection('teamInvites'),
|
|
|
|
|
+ tokens: internalDb.collection('tokens'),
|
|
|
|
|
+ userAuditLogEntries: internalDb.collection('userAuditLogEntries'),
|
|
|
|
|
+ users: internalDb.collection('users'),
|
|
|
|
|
+ onboardingDataCollection: internalDb.collection('onboardingDataCollection'),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+const connectionPromise = mongoClient.connect()
|
|
|
|
|
+
|
|
|
async function getCollectionNames() {
|
|
async function getCollectionNames() {
|
|
|
const internalDb = mongoClient.db()
|
|
const internalDb = mongoClient.db()
|
|
|
|
|
|
|
@@ -142,10 +125,10 @@ async function getCollectionInternal(name) {
|
|
|
module.exports = {
|
|
module.exports = {
|
|
|
db,
|
|
db,
|
|
|
ObjectId,
|
|
ObjectId,
|
|
|
|
|
+ connectionPromise,
|
|
|
getCollectionNames,
|
|
getCollectionNames,
|
|
|
getCollectionInternal,
|
|
getCollectionInternal,
|
|
|
dropTestDatabase,
|
|
dropTestDatabase,
|
|
|
- waitForDb,
|
|
|
|
|
READ_PREFERENCE_PRIMARY,
|
|
READ_PREFERENCE_PRIMARY,
|
|
|
READ_PREFERENCE_SECONDARY,
|
|
READ_PREFERENCE_SECONDARY,
|
|
|
}
|
|
}
|