diff options
| author | Jake Mannens <jake@asger.xyz> | 2023-09-06 09:30:54 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2023-09-06 09:30:54 +1000 |
| commit | c1c81ba6a14437e020841f1d454d473bbda6b52b (patch) | |
| tree | c6086bd8f8f4048bf3257ba93503605249d379c1 /Migrations/20230905172129_UploadedFileMetadata.cs | |
| parent | 33a3c4d57d774d98c3836c98ecbd2e1dd5ea84c3 (diff) | |
Moved metadata from Media object to UploadedFile object
Diffstat (limited to 'Migrations/20230905172129_UploadedFileMetadata.cs')
| -rw-r--r-- | Migrations/20230905172129_UploadedFileMetadata.cs | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/Migrations/20230905172129_UploadedFileMetadata.cs b/Migrations/20230905172129_UploadedFileMetadata.cs new file mode 100644 index 0000000..549ede8 --- /dev/null +++ b/Migrations/20230905172129_UploadedFileMetadata.cs @@ -0,0 +1,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); + } + } +} |
