qtc-net-server/qtc-net-server/Migrations/20250608203855_RefreshTokensForeignKey.cs
2025-06-15 14:24:53 -07:00

227 lines
7.1 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace qtc_api.Migrations
{
/// <inheritdoc />
public partial class RefreshTokensForeignKey : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Rooms");
migrationBuilder.DropPrimaryKey(
name: "PK_ValidRefreshTokens",
table: "ValidRefreshTokens");
migrationBuilder.DropPrimaryKey(
name: "PK_Users",
table: "Users");
migrationBuilder.DropPrimaryKey(
name: "PK_Contacts",
table: "Contacts");
migrationBuilder.RenameTable(
name: "ValidRefreshTokens",
newName: "RefreshToken");
migrationBuilder.RenameTable(
name: "Users",
newName: "User");
migrationBuilder.RenameTable(
name: "Contacts",
newName: "Contact");
migrationBuilder.AlterColumn<string>(
name: "UserID",
table: "RefreshToken",
type: "varchar(255)",
nullable: false,
oldClrType: typeof(string),
oldType: "longtext");
migrationBuilder.AlterColumn<string>(
name: "UserId",
table: "Contact",
type: "varchar(255)",
nullable: false,
oldClrType: typeof(string),
oldType: "longtext");
migrationBuilder.AlterColumn<string>(
name: "OwnerId",
table: "Contact",
type: "varchar(255)",
nullable: false,
oldClrType: typeof(string),
oldType: "longtext");
migrationBuilder.AddPrimaryKey(
name: "PK_RefreshToken",
table: "RefreshToken",
column: "ID");
migrationBuilder.AddPrimaryKey(
name: "PK_User",
table: "User",
column: "Id");
migrationBuilder.AddPrimaryKey(
name: "PK_Contact",
table: "Contact",
column: "Id");
migrationBuilder.CreateIndex(
name: "IX_RefreshToken_UserID",
table: "RefreshToken",
column: "UserID");
migrationBuilder.CreateIndex(
name: "IX_Contact_OwnerId",
table: "Contact",
column: "OwnerId");
migrationBuilder.CreateIndex(
name: "IX_Contact_UserId",
table: "Contact",
column: "UserId");
migrationBuilder.AddForeignKey(
name: "FK_Contact_User_OwnerId",
table: "Contact",
column: "OwnerId",
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Contact_User_UserId",
table: "Contact",
column: "UserId",
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_RefreshToken_User_UserID",
table: "RefreshToken",
column: "UserID",
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Contact_User_OwnerId",
table: "Contact");
migrationBuilder.DropForeignKey(
name: "FK_Contact_User_UserId",
table: "Contact");
migrationBuilder.DropForeignKey(
name: "FK_RefreshToken_User_UserID",
table: "RefreshToken");
migrationBuilder.DropPrimaryKey(
name: "PK_User",
table: "User");
migrationBuilder.DropPrimaryKey(
name: "PK_RefreshToken",
table: "RefreshToken");
migrationBuilder.DropIndex(
name: "IX_RefreshToken_UserID",
table: "RefreshToken");
migrationBuilder.DropPrimaryKey(
name: "PK_Contact",
table: "Contact");
migrationBuilder.DropIndex(
name: "IX_Contact_OwnerId",
table: "Contact");
migrationBuilder.DropIndex(
name: "IX_Contact_UserId",
table: "Contact");
migrationBuilder.RenameTable(
name: "User",
newName: "Users");
migrationBuilder.RenameTable(
name: "RefreshToken",
newName: "ValidRefreshTokens");
migrationBuilder.RenameTable(
name: "Contact",
newName: "Contacts");
migrationBuilder.AlterColumn<string>(
name: "UserID",
table: "ValidRefreshTokens",
type: "longtext",
nullable: false,
oldClrType: typeof(string),
oldType: "varchar(255)");
migrationBuilder.AlterColumn<string>(
name: "UserId",
table: "Contacts",
type: "longtext",
nullable: false,
oldClrType: typeof(string),
oldType: "varchar(255)");
migrationBuilder.AlterColumn<string>(
name: "OwnerId",
table: "Contacts",
type: "longtext",
nullable: false,
oldClrType: typeof(string),
oldType: "varchar(255)");
migrationBuilder.AddPrimaryKey(
name: "PK_Users",
table: "Users",
column: "Id");
migrationBuilder.AddPrimaryKey(
name: "PK_ValidRefreshTokens",
table: "ValidRefreshTokens",
column: "ID");
migrationBuilder.AddPrimaryKey(
name: "PK_Contacts",
table: "Contacts",
column: "Id");
migrationBuilder.CreateTable(
name: "Rooms",
columns: table => new
{
Id = table.Column<string>(type: "varchar(255)", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
CreatorId = table.Column<string>(type: "longtext", nullable: false),
Name = table.Column<string>(type: "longtext", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Rooms", x => x.Id);
})
.Annotation("MySQL:Charset", "utf8mb4");
}
}
}