using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using NpgsqlTypes;

#nullable disable

namespace OpenArchival.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class InitalCreate : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "ArchiveCategories",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Name = table.Column<string>(type: "text", nullable: false),
                    Description = table.Column<string>(type: "text", nullable: true),
                    FieldSeparator = table.Column<string>(type: "text", nullable: false),
                    FieldNames = table.Column<List<string>>(type: "text[]", nullable: false),
                    FieldDescriptions = table.Column<List<string>>(type: "text[]", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArchiveCategories", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ArtifactAssociatedNames",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Value = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArtifactAssociatedNames", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ArtifactDefects",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Description = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArtifactDefects", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ArtifactEntryTags",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Name = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArtifactEntryTags", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ArtifactStorageLocations",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Location = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArtifactStorageLocations", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ArtifactTypes",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Name = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArtifactTypes", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "AspNetRoles",
                columns: table => new
                {
                    Id = table.Column<string>(type: "text", nullable: false),
                    Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
                    NormalizedName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AspNetRoles", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "AspNetUsers",
                columns: table => new
                {
                    Id = table.Column<string>(type: "text", nullable: false),
                    PermissionLevel = table.Column<string>(type: "text", nullable: false),
                    UserName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
                    NormalizedUserName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
                    Email = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
                    NormalizedEmail = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
                    EmailConfirmed = table.Column<bool>(type: "boolean", nullable: false),
                    PasswordHash = table.Column<string>(type: "text", nullable: true),
                    SecurityStamp = table.Column<string>(type: "text", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "text", nullable: true),
                    PhoneNumber = table.Column<string>(type: "text", nullable: true),
                    PhoneNumberConfirmed = table.Column<bool>(type: "boolean", nullable: false),
                    TwoFactorEnabled = table.Column<bool>(type: "boolean", nullable: false),
                    LockoutEnd = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
                    LockoutEnabled = table.Column<bool>(type: "boolean", nullable: false),
                    AccessFailedCount = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AspNetUsers", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "BlogPosts",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Title = table.Column<string>(type: "text", nullable: false),
                    Content = table.Column<string>(type: "text", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    ModifiedTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    ContentSearchVector = table.Column<NpgsqlTsVector>(type: "tsvector", nullable: false)
                        .Annotation("Npgsql:TsVectorConfig", "english")
                        .Annotation("Npgsql:TsVectorProperties", new[] { "Content" }),
                    TitleSearchVector = table.Column<NpgsqlTsVector>(type: "tsvector", nullable: false)
                        .Annotation("Npgsql:TsVectorConfig", "english")
                        .Annotation("Npgsql:TsVectorProperties", new[] { "Title" }),
                    TagsSearchString = table.Column<string>(type: "text", nullable: false),
                    TagsSearchVector = table.Column<NpgsqlTsVector>(type: "tsvector", nullable: false)
                        .Annotation("Npgsql:TsVectorConfig", "english")
                        .Annotation("Npgsql:TsVectorProperties", new[] { "TagsSearchString" }),
                    AllSearchString = table.Column<string>(type: "text", nullable: false),
                    AllSearchVector = table.Column<NpgsqlTsVector>(type: "tsvector", nullable: false)
                        .Annotation("Npgsql:TsVectorConfig", "english")
                        .Annotation("Npgsql:TsVectorProperties", new[] { "AllSearchString" })
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BlogPosts", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "BlogPostTags",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Name = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BlogPostTags", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SearchPageSliderEntries",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Title = table.Column<string>(type: "text", nullable: false),
                    Description = table.Column<string>(type: "text", nullable: false),
                    MaxCount = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SearchPageSliderEntries", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ArtifactGroupings",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    CategoryId = table.Column<int>(type: "integer", nullable: false),
                    Title = table.Column<string>(type: "text", nullable: false),
                    Description = table.Column<string>(type: "text", nullable: true),
                    TypeId = table.Column<int>(type: "integer", nullable: false),
                    IsPublicallyVisible = table.Column<bool>(type: "boolean", nullable: false),
                    AllSearchString = table.Column<string>(type: "text", nullable: false),
                    AllSearchVector = table.Column<NpgsqlTsVector>(type: "tsvector", nullable: true)
                        .Annotation("Npgsql:TsVectorConfig", "english")
                        .Annotation("Npgsql:TsVectorProperties", new[] { "AllSearchString" }),
                    TagsSearchString = table.Column<string>(type: "text", nullable: false),
                    TagsSearchVector = table.Column<NpgsqlTsVector>(type: "tsvector", nullable: true)
                        .Annotation("Npgsql:TsVectorConfig", "english")
                        .Annotation("Npgsql:TsVectorProperties", new[] { "TagsSearchString" }),
                    DefectsSearchString = table.Column<string>(type: "text", nullable: false),
                    DefectsSearchVector = table.Column<NpgsqlTsVector>(type: "tsvector", nullable: true)
                        .Annotation("Npgsql:TsVectorConfig", "english")
                        .Annotation("Npgsql:TsVectorProperties", new[] { "DefectsSearchString" }),
                    ListedNamesSearchString = table.Column<string>(type: "text", nullable: false),
                    ListedNamesSearchVector = table.Column<NpgsqlTsVector>(type: "tsvector", nullable: true)
                        .Annotation("Npgsql:TsVectorConfig", "english")
                        .Annotation("Npgsql:TsVectorProperties", new[] { "ListedNamesSearchString" }),
                    TitleSearchString = table.Column<string>(type: "text", nullable: false),
                    TitleSearchVector = table.Column<NpgsqlTsVector>(type: "tsvector", nullable: true)
                        .Annotation("Npgsql:TsVectorConfig", "english")
                        .Annotation("Npgsql:TsVectorProperties", new[] { "TitleSearchString" }),
                    DescriptionSearchString = table.Column<string>(type: "text", nullable: false),
                    DescriptionSearchVector = table.Column<NpgsqlTsVector>(type: "tsvector", nullable: true)
                        .Annotation("Npgsql:TsVectorConfig", "english")
                        .Annotation("Npgsql:TsVectorProperties", new[] { "DescriptionSearchString" }),
                    FilenamesSearchString = table.Column<string>(type: "text", nullable: false),
                    FilenamesSearchVector = table.Column<NpgsqlTsVector>(type: "tsvector", nullable: false)
                        .Annotation("Npgsql:TsVectorConfig", "english")
                        .Annotation("Npgsql:TsVectorProperties", new[] { "FilenamesSearchString" }),
                    FileContentSearchString = table.Column<string>(type: "text", nullable: false),
                    FileContentSearchVector = table.Column<NpgsqlTsVector>(type: "tsvector", nullable: false)
                        .Annotation("Npgsql:TsVectorConfig", "english")
                        .Annotation("Npgsql:TsVectorProperties", new[] { "FileContentSearchString" }),
                    IdentifierFields = table.Column<string>(type: "jsonb", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArtifactGroupings", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ArtifactGroupings_ArchiveCategories_CategoryId",
                        column: x => x.CategoryId,
                        principalTable: "ArchiveCategories",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ArtifactGroupings_ArtifactTypes_TypeId",
                        column: x => x.TypeId,
                        principalTable: "ArtifactTypes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AspNetRoleClaims",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    RoleId = table.Column<string>(type: "text", nullable: false),
                    ClaimType = table.Column<string>(type: "text", nullable: true),
                    ClaimValue = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
                        column: x => x.RoleId,
                        principalTable: "AspNetRoles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AspNetUserClaims",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    UserId = table.Column<string>(type: "text", nullable: false),
                    ClaimType = table.Column<string>(type: "text", nullable: true),
                    ClaimValue = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AspNetUserClaims_AspNetUsers_UserId",
                        column: x => x.UserId,
                        principalTable: "AspNetUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AspNetUserLogins",
                columns: table => new
                {
                    LoginProvider = table.Column<string>(type: "text", nullable: false),
                    ProviderKey = table.Column<string>(type: "text", nullable: false),
                    ProviderDisplayName = table.Column<string>(type: "text", nullable: true),
                    UserId = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
                    table.ForeignKey(
                        name: "FK_AspNetUserLogins_AspNetUsers_UserId",
                        column: x => x.UserId,
                        principalTable: "AspNetUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AspNetUserRoles",
                columns: table => new
                {
                    UserId = table.Column<string>(type: "text", nullable: false),
                    RoleId = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
                    table.ForeignKey(
                        name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
                        column: x => x.RoleId,
                        principalTable: "AspNetRoles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AspNetUserRoles_AspNetUsers_UserId",
                        column: x => x.UserId,
                        principalTable: "AspNetUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AspNetUserTokens",
                columns: table => new
                {
                    UserId = table.Column<string>(type: "text", nullable: false),
                    LoginProvider = table.Column<string>(type: "text", nullable: false),
                    Name = table.Column<string>(type: "text", nullable: false),
                    Value = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
                    table.ForeignKey(
                        name: "FK_AspNetUserTokens_AspNetUsers_UserId",
                        column: x => x.UserId,
                        principalTable: "AspNetUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "BlogPostViews",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    BlogPostId = table.Column<int>(type: "integer", nullable: false),
                    Views = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BlogPostViews", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BlogPostViews_BlogPosts_BlogPostId",
                        column: x => x.BlogPostId,
                        principalTable: "BlogPosts",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "BlogPostBlogPostTag",
                columns: table => new
                {
                    BlogPostsId = table.Column<int>(type: "integer", nullable: false),
                    TagsId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BlogPostBlogPostTag", x => new { x.BlogPostsId, x.TagsId });
                    table.ForeignKey(
                        name: "FK_BlogPostBlogPostTag_BlogPostTags_TagsId",
                        column: x => x.TagsId,
                        principalTable: "BlogPostTags",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_BlogPostBlogPostTag_BlogPosts_BlogPostsId",
                        column: x => x.BlogPostsId,
                        principalTable: "BlogPosts",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ArtifactEntryTagSearchPageSliderEntry",
                columns: table => new
                {
                    FilterTagsId = table.Column<int>(type: "integer", nullable: false),
                    SearchPageSlidersId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArtifactEntryTagSearchPageSliderEntry", x => new { x.FilterTagsId, x.SearchPageSlidersId });
                    table.ForeignKey(
                        name: "FK_ArtifactEntryTagSearchPageSliderEntry_ArtifactEntryTags_Fil~",
                        column: x => x.FilterTagsId,
                        principalTable: "ArtifactEntryTags",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ArtifactEntryTagSearchPageSliderEntry_SearchPageSliderEntri~",
                        column: x => x.SearchPageSlidersId,
                        principalTable: "SearchPageSliderEntries",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ArtifactEntries",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    ArtifactNumber = table.Column<string>(type: "text", nullable: true),
                    Title = table.Column<string>(type: "text", nullable: false),
                    Description = table.Column<string>(type: "text", nullable: true),
                    StorageLocationId = table.Column<int>(type: "integer", nullable: false),
                    AssociatedDates = table.Column<List<DateTime>>(type: "timestamp with time zone[]", nullable: true),
                    Links = table.Column<List<string>>(type: "text[]", nullable: true),
                    FileTextContent = table.Column<string>(type: "text", nullable: true),
                    TypeId = table.Column<int>(type: "integer", nullable: false),
                    IsPubliclyVisible = table.Column<bool>(type: "boolean", nullable: false),
                    Quantity = table.Column<int>(type: "integer", nullable: false),
                    ArtifactGroupingId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArtifactEntries", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ArtifactEntries_ArtifactGroupings_ArtifactGroupingId",
                        column: x => x.ArtifactGroupingId,
                        principalTable: "ArtifactGroupings",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ArtifactEntries_ArtifactStorageLocations_StorageLocationId",
                        column: x => x.StorageLocationId,
                        principalTable: "ArtifactStorageLocations",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ArtifactEntries_ArtifactTypes_TypeId",
                        column: x => x.TypeId,
                        principalTable: "ArtifactTypes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ArtifactGroupingBlogPost",
                columns: table => new
                {
                    ArtifactGroupingsId = table.Column<int>(type: "integer", nullable: false),
                    BlogPostsId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArtifactGroupingBlogPost", x => new { x.ArtifactGroupingsId, x.BlogPostsId });
                    table.ForeignKey(
                        name: "FK_ArtifactGroupingBlogPost_ArtifactGroupings_ArtifactGrouping~",
                        column: x => x.ArtifactGroupingsId,
                        principalTable: "ArtifactGroupings",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ArtifactGroupingBlogPost_BlogPosts_BlogPostsId",
                        column: x => x.BlogPostsId,
                        principalTable: "BlogPosts",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ArtifactGroupingViewCounts",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    ArtifactGroupingId = table.Column<int>(type: "integer", nullable: false),
                    Views = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArtifactGroupingViewCounts", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ArtifactGroupingViewCounts_ArtifactGroupings_ArtifactGroupi~",
                        column: x => x.ArtifactGroupingId,
                        principalTable: "ArtifactGroupings",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ArtifactDefectArtifactEntry",
                columns: table => new
                {
                    ArtifactEntriesId = table.Column<int>(type: "integer", nullable: false),
                    DefectsId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArtifactDefectArtifactEntry", x => new { x.ArtifactEntriesId, x.DefectsId });
                    table.ForeignKey(
                        name: "FK_ArtifactDefectArtifactEntry_ArtifactDefects_DefectsId",
                        column: x => x.DefectsId,
                        principalTable: "ArtifactDefects",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ArtifactDefectArtifactEntry_ArtifactEntries_ArtifactEntries~",
                        column: x => x.ArtifactEntriesId,
                        principalTable: "ArtifactEntries",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ArtifactEntryArtifactEntryTag",
                columns: table => new
                {
                    ArtifactEntriesId = table.Column<int>(type: "integer", nullable: false),
                    TagsId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArtifactEntryArtifactEntryTag", x => new { x.ArtifactEntriesId, x.TagsId });
                    table.ForeignKey(
                        name: "FK_ArtifactEntryArtifactEntryTag_ArtifactEntries_ArtifactEntri~",
                        column: x => x.ArtifactEntriesId,
                        principalTable: "ArtifactEntries",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ArtifactEntryArtifactEntryTag_ArtifactEntryTags_TagsId",
                        column: x => x.TagsId,
                        principalTable: "ArtifactEntryTags",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ArtifactEntryListedName",
                columns: table => new
                {
                    ArtifactEntriesId = table.Column<int>(type: "integer", nullable: false),
                    ListedNamesId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArtifactEntryListedName", x => new { x.ArtifactEntriesId, x.ListedNamesId });
                    table.ForeignKey(
                        name: "FK_ArtifactEntryListedName_ArtifactAssociatedNames_ListedNames~",
                        column: x => x.ListedNamesId,
                        principalTable: "ArtifactAssociatedNames",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ArtifactEntryListedName_ArtifactEntries_ArtifactEntriesId",
                        column: x => x.ArtifactEntriesId,
                        principalTable: "ArtifactEntries",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ArtifactFilePaths",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    ParentArtifactEntryId = table.Column<int>(type: "integer", nullable: true),
                    ParentBlogPostId = table.Column<int>(type: "integer", nullable: true),
                    OriginalName = table.Column<string>(type: "text", nullable: false),
                    Path = table.Column<string>(type: "text", nullable: false),
                    ArtifactGroupingId = table.Column<int>(type: "integer", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArtifactFilePaths", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ArtifactFilePaths_ArtifactEntries_ParentArtifactEntryId",
                        column: x => x.ParentArtifactEntryId,
                        principalTable: "ArtifactEntries",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ArtifactFilePaths_ArtifactGroupings_ArtifactGroupingId",
                        column: x => x.ArtifactGroupingId,
                        principalTable: "ArtifactGroupings",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_ArtifactFilePaths_BlogPosts_ParentBlogPostId",
                        column: x => x.ParentBlogPostId,
                        principalTable: "BlogPosts",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "ArtifactRelationships",
                columns: table => new
                {
                    RelatedById = table.Column<int>(type: "integer", nullable: false),
                    RelatedToId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArtifactRelationships", x => new { x.RelatedById, x.RelatedToId });
                    table.ForeignKey(
                        name: "FK_ArtifactRelationships_ArtifactEntries_RelatedById",
                        column: x => x.RelatedById,
                        principalTable: "ArtifactEntries",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ArtifactRelationships_ArtifactEntries_RelatedToId",
                        column: x => x.RelatedToId,
                        principalTable: "ArtifactEntries",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactDefectArtifactEntry_DefectsId",
                table: "ArtifactDefectArtifactEntry",
                column: "DefectsId");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactEntries_ArtifactGroupingId",
                table: "ArtifactEntries",
                column: "ArtifactGroupingId");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactEntries_StorageLocationId",
                table: "ArtifactEntries",
                column: "StorageLocationId");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactEntries_TypeId",
                table: "ArtifactEntries",
                column: "TypeId");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactEntryArtifactEntryTag_TagsId",
                table: "ArtifactEntryArtifactEntryTag",
                column: "TagsId");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactEntryListedName_ListedNamesId",
                table: "ArtifactEntryListedName",
                column: "ListedNamesId");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactEntryTagSearchPageSliderEntry_SearchPageSlidersId",
                table: "ArtifactEntryTagSearchPageSliderEntry",
                column: "SearchPageSlidersId");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactFilePaths_ArtifactGroupingId",
                table: "ArtifactFilePaths",
                column: "ArtifactGroupingId");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactFilePaths_ParentArtifactEntryId",
                table: "ArtifactFilePaths",
                column: "ParentArtifactEntryId");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactFilePaths_ParentBlogPostId",
                table: "ArtifactFilePaths",
                column: "ParentBlogPostId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactGroupingBlogPost_BlogPostsId",
                table: "ArtifactGroupingBlogPost",
                column: "BlogPostsId");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactGroupings_AllSearchVector",
                table: "ArtifactGroupings",
                column: "AllSearchVector")
                .Annotation("Npgsql:IndexMethod", "GIN");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactGroupings_CategoryId",
                table: "ArtifactGroupings",
                column: "CategoryId");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactGroupings_DefectsSearchVector",
                table: "ArtifactGroupings",
                column: "DefectsSearchVector")
                .Annotation("Npgsql:IndexMethod", "GIN");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactGroupings_DescriptionSearchVector",
                table: "ArtifactGroupings",
                column: "DescriptionSearchVector")
                .Annotation("Npgsql:IndexMethod", "GIN");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactGroupings_FileContentSearchVector",
                table: "ArtifactGroupings",
                column: "FileContentSearchVector")
                .Annotation("Npgsql:IndexMethod", "GIN");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactGroupings_FilenamesSearchVector",
                table: "ArtifactGroupings",
                column: "FilenamesSearchVector")
                .Annotation("Npgsql:IndexMethod", "GIN");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactGroupings_ListedNamesSearchVector",
                table: "ArtifactGroupings",
                column: "ListedNamesSearchVector")
                .Annotation("Npgsql:IndexMethod", "GIN");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactGroupings_TagsSearchVector",
                table: "ArtifactGroupings",
                column: "TagsSearchVector")
                .Annotation("Npgsql:IndexMethod", "GIN");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactGroupings_TitleSearchVector",
                table: "ArtifactGroupings",
                column: "TitleSearchVector")
                .Annotation("Npgsql:IndexMethod", "GIN");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactGroupings_TypeId",
                table: "ArtifactGroupings",
                column: "TypeId");

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactGroupingViewCounts_ArtifactGroupingId",
                table: "ArtifactGroupingViewCounts",
                column: "ArtifactGroupingId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ArtifactRelationships_RelatedToId",
                table: "ArtifactRelationships",
                column: "RelatedToId");

            migrationBuilder.CreateIndex(
                name: "IX_AspNetRoleClaims_RoleId",
                table: "AspNetRoleClaims",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "RoleNameIndex",
                table: "AspNetRoles",
                column: "NormalizedName",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_AspNetUserClaims_UserId",
                table: "AspNetUserClaims",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_AspNetUserLogins_UserId",
                table: "AspNetUserLogins",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_AspNetUserRoles_RoleId",
                table: "AspNetUserRoles",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "EmailIndex",
                table: "AspNetUsers",
                column: "NormalizedEmail");

            migrationBuilder.CreateIndex(
                name: "UserNameIndex",
                table: "AspNetUsers",
                column: "NormalizedUserName",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_BlogPostBlogPostTag_TagsId",
                table: "BlogPostBlogPostTag",
                column: "TagsId");

            migrationBuilder.CreateIndex(
                name: "IX_BlogPosts_AllSearchVector",
                table: "BlogPosts",
                column: "AllSearchVector")
                .Annotation("Npgsql:IndexMethod", "GIN");

            migrationBuilder.CreateIndex(
                name: "IX_BlogPosts_ContentSearchVector",
                table: "BlogPosts",
                column: "ContentSearchVector")
                .Annotation("Npgsql:IndexMethod", "GIN");

            migrationBuilder.CreateIndex(
                name: "IX_BlogPosts_TagsSearchVector",
                table: "BlogPosts",
                column: "TagsSearchVector")
                .Annotation("Npgsql:IndexMethod", "GIN");

            migrationBuilder.CreateIndex(
                name: "IX_BlogPosts_TitleSearchVector",
                table: "BlogPosts",
                column: "TitleSearchVector")
                .Annotation("Npgsql:IndexMethod", "GIN");

            migrationBuilder.CreateIndex(
                name: "IX_BlogPostViews_BlogPostId",
                table: "BlogPostViews",
                column: "BlogPostId",
                unique: true);
        }

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

            migrationBuilder.DropTable(
                name: "ArtifactEntryArtifactEntryTag");

            migrationBuilder.DropTable(
                name: "ArtifactEntryListedName");

            migrationBuilder.DropTable(
                name: "ArtifactEntryTagSearchPageSliderEntry");

            migrationBuilder.DropTable(
                name: "ArtifactFilePaths");

            migrationBuilder.DropTable(
                name: "ArtifactGroupingBlogPost");

            migrationBuilder.DropTable(
                name: "ArtifactGroupingViewCounts");

            migrationBuilder.DropTable(
                name: "ArtifactRelationships");

            migrationBuilder.DropTable(
                name: "AspNetRoleClaims");

            migrationBuilder.DropTable(
                name: "AspNetUserClaims");

            migrationBuilder.DropTable(
                name: "AspNetUserLogins");

            migrationBuilder.DropTable(
                name: "AspNetUserRoles");

            migrationBuilder.DropTable(
                name: "AspNetUserTokens");

            migrationBuilder.DropTable(
                name: "BlogPostBlogPostTag");

            migrationBuilder.DropTable(
                name: "BlogPostViews");

            migrationBuilder.DropTable(
                name: "ArtifactDefects");

            migrationBuilder.DropTable(
                name: "ArtifactAssociatedNames");

            migrationBuilder.DropTable(
                name: "ArtifactEntryTags");

            migrationBuilder.DropTable(
                name: "SearchPageSliderEntries");

            migrationBuilder.DropTable(
                name: "ArtifactEntries");

            migrationBuilder.DropTable(
                name: "AspNetRoles");

            migrationBuilder.DropTable(
                name: "AspNetUsers");

            migrationBuilder.DropTable(
                name: "BlogPostTags");

            migrationBuilder.DropTable(
                name: "BlogPosts");

            migrationBuilder.DropTable(
                name: "ArtifactGroupings");

            migrationBuilder.DropTable(
                name: "ArtifactStorageLocations");

            migrationBuilder.DropTable(
                name: "ArchiveCategories");

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