using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFrameworkCore.Data.Migrations
{
///
public partial class AddRelationshipConstraints : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "TeamId",
table: "Coaches");
migrationBuilder.AlterColumn(
name: "LeagueId",
table: "Teams",
type: "INTEGER",
nullable: true,
oldClrType: typeof(int),
oldType: "INTEGER");
migrationBuilder.AddColumn(
name: "AwayTeamScore",
table: "Matches",
type: "INTEGER",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn(
name: "HomeTeamScore",
table: "Matches",
type: "INTEGER",
nullable: false,
defaultValue: 0);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 1,
column: "LeagueId",
value: null);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 2,
column: "LeagueId",
value: null);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 3,
column: "LeagueId",
value: null);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 4,
column: "LeagueId",
value: null);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 5,
column: "LeagueId",
value: null);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 6,
column: "LeagueId",
value: null);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 7,
column: "LeagueId",
value: null);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 8,
column: "LeagueId",
value: null);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 9,
column: "LeagueId",
value: null);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 10,
column: "LeagueId",
value: null);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 11,
column: "LeagueId",
value: null);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 12,
column: "LeagueId",
value: null);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 13,
column: "LeagueId",
value: null);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 14,
column: "LeagueId",
value: null);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 15,
column: "LeagueId",
value: null);
migrationBuilder.CreateIndex(
name: "IX_Teams_CoachId",
table: "Teams",
column: "CoachId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Teams_LeagueId",
table: "Teams",
column: "LeagueId");
migrationBuilder.CreateIndex(
name: "IX_Teams_Name",
table: "Teams",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Matches_AwayTeamId",
table: "Matches",
column: "AwayTeamId");
migrationBuilder.CreateIndex(
name: "IX_Matches_HomeTeamId",
table: "Matches",
column: "HomeTeamId");
migrationBuilder.AddForeignKey(
name: "FK_Matches_Teams_AwayTeamId",
table: "Matches",
column: "AwayTeamId",
principalTable: "Teams",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_Matches_Teams_HomeTeamId",
table: "Matches",
column: "HomeTeamId",
principalTable: "Teams",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_Teams_Coaches_CoachId",
table: "Teams",
column: "CoachId",
principalTable: "Coaches",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Teams_Leagues_LeagueId",
table: "Teams",
column: "LeagueId",
principalTable: "Leagues",
principalColumn: "Id");
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Matches_Teams_AwayTeamId",
table: "Matches");
migrationBuilder.DropForeignKey(
name: "FK_Matches_Teams_HomeTeamId",
table: "Matches");
migrationBuilder.DropForeignKey(
name: "FK_Teams_Coaches_CoachId",
table: "Teams");
migrationBuilder.DropForeignKey(
name: "FK_Teams_Leagues_LeagueId",
table: "Teams");
migrationBuilder.DropIndex(
name: "IX_Teams_CoachId",
table: "Teams");
migrationBuilder.DropIndex(
name: "IX_Teams_LeagueId",
table: "Teams");
migrationBuilder.DropIndex(
name: "IX_Teams_Name",
table: "Teams");
migrationBuilder.DropIndex(
name: "IX_Matches_AwayTeamId",
table: "Matches");
migrationBuilder.DropIndex(
name: "IX_Matches_HomeTeamId",
table: "Matches");
migrationBuilder.DropColumn(
name: "AwayTeamScore",
table: "Matches");
migrationBuilder.DropColumn(
name: "HomeTeamScore",
table: "Matches");
migrationBuilder.AlterColumn(
name: "LeagueId",
table: "Teams",
type: "INTEGER",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "INTEGER",
oldNullable: true);
migrationBuilder.AddColumn(
name: "TeamId",
table: "Coaches",
type: "INTEGER",
nullable: true);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 1,
column: "LeagueId",
value: 0);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 2,
column: "LeagueId",
value: 0);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 3,
column: "LeagueId",
value: 0);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 4,
column: "LeagueId",
value: 0);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 5,
column: "LeagueId",
value: 0);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 6,
column: "LeagueId",
value: 0);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 7,
column: "LeagueId",
value: 0);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 8,
column: "LeagueId",
value: 0);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 9,
column: "LeagueId",
value: 0);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 10,
column: "LeagueId",
value: 0);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 11,
column: "LeagueId",
value: 0);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 12,
column: "LeagueId",
value: 0);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 13,
column: "LeagueId",
value: 0);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 14,
column: "LeagueId",
value: 0);
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 15,
column: "LeagueId",
value: 0);
}
}
}