Files
webappserver1/Migrations/20260519032425_InitialFriends.cs
2026-05-19 21:55:48 +08:00

409 lines
17 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace WebAppServer1.Migrations
{
/// <inheritdoc />
public partial class InitialFriends : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "Password",
table: "Users",
newName: "Username");
migrationBuilder.RenameColumn(
name: "Name",
table: "Users",
newName: "Signature");
migrationBuilder.RenameColumn(
name: "LastModifiedDate",
table: "Users",
newName: "LastActive");
migrationBuilder.RenameColumn(
name: "CreatedDate",
table: "Users",
newName: "CreatedAt");
migrationBuilder.AddColumn<string>(
name: "AvatarUrl",
table: "Users",
type: "text",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
name: "Email",
table: "Users",
type: "text",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<bool>(
name: "IsOnline",
table: "Users",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<string>(
name: "PasswordHash",
table: "Users",
type: "text",
nullable: false,
defaultValue: "");
migrationBuilder.CreateTable(
name: "Friends",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<int>(type: "integer", nullable: false),
FriendId = table.Column<int>(type: "integer", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Friends", x => x.Id);
table.ForeignKey(
name: "FK_Friends_Users_FriendId",
column: x => x.FriendId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Friends_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Groups",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
OwnerId = table.Column<int>(type: "integer", nullable: false),
AvatarUrl = table.Column<string>(type: "text", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Groups", x => x.Id);
table.ForeignKey(
name: "FK_Groups_Users_OwnerId",
column: x => x.OwnerId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "LoginRecords",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<int>(type: "integer", nullable: false),
LoginTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
IpAddress = table.Column<string>(type: "text", nullable: false),
DeviceInfo = table.Column<string>(type: "text", nullable: false),
IsSuccess = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_LoginRecords", x => x.Id);
table.ForeignKey(
name: "FK_LoginRecords_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Notifications",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<int>(type: "integer", nullable: false),
Type = table.Column<int>(type: "integer", nullable: false),
Content = table.Column<string>(type: "text", nullable: false),
IsRead = table.Column<bool>(type: "boolean", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Notifications", x => x.Id);
table.ForeignKey(
name: "FK_Notifications_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "userProfileHistories",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<int>(type: "integer", nullable: false),
FieldName = table.Column<string>(type: "text", nullable: false),
OldValue = table.Column<string>(type: "text", nullable: false),
NewValue = table.Column<string>(type: "text", nullable: false),
ChangedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
ChangedBy = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_userProfileHistories", x => x.Id);
table.ForeignKey(
name: "FK_userProfileHistories_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "GroupMembers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
GroupId = table.Column<int>(type: "integer", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false),
Role = table.Column<int>(type: "integer", nullable: false),
JoinedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GroupMembers", x => x.Id);
table.ForeignKey(
name: "FK_GroupMembers_Groups_GroupId",
column: x => x.GroupId,
principalTable: "Groups",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_GroupMembers_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Messages",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
SenderId = table.Column<int>(type: "integer", nullable: false),
ReceiverId = table.Column<int>(type: "integer", nullable: true),
GroupId = table.Column<int>(type: "integer", nullable: true),
Content = table.Column<string>(type: "text", nullable: false),
MessageType = table.Column<int>(type: "integer", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
IsRead = table.Column<bool>(type: "boolean", nullable: false),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Messages", x => x.Id);
table.ForeignKey(
name: "FK_Messages_Groups_GroupId",
column: x => x.GroupId,
principalTable: "Groups",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Messages_Users_ReceiverId",
column: x => x.ReceiverId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Messages_Users_SenderId",
column: x => x.SenderId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Files",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UploaderId = table.Column<int>(type: "integer", nullable: false),
MessageId = table.Column<int>(type: "integer", nullable: false),
FileUrl = table.Column<string>(type: "text", nullable: false),
FileType = table.Column<int>(type: "integer", nullable: false),
Size = table.Column<int>(type: "integer", nullable: false),
UploadedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Files", x => x.Id);
table.ForeignKey(
name: "FK_Files_Messages_MessageId",
column: x => x.MessageId,
principalTable: "Messages",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Files_Users_UploaderId",
column: x => x.UploaderId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Files_MessageId",
table: "Files",
column: "MessageId");
migrationBuilder.CreateIndex(
name: "IX_Files_UploaderId",
table: "Files",
column: "UploaderId");
migrationBuilder.CreateIndex(
name: "IX_Friends_FriendId",
table: "Friends",
column: "FriendId");
migrationBuilder.CreateIndex(
name: "IX_Friends_UserId",
table: "Friends",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_GroupMembers_GroupId",
table: "GroupMembers",
column: "GroupId");
migrationBuilder.CreateIndex(
name: "IX_GroupMembers_UserId",
table: "GroupMembers",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Groups_OwnerId",
table: "Groups",
column: "OwnerId");
migrationBuilder.CreateIndex(
name: "IX_LoginRecords_UserId",
table: "LoginRecords",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Messages_GroupId",
table: "Messages",
column: "GroupId");
migrationBuilder.CreateIndex(
name: "IX_Messages_ReceiverId",
table: "Messages",
column: "ReceiverId");
migrationBuilder.CreateIndex(
name: "IX_Messages_SenderId",
table: "Messages",
column: "SenderId");
migrationBuilder.CreateIndex(
name: "IX_Notifications_UserId",
table: "Notifications",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_userProfileHistories_UserId",
table: "userProfileHistories",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Files");
migrationBuilder.DropTable(
name: "Friends");
migrationBuilder.DropTable(
name: "GroupMembers");
migrationBuilder.DropTable(
name: "LoginRecords");
migrationBuilder.DropTable(
name: "Notifications");
migrationBuilder.DropTable(
name: "userProfileHistories");
migrationBuilder.DropTable(
name: "Messages");
migrationBuilder.DropTable(
name: "Groups");
migrationBuilder.DropColumn(
name: "AvatarUrl",
table: "Users");
migrationBuilder.DropColumn(
name: "Email",
table: "Users");
migrationBuilder.DropColumn(
name: "IsOnline",
table: "Users");
migrationBuilder.DropColumn(
name: "PasswordHash",
table: "Users");
migrationBuilder.RenameColumn(
name: "Username",
table: "Users",
newName: "Password");
migrationBuilder.RenameColumn(
name: "Signature",
table: "Users",
newName: "Name");
migrationBuilder.RenameColumn(
name: "LastActive",
table: "Users",
newName: "LastModifiedDate");
migrationBuilder.RenameColumn(
name: "CreatedAt",
table: "Users",
newName: "CreatedDate");
}
}
}