Update_7_55.cs 1.2 KB

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