song-of-the-day/song_of_the_day/Data/Migrations/20250720144512_explicitly model liked songs relationship.cs

81 lines
2.6 KiB
C#

using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace song_of_the_day.DataMigrations
{
/// <inheritdoc />
public partial class explicitlymodellikedsongsrelationship : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Songs_Users_UserId",
table: "Songs");
migrationBuilder.DropIndex(
name: "IX_Songs_UserId",
table: "Songs");
migrationBuilder.DropColumn(
name: "UserId",
table: "Songs");
migrationBuilder.CreateTable(
name: "LikedSongs",
columns: table => new
{
SongId = table.Column<int>(type: "integer", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_LikedSongs", x => new { x.SongId, x.UserId });
table.ForeignKey(
name: "FK_LikedSongs_Songs_SongId",
column: x => x.SongId,
principalTable: "Songs",
principalColumn: "SongId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_LikedSongs_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "UserId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_LikedSongs_UserId",
table: "LikedSongs",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "LikedSongs");
migrationBuilder.AddColumn<int>(
name: "UserId",
table: "Songs",
type: "integer",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_Songs_UserId",
table: "Songs",
column: "UserId");
migrationBuilder.AddForeignKey(
name: "FK_Songs_Users_UserId",
table: "Songs",
column: "UserId",
principalTable: "Users",
principalColumn: "UserId");
}
}
}