summaryrefslogtreecommitdiff
path: root/Migrations/20230905172129_UploadedFileMetadata.cs
blob: 549ede89c9b9c2072ceb8675800613fc9e92bc7f (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HyperBooru.Migrations
{
    /// <inheritdoc />
    public partial class UploadedFileMetadata : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.RenameColumn(
                name: "OriginalChecksum",
                table: "UploadedFiles",
                newName: "Checksum");

            migrationBuilder.AddColumn<string>(
                name: "MimeType",
                table: "UploadedFiles",
                type: "text",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "Height",
                table: "UploadedFiles",
                type: "integer",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "Width",
                table: "UploadedFiles",
                type: "integer",
                nullable: true);

            migrationBuilder.Sql(@"
                UPDATE
                  ""UploadedFiles""
                SET
                  ""MimeType"" = m.""MimeType"",
                  ""Width"" = m.""Width"",
                  ""Height"" = m.""Height""
                FROM
                  (SELECT
                    ""ObjectId"",
                    ""MimeType"",
                    ""Width"",
                    ""Height""
                  FROM
                    ""Media"") AS m
                WHERE
                  ""UploadedFiles"".""MediaObjectId"" = m.""ObjectId""");

            migrationBuilder.Sql(@"
                ALTER TABLE
                    ""UploadedFiles""
                ALTER COLUMN
                    ""MimeType""
                SET NOT NULL");

            migrationBuilder.AlterColumn<string>(
                name: "MimeType",
                table: "UploadedFiles",
                nullable: false);

            migrationBuilder.DropColumn(
                name: "Checksum",
                table: "Media");

            migrationBuilder.DropColumn(
                name: "Height",
                table: "Media");

            migrationBuilder.DropColumn(
                name: "MimeType",
                table: "Media");

            migrationBuilder.DropColumn(
                name: "Width",
                table: "Media");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "Checksum",
                table: "UploadedFiles");

            migrationBuilder.DropColumn(
                name: "Height",
                table: "UploadedFiles");

            migrationBuilder.DropColumn(
                name: "Width",
                table: "UploadedFiles");

            migrationBuilder.RenameColumn(
                name: "MimeType",
                table: "UploadedFiles",
                newName: "OriginalChecksum");

            migrationBuilder.AddColumn<string>(
                name: "Checksum",
                table: "Media",
                type: "text",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<int>(
                name: "Height",
                table: "Media",
                type: "integer",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<string>(
                name: "MimeType",
                table: "Media",
                type: "text",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<int>(
                name: "Width",
                table: "Media",
                type: "integer",
                nullable: false,
                defaultValue: 0);
        }
    }
}