From e89c9128c35ae6dc056c24819ea2ac8f4900ba19 Mon Sep 17 00:00:00 2001 From: Jessica Lawshe <5312836+lawshe@users.noreply.github.com> Date: Thu, 5 Mar 2026 10:41:37 -0600 Subject: [PATCH] Merge pull request #31783 from overleaf/jel-mongo-domainVerification [web] Add `domainVerifications` collection GitOrigin-RevId: 5a9fe9ea80ecf76af9802014149ae785cc4412d5 --- .../web/app/src/infrastructure/mongodb.mjs | 1 + .../web/app/src/models/DomainVerification.mjs | 33 +++++++++++++++++++ ...25162503_add_index_domainVerifications.mjs | 32 ++++++++++++++++++ tools/migrations/lib/mongodb.mjs | 1 + 4 files changed, 67 insertions(+) create mode 100644 services/web/app/src/models/DomainVerification.mjs create mode 100644 tools/migrations/20260225162503_add_index_domainVerifications.mjs diff --git a/services/web/app/src/infrastructure/mongodb.mjs b/services/web/app/src/infrastructure/mongodb.mjs index 6ffc38639f..f0bde7efab 100644 --- a/services/web/app/src/infrastructure/mongodb.mjs +++ b/services/web/app/src/infrastructure/mongodb.mjs @@ -38,6 +38,7 @@ export const db = { deletedProjects: internalDb.collection('deletedProjects'), deletedSubscriptions: internalDb.collection('deletedSubscriptions'), deletedUsers: internalDb.collection('deletedUsers'), + domainVerifications: internalDb.collection('domainVerifications'), dropboxEntities: internalDb.collection('dropboxEntities'), dropboxProjects: internalDb.collection('dropboxProjects'), docSnapshots: internalDb.collection('docSnapshots'), diff --git a/services/web/app/src/models/DomainVerification.mjs b/services/web/app/src/models/DomainVerification.mjs new file mode 100644 index 0000000000..ca84561b23 --- /dev/null +++ b/services/web/app/src/models/DomainVerification.mjs @@ -0,0 +1,33 @@ +import mongoose from '../infrastructure/Mongoose.mjs' +const { Schema } = mongoose + +export const DomainVerificationSchema = new Schema( + { + domain: { + type: String, + required: true, + unique: true, + }, + token: { type: String, required: true }, + status: { + type: String, + enum: ['pending', 'verified', 'failed'], + default: 'pending', + }, + createdAt: { type: Date, default: Date.now }, + verifiedAt: Date, + reverifiedAt: Date, + verificationAttemptCount: { type: Number, default: 0 }, + groupId: Schema.Types.ObjectId, + lastVerificationAttemptAt: Date, + }, + { + collection: 'domainVerifications', + minimize: false, + } +) + +export const DomainVerification = mongoose.model( + 'DomainVerification', + DomainVerificationSchema +) diff --git a/tools/migrations/20260225162503_add_index_domainVerifications.mjs b/tools/migrations/20260225162503_add_index_domainVerifications.mjs new file mode 100644 index 0000000000..8c542cc1eb --- /dev/null +++ b/tools/migrations/20260225162503_add_index_domainVerifications.mjs @@ -0,0 +1,32 @@ +/* eslint-disable no-unused-vars */ + +import Helpers from './lib/helpers.mjs' + +const tags = ['saas'] + +const indexes = [ + { + key: { domain: 1 }, + name: 'domain_1', + unique: true, + }, +] + +const migrate = async client => { + const { db } = client + + await Helpers.addIndexesToCollection(db.domainVerifications, indexes) +} + +const rollback = async client => { + const { db } = client + await Helpers.dropIndexesFromCollection(db.domainVerifications, [ + { name: 'domain_1' }, + ]) +} + +export default { + tags, + migrate, + rollback, +} diff --git a/tools/migrations/lib/mongodb.mjs b/tools/migrations/lib/mongodb.mjs index b692783c76..dc0ad2c214 100644 --- a/tools/migrations/lib/mongodb.mjs +++ b/tools/migrations/lib/mongodb.mjs @@ -20,6 +20,7 @@ export const db = { dropboxProjects: internalDb.collection('dropboxProjects'), docSnapshots: internalDb.collection('docSnapshots'), docs: internalDb.collection('docs'), + domainVerifications: internalDb.collection('domainVerifications'), feedbacks: internalDb.collection('feedbacks'), githubSyncEntityVersions: internalDb.collection('githubSyncEntityVersions'), githubSyncProjectStates: internalDb.collection('githubSyncProjectStates'),