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
|
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace HyperBooru.Migrations
{
/// <inheritdoc />
public partial class UploadedFilesToObjects : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "Guid",
table: "UploadedFiles",
type: "uuid",
nullable: false,
defaultValueSql: "gen_random_uuid()");
migrationBuilder.Sql(
"INSERT INTO \"Objects\" (\"Guid\") SELECT \"Guid\" FROM \"UploadedFiles\";");
migrationBuilder.Sql(
"UPDATE \"UploadedFiles\" AS uf SET \"UploadedFileId\" = o.\"ObjectId\" FROM \"Objects\" AS o WHERE o.\"Guid\" = uf.\"Guid\";");
migrationBuilder.DropColumn(
name: "Guid",
table: "UploadedFiles");
migrationBuilder.RenameColumn(
name: "UploadedFileId",
table: "UploadedFiles",
newName: "ObjectId");
migrationBuilder.AlterColumn<int>(
name: "ObjectId",
table: "UploadedFiles",
type: "integer",
nullable: false,
oldClrType: typeof(int),
oldType: "integer")
.OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
migrationBuilder.AddForeignKey(
name: "FK_UploadedFiles_Objects_ObjectId",
table: "UploadedFiles",
column: "ObjectId",
principalTable: "Objects",
principalColumn: "ObjectId",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_UploadedFiles_Objects_ObjectId",
table: "UploadedFiles");
migrationBuilder.RenameColumn(
name: "ObjectId",
table: "UploadedFiles",
newName: "UploadedFileId");
migrationBuilder.AlterColumn<int>(
name: "UploadedFileId",
table: "UploadedFiles",
type: "integer",
nullable: false,
oldClrType: typeof(int),
oldType: "integer")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
}
}
}
|