using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace MaBibli.Api.Data.Migrations
{
    /// <inheritdoc />
    public partial class Revues : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Revues",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Titre = table.Column<string>(type: "TEXT", nullable: false),
                    TitreNormalise = table.Column<string>(type: "TEXT", nullable: false),
                    Issn = table.Column<string>(type: "TEXT", nullable: true),
                    Editeur = table.Column<string>(type: "TEXT", nullable: true),
                    DateAjout = table.Column<DateTime>(type: "TEXT", nullable: false),
                    AjoutePar = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Revues", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "NumerosRevue",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    RevueId = table.Column<int>(type: "INTEGER", nullable: false),
                    Numero = table.Column<string>(type: "TEXT", nullable: false),
                    NumeroNormalise = table.Column<string>(type: "TEXT", nullable: false),
                    DateParution = table.Column<DateTime>(type: "TEXT", nullable: true),
                    Note = table.Column<string>(type: "TEXT", nullable: true),
                    DateAjout = table.Column<DateTime>(type: "TEXT", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_NumerosRevue", x => x.Id);
                    table.ForeignKey(
                        name: "FK_NumerosRevue_Revues_RevueId",
                        column: x => x.RevueId,
                        principalTable: "Revues",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_NumerosRevue_RevueId_NumeroNormalise",
                table: "NumerosRevue",
                columns: new[] { "RevueId", "NumeroNormalise" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Revues_Issn",
                table: "Revues",
                column: "Issn",
                unique: true,
                filter: "\"Issn\" IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_Revues_TitreNormalise",
                table: "Revues",
                column: "TitreNormalise",
                unique: true);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "NumerosRevue");

            migrationBuilder.DropTable(
                name: "Revues");
        }
    }
}
