using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Infrastructure.Migrations
{
  public partial class AddCreatedBy : Migration
  {
    protected override void Up(MigrationBuilder migrationBuilder)
    {
      migrationBuilder.Sql("DELETE FROM Comments;");
      migrationBuilder.Sql("DELETE FROM Links;");

      migrationBuilder.AddColumn<Guid>(
          name: "CreatedBy",
          table: "Links",
          type: "TEXT",
          nullable: false,
          defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

      migrationBuilder.AddColumn<Guid>(
          name: "CreatedBy",
          table: "Comments",
          type: "TEXT",
          nullable: false,
          defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

      migrationBuilder.CreateIndex(
          name: "IX_Links_CreatedBy",
          table: "Links",
          column: "CreatedBy");

      migrationBuilder.CreateIndex(
          name: "IX_Comments_CreatedBy",
          table: "Comments",
          column: "CreatedBy");

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

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

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

      migrationBuilder.DropForeignKey(
          name: "FK_Links_AspNetUsers_CreatedBy",
          table: "Links");

      migrationBuilder.DropIndex(
          name: "IX_Links_CreatedBy",
          table: "Links");

      migrationBuilder.DropIndex(
          name: "IX_Comments_CreatedBy",
          table: "Comments");

      migrationBuilder.DropColumn(
          name: "CreatedBy",
          table: "Links");

      migrationBuilder.DropColumn(
          name: "CreatedBy",
          table: "Comments");
    }
  }
}
