132 lines
5.2 KiB
C#
132 lines
5.2 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Moonlight.Core.Database.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddPostsModels : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "Posts",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
|
.Annotation("Sqlite:Autoincrement", true),
|
|
Title = table.Column<string>(type: "TEXT", nullable: false),
|
|
Content = table.Column<string>(type: "TEXT", nullable: false),
|
|
AuthorId = table.Column<int>(type: "INTEGER", nullable: false),
|
|
Type = table.Column<int>(type: "INTEGER", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Posts", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Posts_Users_AuthorId",
|
|
column: x => x.AuthorId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "PostComments",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
|
.Annotation("Sqlite:Autoincrement", true),
|
|
Content = table.Column<string>(type: "TEXT", nullable: false),
|
|
AuthorId = table.Column<int>(type: "INTEGER", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
PostId = table.Column<int>(type: "INTEGER", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_PostComments", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_PostComments_Posts_PostId",
|
|
column: x => x.PostId,
|
|
principalTable: "Posts",
|
|
principalColumn: "Id");
|
|
table.ForeignKey(
|
|
name: "FK_PostComments_Users_AuthorId",
|
|
column: x => x.AuthorId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "PostLikes",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
|
.Annotation("Sqlite:Autoincrement", true),
|
|
UserId = table.Column<int>(type: "INTEGER", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
PostId = table.Column<int>(type: "INTEGER", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_PostLikes", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_PostLikes_Posts_PostId",
|
|
column: x => x.PostId,
|
|
principalTable: "Posts",
|
|
principalColumn: "Id");
|
|
table.ForeignKey(
|
|
name: "FK_PostLikes_Users_UserId",
|
|
column: x => x.UserId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_PostComments_AuthorId",
|
|
table: "PostComments",
|
|
column: "AuthorId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_PostComments_PostId",
|
|
table: "PostComments",
|
|
column: "PostId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_PostLikes_PostId",
|
|
table: "PostLikes",
|
|
column: "PostId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_PostLikes_UserId",
|
|
table: "PostLikes",
|
|
column: "UserId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Posts_AuthorId",
|
|
table: "Posts",
|
|
column: "AuthorId");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "PostComments");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "PostLikes");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Posts");
|
|
}
|
|
}
|
|
}
|