Update_7_55.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using InABox.Core;
  2. using InABox.Database;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace PRS.Shared.Database_Update_Scripts;
  9. /// <summary>
  10. /// Update all the documents to use external storage.
  11. /// </summary>
  12. internal class Update_7_55 : DatabaseUpdateScript
  13. {
  14. public override VersionNumber Version => new(7, 55);
  15. public override bool Update()
  16. {
  17. var store = DbFactory.FindStore<Document>(Guid.Empty, "", Platform.Server, CoreUtils.GetVersion());
  18. int i = 0;
  19. int numStep = 100;
  20. while (true)
  21. {
  22. var documents = DbFactory.Provider.Query<Document>(
  23. new Filter<Document>(x => x.Data).IsNotEqualTo(null)
  24. .And(x => x.Data).IsNotEqualTo(Array.Empty<byte>()),
  25. new Columns<Document>(x => x.ID).Add(x => x.Data),
  26. top: numStep).ToList<Document>();
  27. if(documents.Count == 0)
  28. {
  29. return true;
  30. }
  31. store.Save(documents, "");
  32. i += numStep;
  33. if (i / numStep % 10 == 0)
  34. {
  35. Logger.Send(LogType.Information, "", $"Converted {i} documents");
  36. }
  37. }
  38. }
  39. }