yavsc/src/Yavsc.Org/Migrations/20260609224137_AddBlogFileAttachments.cs
2026-06-10 00:23:17 +01:00

69 lines
2.7 KiB
C#

using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Yavsc.Migrations
{
/// <inheritdoc />
public partial class AddBlogFileAttachments : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "UploadedFiles",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Path = table.Column<string>(type: "text", nullable: true),
Length = table.Column<long>(type: "bigint", nullable: false),
ContentType = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_UploadedFiles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "BlogAttachedFiles",
columns: table => new
{
FileId = table.Column<long>(type: "bigint", nullable: false),
PostId = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_BlogAttachedFiles", x => new { x.FileId, x.PostId });
table.ForeignKey(
name: "FK_BlogAttachedFiles_BlogSpot_PostId",
column: x => x.PostId,
principalTable: "BlogSpot",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_BlogAttachedFiles_UploadedFiles_FileId",
column: x => x.FileId,
principalTable: "UploadedFiles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_BlogAttachedFiles_PostId",
table: "BlogAttachedFiles",
column: "PostId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "BlogAttachedFiles");
migrationBuilder.DropTable(
name: "UploadedFiles");
}
}
}