using Microsoft.EntityFrameworkCore.Migrations;

namespace Infrastructure.Migrations
{
  public partial class AddUserToVote : Migration
  {
    protected override void Up(MigrationBuilder migrationBuilder)
    {
      migrationBuilder.Sql("DELETE FROM link_votes; DELETE FROM comment_votes;");

      migrationBuilder.RenameColumn(
          name: "Id",
          table: "link_votes",
          newName: "CreatedBy");

      migrationBuilder.RenameColumn(
          name: "Id",
          table: "comment_votes",
          newName: "CreatedBy");

      migrationBuilder.CreateIndex(
          name: "IX_link_votes_CreatedBy",
          table: "link_votes",
          column: "CreatedBy");

      migrationBuilder.CreateIndex(
          name: "IX_comment_votes_CreatedBy",
          table: "comment_votes",
          column: "CreatedBy");

      migrationBuilder.AddForeignKey(
          name: "FK_comment_votes_AspNetUsers_CreatedBy",
          table: "comment_votes",
          column: "CreatedBy",
          principalTable: "AspNetUsers",
          principalColumn: "Id",
          onDelete: ReferentialAction.Cascade);

      migrationBuilder.AddForeignKey(
          name: "FK_link_votes_AspNetUsers_CreatedBy",
          table: "link_votes",
          column: "CreatedBy",
          principalTable: "AspNetUsers",
          principalColumn: "Id",
          onDelete: ReferentialAction.Cascade);
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
      migrationBuilder.DropForeignKey(
          name: "FK_comment_votes_AspNetUsers_CreatedBy",
          table: "comment_votes");

      migrationBuilder.DropForeignKey(
          name: "FK_link_votes_AspNetUsers_CreatedBy",
          table: "link_votes");

      migrationBuilder.DropIndex(
          name: "IX_link_votes_CreatedBy",
          table: "link_votes");

      migrationBuilder.DropIndex(
          name: "IX_comment_votes_CreatedBy",
          table: "comment_votes");

      migrationBuilder.RenameColumn(
          name: "CreatedBy",
          table: "link_votes",
          newName: "Id");

      migrationBuilder.RenameColumn(
          name: "CreatedBy",
          table: "comment_votes",
          newName: "Id");
    }
  }
}
