JellyfinMigrationAttribute.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma warning disable CA1019 // Define accessors for attribute arguments
  2. using System;
  3. using System.Globalization;
  4. using Jellyfin.Server.Migrations.Stages;
  5. namespace Jellyfin.Server.Migrations;
  6. /// <summary>
  7. /// Declares an class as an migration with its set metadata.
  8. /// </summary>
  9. [AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
  10. public sealed class JellyfinMigrationAttribute : Attribute
  11. {
  12. /// <summary>
  13. /// Initializes a new instance of the <see cref="JellyfinMigrationAttribute"/> class.
  14. /// </summary>
  15. /// <param name="order">The ordering this migration should be applied to. Must be a valid DateTime ISO8601 formatted string.</param>
  16. /// <param name="name">The name of this Migration.</param>
  17. public JellyfinMigrationAttribute(string order, string name) : this(order, name, null)
  18. {
  19. }
  20. /// <summary>
  21. /// Initializes a new instance of the <see cref="JellyfinMigrationAttribute"/> class for legacy migrations.
  22. /// </summary>
  23. /// <param name="order">The ordering this migration should be applied to. Must be a valid DateTime ISO8601 formatted string.</param>
  24. /// <param name="name">The name of this Migration.</param>
  25. /// <param name="key">[ONLY FOR LEGACY MIGRATIONS]The unique key of this migration. Must be a valid Guid formatted string.</param>
  26. public JellyfinMigrationAttribute(string order, string name, string? key)
  27. {
  28. Order = DateTime.Parse(order, CultureInfo.InvariantCulture);
  29. Name = name;
  30. Stage = JellyfinMigrationStageTypes.AppInitialisation;
  31. if (key is not null)
  32. {
  33. Key = Guid.Parse(key);
  34. }
  35. }
  36. /// <summary>
  37. /// Gets or Sets a value indicating whether the annoated migration should be executed on a fresh install.
  38. /// </summary>
  39. public bool RunMigrationOnSetup { get; set; }
  40. /// <summary>
  41. /// Gets or Sets the stage the annoated migration should be executed at. Defaults to <see cref="JellyfinMigrationStageTypes.CoreInitialisaition"/>.
  42. /// </summary>
  43. public JellyfinMigrationStageTypes Stage { get; set; } = JellyfinMigrationStageTypes.CoreInitialisaition;
  44. /// <summary>
  45. /// Gets the ordering of the migration.
  46. /// </summary>
  47. public DateTime Order { get; }
  48. /// <summary>
  49. /// Gets the name of the migration.
  50. /// </summary>
  51. public string Name { get; }
  52. /// <summary>
  53. /// Gets the Legacy Key of the migration. Not required for new Migrations.
  54. /// </summary>
  55. public Guid? Key { get; }
  56. }