JellyfinMigrationAttribute.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #pragma warning disable CS0618 // Type or member is obsolete
  18. public JellyfinMigrationAttribute(string order, string name) : this(order, name, null)
  19. #pragma warning restore CS0618 // Type or member is obsolete
  20. {
  21. }
  22. /// <summary>
  23. /// Initializes a new instance of the <see cref="JellyfinMigrationAttribute"/> class for legacy migrations.
  24. /// </summary>
  25. /// <param name="order">The ordering this migration should be applied to. Must be a valid DateTime ISO8601 formatted string.</param>
  26. /// <param name="name">The name of this Migration.</param>
  27. /// <param name="key">[ONLY FOR LEGACY MIGRATIONS]The unique key of this migration. Must be a valid Guid formatted string.</param>
  28. [Obsolete("This Constructor should only be used for Legacy migrations. Use the (Order,Name) one for all new ones instead.")]
  29. public JellyfinMigrationAttribute(string order, string name, string? key)
  30. {
  31. Order = DateTime.Parse(order, CultureInfo.InvariantCulture);
  32. Name = name;
  33. Stage = JellyfinMigrationStageTypes.AppInitialisation;
  34. if (key is not null)
  35. {
  36. Key = Guid.Parse(key);
  37. }
  38. }
  39. /// <summary>
  40. /// Gets or Sets a value indicating whether the annoated migration should be executed on a fresh install.
  41. /// </summary>
  42. public bool RunMigrationOnSetup { get; set; }
  43. /// <summary>
  44. /// Gets or Sets the stage the annoated migration should be executed at. Defaults to <see cref="JellyfinMigrationStageTypes.CoreInitialisation"/>.
  45. /// </summary>
  46. public JellyfinMigrationStageTypes Stage { get; set; } = JellyfinMigrationStageTypes.CoreInitialisation;
  47. /// <summary>
  48. /// Gets the ordering of the migration.
  49. /// </summary>
  50. public DateTime Order { get; }
  51. /// <summary>
  52. /// Gets the name of the migration.
  53. /// </summary>
  54. public string Name { get; }
  55. /// <summary>
  56. /// Gets the Legacy Key of the migration. Not required for new Migrations.
  57. /// </summary>
  58. public Guid? Key { get; }
  59. }