using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

namespace isndhost.Migrations
{
    public partial class versionCommit : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<long>(
                name: "CommitNId",
                table: "Packages",
                nullable: false,
                defaultValue: 0L);

            migrationBuilder.AddColumn<DateTime>(
                name: "CommitTimeStamp",
                table: "Packages",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            migrationBuilder.AddColumn<bool>(
                name: "Public",
                table: "Packages",
                nullable: false,
                defaultValue: false);

            migrationBuilder.CreateTable(
                name: "Commits",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
                    TimeStamp = table.Column<DateTime>(nullable: false),
                    Action = table.Column<int>(nullable: false),
                    PackageVersionId = table.Column<string>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Commits", x => x.Id);
                });

            migrationBuilder.Sql(
                @"delete from ""PackageVersions"""
                );

            migrationBuilder.Sql(
                @"delete from ""Packages"";"
                );

            migrationBuilder.CreateIndex(
                name: "IX_Packages_CommitNId",
                table: "Packages",
                column: "CommitNId");

            migrationBuilder.AddForeignKey(
                name: "FK_Packages_Commits_CommitNId",
                table: "Packages",
                column: "CommitNId",
                principalTable: "Commits",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

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

            migrationBuilder.DropTable(
                name: "Commits");

            migrationBuilder.DropIndex(
                name: "IX_Packages_CommitNId",
                table: "Packages");

            migrationBuilder.DropColumn(
                name: "CommitNId",
                table: "Packages");

            migrationBuilder.DropColumn(
                name: "CommitTimeStamp",
                table: "Packages");

            migrationBuilder.DropColumn(
                name: "Public",
                table: "Packages");
        }
    }
}
