mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-30 08:48:39 +00:00
Fix database migration
This commit is contained in:
parent
19a29ca328
commit
aaea040276
3 changed files with 116 additions and 56 deletions
|
@ -1,48 +0,0 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ProjectLighthouse.Migrations
|
||||
{
|
||||
public partial class CommentRefactor : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Comments_Slots_TargetId",
|
||||
table: "Comments");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Comments_Users_TargetId",
|
||||
table: "Comments");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Comments_TargetId",
|
||||
table: "Comments");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Comments_TargetId",
|
||||
table: "Comments",
|
||||
column: "TargetId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Comments_Slots_TargetId",
|
||||
table: "Comments",
|
||||
column: "TargetId",
|
||||
principalTable: "Slots",
|
||||
principalColumn: "SlotId",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Comments_Users_TargetId",
|
||||
table: "Comments",
|
||||
column: "TargetId",
|
||||
principalTable: "Users",
|
||||
principalColumn: "UserId",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
110
ProjectLighthouse/Migrations/20220205132152_CommentRefactor.cs
Normal file
110
ProjectLighthouse/Migrations/20220205132152_CommentRefactor.cs
Normal file
|
@ -0,0 +1,110 @@
|
|||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ProjectLighthouse.Migrations
|
||||
{
|
||||
public partial class CommentRefactor : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Comments_Users_TargetUserId",
|
||||
table: "Comments");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Comments_TargetUserId",
|
||||
table: "Comments");
|
||||
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "TargetUserId",
|
||||
table: "Comments",
|
||||
newName: "Type");
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "Deleted",
|
||||
table: "Comments",
|
||||
type: "tinyint(1)",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "DeletedBy",
|
||||
table: "Comments",
|
||||
type: "longtext",
|
||||
nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "DeletedType",
|
||||
table: "Comments",
|
||||
type: "longtext",
|
||||
nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "TargetId",
|
||||
table: "Comments",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Reactions",
|
||||
columns: table => new
|
||||
{
|
||||
RatingId = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
UserId = table.Column<int>(type: "int", nullable: false),
|
||||
TargetId = table.Column<int>(type: "int", nullable: false),
|
||||
Rating = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Reactions", x => x.RatingId);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Reactions");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Deleted",
|
||||
table: "Comments");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DeletedBy",
|
||||
table: "Comments");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DeletedType",
|
||||
table: "Comments");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TargetId",
|
||||
table: "Comments");
|
||||
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "Type",
|
||||
table: "Comments",
|
||||
newName: "TargetUserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Comments_TargetUserId",
|
||||
table: "Comments",
|
||||
column: "TargetUserId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Comments_Users_TargetUserId",
|
||||
table: "Comments",
|
||||
column: "TargetUserId",
|
||||
principalTable: "Users",
|
||||
principalColumn: "UserId",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -48,15 +48,13 @@ public class Comment
|
|||
{
|
||||
return "This comment has been deleted by the author.";
|
||||
}
|
||||
else
|
||||
{
|
||||
using Database database = new();
|
||||
User deletedBy = database.Users.FirstOrDefault(u => u.Username == this.DeletedBy);
|
||||
|
||||
if (deletedBy != null && deletedBy.UserId == this.TargetId)
|
||||
{
|
||||
return "This comment has been deleted by the player.";
|
||||
}
|
||||
using Database database = new();
|
||||
User deletedBy = database.Users.FirstOrDefault(u => u.Username == this.DeletedBy);
|
||||
|
||||
if (deletedBy != null && deletedBy.UserId == this.TargetId)
|
||||
{
|
||||
return "This comment has been deleted by the player.";
|
||||
}
|
||||
|
||||
return "This comment has been deleted.";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue