20220825160708_recreate_dropboxEntities.mjs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import Helpers from './lib/helpers.mjs'
  2. const tags = ['saas']
  3. const indexes = [
  4. {
  5. key: { 'overleaf.userId': 1, 'dropbox.id': 1 },
  6. name: 'overleaf.userId_1_dropbox.id_1',
  7. unique: true,
  8. partialFilterExpression: { 'dropbox.id': { $exists: true } },
  9. },
  10. {
  11. key: { 'overleaf.userId': 1, 'overleaf.id': 1 },
  12. name: 'overleaf.userId_1_overleaf.id_1',
  13. unique: true,
  14. partialFilterExpression: { 'overleaf.id': { $exists: true } },
  15. },
  16. { key: { 'overleaf.userId': 1, 'dropbox.pathLower': 'hashed' } },
  17. ]
  18. const migrate = async client => {
  19. const { db } = client
  20. // Forcibly drop the dropboxEntities collection. The new structure is
  21. // different and we don't want to keep the data with the old structure around.
  22. await db.dropboxEntities.drop()
  23. await Helpers.addIndexesToCollection(db.dropboxEntities, indexes)
  24. }
  25. const rollback = async client => {
  26. const { db } = client
  27. await Helpers.dropIndexesFromCollection(db.dropboxEntities, indexes)
  28. }
  29. export default {
  30. tags,
  31. migrate,
  32. rollback,
  33. }