aboutsummaryrefslogtreecommitdiff
path: root/src/Jellyfin.Database/Jellyfin.Database.Providers.Sqlite/Migrations/20260113233000_AddForeignKeyToOwnerId.cs
blob: 39a0805d2a036ca13c9dda5a78cebe810fea4a56 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Jellyfin.Database.Providers.Sqlite.Migrations
{
    /// <inheritdoc />
    public partial class AddForeignKeyToOwnerId : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_BaseItems_BaseItems_BaseItemEntityId",
                table: "BaseItems");

            migrationBuilder.DropIndex(
                name: "IX_BaseItems_BaseItemEntityId",
                table: "BaseItems");

            migrationBuilder.DropColumn(
                name: "BaseItemEntityId",
                table: "BaseItems");

            migrationBuilder.Sql(
                """
                UPDATE BaseItems
                SET OwnerId = '00000000-0000-0000-0000-000000000001'
                WHERE OwnerId IS NOT NULL
                  AND OwnerId NOT IN (SELECT Id FROM BaseItems);
                """);

            migrationBuilder.AddForeignKey(
                name: "FK_BaseItems_BaseItems_OwnerId",
                table: "BaseItems",
                column: "OwnerId",
                principalTable: "BaseItems",
                principalColumn: "Id");

            migrationBuilder.AddColumn<bool>(
                name: "IsOriginal",
                table: "MediaStreamInfos",
                type: "INTEGER",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<string>(
                name: "OriginalLanguage",
                table: "BaseItems",
                type: "TEXT",
                nullable: true);

            migrationBuilder.UpdateData(
                table: "BaseItems",
                keyColumn: "Id",
                keyValue: new Guid("00000000-0000-0000-0000-000000000001"),
                column: "OriginalLanguage",
                value: null);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_BaseItems_BaseItems_OwnerId",
                table: "BaseItems");

            migrationBuilder.AddColumn<Guid>(
                name: "BaseItemEntityId",
                table: "BaseItems",
                type: "TEXT",
                nullable: true);

            migrationBuilder.UpdateData(
                table: "BaseItems",
                keyColumn: "Id",
                keyValue: new Guid("00000000-0000-0000-0000-000000000001"),
                column: "BaseItemEntityId",
                value: null);

            migrationBuilder.CreateIndex(
                name: "IX_BaseItems_BaseItemEntityId",
                table: "BaseItems",
                column: "BaseItemEntityId");

            migrationBuilder.AddForeignKey(
                name: "FK_BaseItems_BaseItems_BaseItemEntityId",
                table: "BaseItems",
                column: "BaseItemEntityId",
                principalTable: "BaseItems",
                principalColumn: "Id");

            migrationBuilder.DropColumn(
                name: "IsOriginal",
                table: "MediaStreamInfos");

            migrationBuilder.DropColumn(
                name: "OriginalLanguage",
                table: "BaseItems");
        }
    }
}