using Microsoft.EntityFrameworkCore.Migrations;

namespace isndhost.Migrations
{
    public partial class pkgVerCom : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<string>(
                name: "PackageId",
                table: "PackageVersions",
                maxLength: 1024,
                nullable: false,
                oldClrType: typeof(string));

            migrationBuilder.AlterColumn<string>(
                name: "Id",
                table: "Packages",
                maxLength: 1024,
                nullable: false,
                oldClrType: typeof(string));

            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" });
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "PackageVersionCommmit");

            migrationBuilder.AlterColumn<string>(
                name: "PackageId",
                table: "PackageVersions",
                nullable: false,
                oldClrType: typeof(string),
                oldMaxLength: 1024);

            migrationBuilder.AlterColumn<string>(
                name: "Id",
                table: "Packages",
                nullable: false,
                oldClrType: typeof(string),
                oldMaxLength: 1024);
        }
    }
}
