aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Migrations/JellyfinMigrationAttribute.cs
blob: 70e54125b8226198dbfe190b2ee39717551d6b0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma warning disable CA1019 // Define accessors for attribute arguments

using System;
using System.Globalization;
using Jellyfin.Server.Migrations.Stages;

namespace Jellyfin.Server.Migrations;

/// <summary>
/// Declares an class as an migration with its set metadata.
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
public sealed class JellyfinMigrationAttribute : Attribute
{
    /// <summary>
    /// Initializes a new instance of the <see cref="JellyfinMigrationAttribute"/> class.
    /// </summary>
    /// <param name="order">The ordering this migration should be applied to. Must be a valid DateTime ISO8601 formatted string.</param>
    /// <param name="name">The name of this Migration.</param>
#pragma warning disable CS0618 // Type or member is obsolete
    public JellyfinMigrationAttribute(string order, string name) : this(order, name, null)
#pragma warning restore CS0618 // Type or member is obsolete
    {
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="JellyfinMigrationAttribute"/> class for legacy migrations.
    /// </summary>
    /// <param name="order">The ordering this migration should be applied to. Must be a valid DateTime ISO8601 formatted string.</param>
    /// <param name="name">The name of this Migration.</param>
    /// <param name="key">[ONLY FOR LEGACY MIGRATIONS]The unique key of this migration. Must be a valid Guid formatted string.</param>
    [Obsolete("This Constructor should only be used for Legacy migrations. Use the (Order,Name) one for all new ones instead.")]
    public JellyfinMigrationAttribute(string order, string name, string? key)
    {
        Order = DateTime.Parse(order, CultureInfo.InvariantCulture);
        Name = name;
        Stage = JellyfinMigrationStageTypes.AppInitialisation;
        if (key is not null)
        {
            Key = Guid.Parse(key);
        }
    }

    /// <summary>
    /// Gets or Sets a value indicating whether the annoated migration should be executed on a fresh install.
    /// </summary>
    public bool RunMigrationOnSetup { get; set; }

    /// <summary>
    /// Gets or Sets the stage the annoated migration should be executed at. Defaults to <see cref="JellyfinMigrationStageTypes.CoreInitialisation"/>.
    /// </summary>
    public JellyfinMigrationStageTypes Stage { get; set; } = JellyfinMigrationStageTypes.CoreInitialisation;

    /// <summary>
    /// Gets the ordering of the migration.
    /// </summary>
    public DateTime Order { get; }

    /// <summary>
    /// Gets the name of the migration.
    /// </summary>
    public string Name { get; }

    /// <summary>
    /// Gets the Legacy Key of the migration. Not required for new Migrations.
    /// </summary>
    public Guid? Key { get; }
}