using Microsoft.EntityFrameworkCore.Migrations;

namespace ReallifeGamemode.Database.Migrations
{
  public partial class FactionVehiclesMultipleOwners : Migration
  {
    protected override void Up(MigrationBuilder migrationBuilder)
    {

      migrationBuilder.AddColumn<string>(
          name: "Owners",
          table: "ServerVehicles",
          nullable: true);

      migrationBuilder.Sql("UPDATE servervehicles SET Owners = CONCAT('[', FactionId, ']') WHERE FactionId IS NOT NULL");

      migrationBuilder.DropForeignKey(
          name: "FK_ServerVehicles_Factions_FactionId",
          table: "ServerVehicles");

      migrationBuilder.DropIndex(
          name: "IX_ServerVehicles_FactionId",
          table: "ServerVehicles");

      migrationBuilder.DropColumn(
          name: "FactionId",
          table: "ServerVehicles");
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
      migrationBuilder.DropColumn(
          name: "Owners",
          table: "ServerVehicles");

      migrationBuilder.AddColumn<int>(
          name: "FactionId",
          table: "ServerVehicles",
          nullable: true);

      migrationBuilder.CreateIndex(
          name: "IX_ServerVehicles_FactionId",
          table: "ServerVehicles",
          column: "FactionId");

      migrationBuilder.AddForeignKey(
          name: "FK_ServerVehicles_Factions_FactionId",
          table: "ServerVehicles",
          column: "FactionId",
          principalTable: "Factions",
          principalColumn: "Id",
          onDelete: ReferentialAction.Restrict);
    }
  }
}
