20220825160708_recreate_dropboxEntities.js 989 B

1234567891011121314151617181920212223242526272829303132
  1. const Helpers = require('./lib/helpers')
  2. exports.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. exports.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. exports.rollback = async client => {
  26. const { db } = client
  27. await Helpers.dropIndexesFromCollection(db.dropboxEntities, indexes)
  28. }