Update_7_55.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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(), Logger.New());
  17. int i = 0;
  18. int numStep = 100;
  19. while (true)
  20. {
  21. var documents = DbFactory.NewProvider(Logger.Main).Query<Document>(
  22. new Filter<Document>(x => x.Data).IsNotEqualTo(null)
  23. .And(x => x.Data).IsNotEqualTo(Array.Empty<byte>()),
  24. Columns.None<Document>().Add(x => x.ID).Add(x => x.Data),
  25. null,
  26. CoreRange.Database(1000)
  27. ).ToList<Document>();
  28. if(documents.Count == 0)
  29. {
  30. return true;
  31. }
  32. store.Save(documents, "");
  33. i += numStep;
  34. if (i / numStep % 10 == 0)
  35. {
  36. Logger.Send(LogType.Information, "", $"Converted {i} documents");
  37. }
  38. }
  39. }
  40. }