Explorar o código

[web] migration fixes (#26443)

* [web] fix typo in ESM migration of a db migration

* [web] migrate old migration to ESM

* [web] use batchedUpdate for bulk updates in old migrations

GitOrigin-RevId: a984f785c577c2ac4125c947b8a3efffa57e1eb7
Jakob Ackermann hai 1 ano
pai
achega
30143ead97

+ 1 - 1
services/web/migrations/20210726083523_convert_split_tests_assigned_at_strings_to_dates.mjs

@@ -1,4 +1,4 @@
-import updateStringDates from '../scripts/confirmed_at_to_dates.mjs'
+import updateStringDates from '../scripts/split_tests_assigned_at_to_dates.mjs'
 
 const tags = ['saas']
 

+ 9 - 7
services/web/migrations/20230110140452_rename_recurly_cached_status.mjs

@@ -1,13 +1,12 @@
-/* eslint-disable no-unused-vars */
-
-import Helpers from './lib/helpers.mjs'
+import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
 
 const tags = ['saas']
 
 const migrate = async client => {
   const { db } = client
   // 'recurly' -> 'recurlyStatus'
-  await db.subscriptions.updateMany(
+  await batchedUpdate(
+    db.subscriptions,
     {
       $and: [
         { recurlyStatus: { $exists: false } },
@@ -17,7 +16,8 @@ const migrate = async client => {
     { $rename: { recurly: 'recurlyStatus' } }
   )
   // some records may have already recached the recurly status, discard old cache
-  await db.subscriptions.updateMany(
+  await batchedUpdate(
+    db.subscriptions,
     {
       $and: [
         { recurlyStatus: { $exists: true } },
@@ -31,7 +31,8 @@ const migrate = async client => {
 const rollback = async client => {
   const { db } = client
   // 'recurlyStatus' -> 'recurly'
-  await db.subscriptions.updateMany(
+  await batchedUpdate(
+    db.subscriptions,
     {
       $and: [
         { recurly: { $exists: false } },
@@ -41,7 +42,8 @@ const rollback = async client => {
     { $rename: { recurlyStatus: 'recurly' } }
   )
   // some records may have already recached the recurly status, discard old cache
-  await db.subscriptions.updateMany(
+  await batchedUpdate(
+    db.subscriptions,
     {
       $and: [
         { recurlyStatus: { $exists: true } },

+ 4 - 5
services/web/migrations/20230207134844_group_invite_emails_to_lowercase.mjs

@@ -1,12 +1,11 @@
-/* eslint-disable no-unused-vars */
-
-import Helpers from './lib/helpers.mjs'
+import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
 
 const tags = ['saas']
 
 const migrate = async client => {
   const { db } = client
-  db.subscriptions.updateMany(
+  await batchedUpdate(
+    db.subscriptions,
     {
       'teamInvites.0': {
         $exists: true,
@@ -36,7 +35,7 @@ const migrate = async client => {
   )
 }
 
-const rollback = async client => {
+const rollback = async () => {
   // There is no way back.
 }
 

+ 6 - 2
services/web/migrations/20230928092537_backfill_subscriptions_managed_users_feature_flag.mjs

@@ -1,8 +1,11 @@
+import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
+
 const tags = ['saas']
 
 const migrate = async client => {
   const { db } = client
-  await db.subscriptions.updateMany(
+  await batchedUpdate(
+    db.subscriptions,
     { 'features.managedUsers': { $ne: true } },
     { $set: { 'features.managedUsers': null } }
   )
@@ -10,7 +13,8 @@ const migrate = async client => {
 
 const rollback = async client => {
   const { db } = client
-  await db.subscriptions.updateMany(
+  await batchedUpdate(
+    db.subscriptions,
     { 'features.managedUsers': { $eq: null } },
     { $set: { 'features.managedUsers': false } }
   )

+ 10 - 4
services/web/migrations/20231025094810_sso_config_certificates_array.mjs

@@ -1,8 +1,11 @@
+import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
+
 const tags = ['saas']
 
 const migrate = async client => {
   const { db } = client
-  await db.ssoConfigs.updateMany(
+  await batchedUpdate(
+    db.ssoConfigs,
     { certificate: { $exists: true }, certificates: { $exists: false } },
     [
       { $set: { certificates: ['$certificate'] } },
@@ -11,11 +14,13 @@ const migrate = async client => {
       },
     ]
   )
-  await db.ssoConfigs.updateMany(
+  await batchedUpdate(
+    db.ssoConfigs,
     { userFirstNameAttribute: null },
     { $unset: { userFirstNameAttribute: true } }
   )
-  await db.ssoConfigs.updateMany(
+  await batchedUpdate(
+    db.ssoConfigs,
     { userLastNameAttribute: null },
     { $unset: { userLastNameAttribute: true } }
   )
@@ -23,7 +28,8 @@ const migrate = async client => {
 
 const rollback = async client => {
   const { db } = client
-  await db.ssoConfigs.updateMany(
+  await batchedUpdate(
+    db.ssoConfigs,
     { certificate: { $exists: false }, certificates: { $exists: true } },
     [
       { $set: { certificate: { $arrayElemAt: ['$certificates', 0] } } },

+ 5 - 5
services/web/migrations/20231030160030_managed_users_enabled.mjs

@@ -1,12 +1,11 @@
-/* eslint-disable no-unused-vars */
-
-import Helpers from './lib/helpers.mjs'
+import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
 
 const tags = ['saas']
 
 const migrate = async client => {
   const { db } = client
-  await db.subscriptions.updateMany(
+  await batchedUpdate(
+    db.subscriptions,
     { groupPolicy: { $exists: true } },
     { $set: { managedUsersEnabled: true } }
   )
@@ -14,7 +13,8 @@ const migrate = async client => {
 
 const rollback = async client => {
   const { db } = client
-  await db.subscriptions.updateMany(
+  await batchedUpdate(
+    db.subscriptions,
     { groupPolicy: { $exists: true } },
     { $unset: { managedUsersEnabled: '' } }
   )

+ 10 - 4
services/web/migrations/20240923131936_create_user_last_active_index.js → services/web/migrations/20240923131936_create_user_last_active_index.mjs

@@ -1,6 +1,6 @@
-const Helpers = require('./lib/helpers')
+import Helpers from './lib/helpers.mjs'
 
-exports.tags = ['server-ce', 'server-pro', 'saas']
+const tags = ['server-ce', 'server-pro', 'saas']
 
 const indexes = [
   {
@@ -9,12 +9,18 @@ const indexes = [
   },
 ]
 
-exports.migrate = async client => {
+async function migrate(client) {
   const { db } = client
   await Helpers.addIndexesToCollection(db.users, indexes)
 }
 
-exports.rollback = async client => {
+async function rollback(client) {
   const { db } = client
   await Helpers.dropIndexesFromCollection(db.users, indexes)
 }
+
+export default {
+  tags,
+  migrate,
+  rollback,
+}

+ 6 - 2
services/web/migrations/20241111133330_remove_null_managed_users_sso_from_subscriptions.mjs

@@ -1,12 +1,16 @@
+import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
+
 const tags = ['saas']
 
 const migrate = async client => {
   const { db } = client
-  await db.subscriptions.updateMany(
+  await batchedUpdate(
+    db.subscriptions,
     { 'features.managedUsers': { $eq: null } },
     { $set: { 'features.managedUsers': true } }
   )
-  await db.subscriptions.updateMany(
+  await batchedUpdate(
+    db.subscriptions,
     { 'features.groupSSO': { $eq: null } },
     { $set: { 'features.groupSSO': true } }
   )