using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Sledgemapper.Api.Migrations
{
    public partial class ChangeCompanyId : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Maps_Campaigns_CampaignId",
                table: "Maps");

            migrationBuilder.DropIndex(
                name: "IX_Maps_CampaignId",
                table: "Maps");

            migrationBuilder.DropColumn(
                name: "Username",
                table: "Users");

            migrationBuilder.AddColumn<Guid>(
                name: "CampaignId1",
                table: "Maps",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "CampaignsCampaignId",
                table: "CampaignUser",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(int),
                oldType: "INTEGER");

            migrationBuilder.AlterColumn<Guid>(
                name: "CampaignId",
                table: "Campaigns",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(int),
                oldType: "INTEGER")
                .OldAnnotation("Sqlite:Autoincrement", true);

            migrationBuilder.CreateIndex(
                name: "IX_Maps_CampaignId1",
                table: "Maps",
                column: "CampaignId1");

            migrationBuilder.AddForeignKey(
                name: "FK_Maps_Campaigns_CampaignId1",
                table: "Maps",
                column: "CampaignId1",
                principalTable: "Campaigns",
                principalColumn: "CampaignId",
                onDelete: ReferentialAction.Restrict);
        }

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

            migrationBuilder.DropIndex(
                name: "IX_Maps_CampaignId1",
                table: "Maps");

            migrationBuilder.DropColumn(
                name: "CampaignId1",
                table: "Maps");

            migrationBuilder.AddColumn<string>(
                name: "Username",
                table: "Users",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AlterColumn<int>(
                name: "CampaignsCampaignId",
                table: "CampaignUser",
                type: "INTEGER",
                nullable: false,
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AlterColumn<int>(
                name: "CampaignId",
                table: "Campaigns",
                type: "INTEGER",
                nullable: false,
                oldClrType: typeof(Guid),
                oldType: "TEXT")
                .Annotation("Sqlite:Autoincrement", true);

            migrationBuilder.CreateIndex(
                name: "IX_Maps_CampaignId",
                table: "Maps",
                column: "CampaignId");

            migrationBuilder.AddForeignKey(
                name: "FK_Maps_Campaigns_CampaignId",
                table: "Maps",
                column: "CampaignId",
                principalTable: "Campaigns",
                principalColumn: "CampaignId",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
