using Microsoft.EntityFrameworkCore.Migrations;

namespace isndhost.Migrations
{
    public partial class pkgverkeypp : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "PackageVersionCommmit");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PackageVersions",
                table: "PackageVersions");

            migrationBuilder.AlterColumn<string>(
                name: "Type",
                table: "PackageVersions",
                maxLength: 256,
                nullable: true,
                oldClrType: typeof(string),
                oldMaxLength: 256);

            migrationBuilder.AddPrimaryKey(
                name: "PK_PackageVersions",
                table: "PackageVersions",
                column: "FullString");

            migrationBuilder.CreateIndex(
                name: "IX_PackageVersions_PackageId",
                table: "PackageVersions",
                column: "PackageId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropPrimaryKey(
                name: "PK_PackageVersions",
                table: "PackageVersions");

            migrationBuilder.DropIndex(
                name: "IX_PackageVersions_PackageId",
                table: "PackageVersions");

            migrationBuilder.AlterColumn<string>(
                name: "Type",
                table: "PackageVersions",
                maxLength: 256,
                nullable: false,
                oldClrType: typeof(string),
                oldMaxLength: 256,
                oldNullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_PackageVersions",
                table: "PackageVersions",
                columns: new[] { "PackageId", "FullString", "Type" });

            migrationBuilder.CreateTable(
                name: "PackageVersionCommmit",
                columns: table => new
                {
                    CommitId = table.Column<long>(nullable: false),
                    PackageId = table.Column<string>(maxLength: 1024, nullable: false),
                    FullString = table.Column<string>(maxLength: 256, nullable: false),
                    PackageType = table.Column<string>(maxLength: 256, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PackageVersionCommmit", x => new { x.CommitId, x.PackageId, x.FullString, x.PackageType });
                    table.ForeignKey(
                        name: "FK_PackageVersionCommmit_Commits_CommitId",
                        column: x => x.CommitId,
                        principalTable: "Commits",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_PackageVersionCommmit_Packages_PackageId",
                        column: x => x.PackageId,
                        principalTable: "Packages",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_PackageVersionCommmit_PackageVersions_PackageId_FullString_~",
                        columns: x => new { x.PackageId, x.FullString, x.PackageType },
                        principalTable: "PackageVersions",
                        principalColumns: new[] { "PackageId", "FullString", "Type" },
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_PackageVersionCommmit_PackageId_FullString_PackageType",
                table: "PackageVersionCommmit",
                columns: new[] { "PackageId", "FullString", "PackageType" });
        }
    }
}
