Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

52.2 KB
Raw Blame
// <auto-generated>
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace AliasClientDb.Migrations
{
    /// <inheritdoc />
    public partial class _210ManifestScopedStorage : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            /*
             * Every manifest-scoped table is rebuilt here to take its composite (ManifestId, Id) key, and the SQLite
             * provider emits those rebuilds in table-name order: a child is copied into its new shape before the
             * parent it names has the composite key that its foreign key resolves against, which SQLite rejects as a
             * foreign key mismatch even when the table is empty. Enforcement is off for the duration, the way the
             * provider itself brackets the drop-and-rename half of a rebuild. The next migration turns it back on.
             * The pragma is a no-op inside a transaction, hence suppressTransaction.
             */
            migrationBuilder.Sql("PRAGMA foreign_keys = OFF;", suppressTransaction: true);

            migrationBuilder.DropForeignKey(
                name: "FK_Attachments_Items_ItemId",
                table: "Attachments");

            migrationBuilder.DropForeignKey(
                name: "FK_FieldHistories_FieldDefinitions_FieldDefinitionId",
                table: "FieldHistories");

            migrationBuilder.DropForeignKey(
                name: "FK_FieldHistories_Items_ItemId",
                table: "FieldHistories");

            migrationBuilder.DropForeignKey(
                name: "FK_FieldValues_FieldDefinitions_FieldDefinitionId",
                table: "FieldValues");

            migrationBuilder.DropForeignKey(
                name: "FK_FieldValues_Items_ItemId",
                table: "FieldValues");

            migrationBuilder.DropForeignKey(
                name: "FK_Folders_Folders_ParentFolderId",
                table: "Folders");

            migrationBuilder.DropForeignKey(
                name: "FK_Items_Folders_FolderId",
                table: "Items");

            migrationBuilder.DropForeignKey(
                name: "FK_Items_Logos_LogoId",
                table: "Items");

            migrationBuilder.DropForeignKey(
                name: "FK_ItemTags_Items_ItemId",
                table: "ItemTags");

            migrationBuilder.DropForeignKey(
                name: "FK_ItemTags_Tags_TagId",
                table: "ItemTags");

            migrationBuilder.DropForeignKey(
                name: "FK_Passkeys_Items_ItemId",
                table: "Passkeys");

            migrationBuilder.DropForeignKey(
                name: "FK_TotpCodes_Items_ItemId",
                table: "TotpCodes");

            migrationBuilder.DropPrimaryKey(
                name: "PK_TotpCodes",
                table: "TotpCodes");

            migrationBuilder.DropIndex(
                name: "IX_TotpCodes_ItemId",
                table: "TotpCodes");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Tags",
                table: "Tags");

            migrationBuilder.DropIndex(
                name: "IX_Tags_Name",
                table: "Tags");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Settings",
                table: "Settings");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Passkeys",
                table: "Passkeys");

            migrationBuilder.DropIndex(
                name: "IX_Passkeys_ItemId",
                table: "Passkeys");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Logos",
                table: "Logos");

            migrationBuilder.DropIndex(
                name: "IX_Logos_Source",
                table: "Logos");

            migrationBuilder.DropPrimaryKey(
                name: "PK_ItemTags",
                table: "ItemTags");

            migrationBuilder.DropIndex(
                name: "IX_ItemTags_ItemId_TagId",
                table: "ItemTags");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Items",
                table: "Items");

            migrationBuilder.DropIndex(
                name: "IX_Items_FolderId",
                table: "Items");

            migrationBuilder.DropIndex(
                name: "IX_Items_LogoId",
                table: "Items");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Folders",
                table: "Folders");

            migrationBuilder.DropPrimaryKey(
                name: "PK_FieldValues",
                table: "FieldValues");

            migrationBuilder.DropPrimaryKey(
                name: "PK_FieldHistories",
                table: "FieldHistories");

            migrationBuilder.DropPrimaryKey(
                name: "PK_FieldDefinitions",
                table: "FieldDefinitions");

            migrationBuilder.DropPrimaryKey(
                name: "PK_EncryptionKeys",
                table: "EncryptionKeys");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Attachments",
                table: "Attachments");

            migrationBuilder.DropIndex(
                name: "IX_Attachments_ItemId",
                table: "Attachments");

            migrationBuilder.DropColumn(
                name: "Id",
                table: "ItemTags");

            migrationBuilder.AlterColumn<string>(
                name: "ItemId",
                table: "TotpCodes",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AlterColumn<string>(
                name: "Id",
                table: "TotpCodes",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AddColumn<string>(
                name: "ManifestId",
                table: "TotpCodes",
                type: "TEXT",
                nullable: false,
                defaultValue: "",
                collation: "NOCASE");

            migrationBuilder.AddColumn<string>(
                name: "Algorithm",
                table: "TotpCodes",
                type: "TEXT",
                maxLength: 20,
                nullable: false,
                defaultValue: "SHA1");

            migrationBuilder.AddColumn<int>(
                name: "Digits",
                table: "TotpCodes",
                type: "INTEGER",
                nullable: false,
                defaultValue: 6);

            migrationBuilder.AddColumn<int>(
                name: "Period",
                table: "TotpCodes",
                type: "INTEGER",
                nullable: false,
                defaultValue: 30);

            migrationBuilder.AlterColumn<string>(
                name: "Id",
                table: "Tags",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AddColumn<string>(
                name: "ManifestId",
                table: "Tags",
                type: "TEXT",
                nullable: false,
                defaultValue: "",
                collation: "NOCASE");

            migrationBuilder.AddColumn<string>(
                name: "ManifestId",
                table: "Settings",
                type: "TEXT",
                nullable: false,
                defaultValue: "",
                collation: "NOCASE");

            migrationBuilder.AlterColumn<string>(
                name: "ItemId",
                table: "Passkeys",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AlterColumn<string>(
                name: "Id",
                table: "Passkeys",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AddColumn<string>(
                name: "ManifestId",
                table: "Passkeys",
                type: "TEXT",
                nullable: false,
                defaultValue: "",
                collation: "NOCASE");

            migrationBuilder.AddColumn<byte[]>(
                name: "CredentialId",
                table: "Passkeys",
                type: "BLOB",
                maxLength: 1023,
                nullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Id",
                table: "Logos",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AddColumn<string>(
                name: "ManifestId",
                table: "Logos",
                type: "TEXT",
                nullable: false,
                defaultValue: "",
                collation: "NOCASE");

            migrationBuilder.AddColumn<string>(
                name: "Kind",
                table: "Logos",
                type: "TEXT",
                maxLength: 20,
                nullable: false,
                defaultValue: "favicon");

            migrationBuilder.AddColumn<string>(
                name: "Name",
                table: "Logos",
                type: "TEXT",
                maxLength: 255,
                nullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "TagId",
                table: "ItemTags",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AlterColumn<string>(
                name: "ItemId",
                table: "ItemTags",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AddColumn<string>(
                name: "ManifestId",
                table: "ItemTags",
                type: "TEXT",
                nullable: false,
                defaultValue: "",
                collation: "NOCASE");

            migrationBuilder.AlterColumn<string>(
                name: "LogoId",
                table: "Items",
                type: "TEXT",
                nullable: true,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "FolderId",
                table: "Items",
                type: "TEXT",
                nullable: true,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Id",
                table: "Items",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AddColumn<string>(
                name: "ManifestId",
                table: "Items",
                type: "TEXT",
                nullable: false,
                defaultValue: "",
                collation: "NOCASE");

            migrationBuilder.AddColumn<DateTime>(
                name: "ArchivedAt",
                table: "Items",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "ParentFolderId",
                table: "Folders",
                type: "TEXT",
                nullable: true,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Id",
                table: "Folders",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AddColumn<string>(
                name: "ManifestId",
                table: "Folders",
                type: "TEXT",
                nullable: false,
                defaultValue: "",
                collation: "NOCASE");

            migrationBuilder.AlterColumn<string>(
                name: "ItemId",
                table: "FieldValues",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AlterColumn<string>(
                name: "FieldDefinitionId",
                table: "FieldValues",
                type: "TEXT",
                nullable: true,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Id",
                table: "FieldValues",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AddColumn<string>(
                name: "ManifestId",
                table: "FieldValues",
                type: "TEXT",
                nullable: false,
                defaultValue: "",
                collation: "NOCASE");

            migrationBuilder.AddColumn<bool>(
                name: "IsDisabled",
                table: "FieldValues",
                type: "INTEGER",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<int>(
                name: "ValueIndex",
                table: "FieldValues",
                type: "INTEGER",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AlterColumn<string>(
                name: "ItemId",
                table: "FieldHistories",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AlterColumn<string>(
                name: "FieldDefinitionId",
                table: "FieldHistories",
                type: "TEXT",
                nullable: true,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Id",
                table: "FieldHistories",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AddColumn<string>(
                name: "ManifestId",
                table: "FieldHistories",
                type: "TEXT",
                nullable: false,
                defaultValue: "",
                collation: "NOCASE");

            migrationBuilder.AlterColumn<string>(
                name: "Id",
                table: "FieldDefinitions",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AddColumn<string>(
                name: "ManifestId",
                table: "FieldDefinitions",
                type: "TEXT",
                nullable: false,
                defaultValue: "",
                collation: "NOCASE");

            migrationBuilder.AlterColumn<string>(
                name: "Id",
                table: "EncryptionKeys",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AddColumn<string>(
                name: "ManifestId",
                table: "EncryptionKeys",
                type: "TEXT",
                nullable: false,
                defaultValue: "",
                collation: "NOCASE");

            migrationBuilder.AlterColumn<string>(
                name: "ItemId",
                table: "Attachments",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AlterColumn<string>(
                name: "Id",
                table: "Attachments",
                type: "TEXT",
                nullable: false,
                collation: "NOCASE",
                oldClrType: typeof(Guid),
                oldType: "TEXT");

            migrationBuilder.AddColumn<string>(
                name: "ManifestId",
                table: "Attachments",
                type: "TEXT",
                nullable: false,
                defaultValue: "",
                collation: "NOCASE");

            migrationBuilder.AddPrimaryKey(
                name: "PK_TotpCodes",
                table: "TotpCodes",
                columns: new[] { "ManifestId", "Id" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_Tags",
                table: "Tags",
                columns: new[] { "ManifestId", "Id" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_Settings",
                table: "Settings",
                columns: new[] { "ManifestId", "Key" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_Passkeys",
                table: "Passkeys",
                columns: new[] { "ManifestId", "Id" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_Logos",
                table: "Logos",
                columns: new[] { "ManifestId", "Id" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_ItemTags",
                table: "ItemTags",
                columns: new[] { "ManifestId", "ItemId", "TagId" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_Items",
                table: "Items",
                columns: new[] { "ManifestId", "Id" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_Folders",
                table: "Folders",
                columns: new[] { "ManifestId", "Id" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_FieldValues",
                table: "FieldValues",
                columns: new[] { "ManifestId", "Id" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_FieldHistories",
                table: "FieldHistories",
                columns: new[] { "ManifestId", "Id" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_FieldDefinitions",
                table: "FieldDefinitions",
                columns: new[] { "ManifestId", "Id" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_EncryptionKeys",
                table: "EncryptionKeys",
                columns: new[] { "ManifestId", "Id" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_Attachments",
                table: "Attachments",
                columns: new[] { "ManifestId", "Id" });

            migrationBuilder.AlterColumn<byte[]>(
                name: "Blob",
                table: "Attachments",
                type: "BLOB",
                nullable: true,
                oldClrType: typeof(byte[]),
                oldType: "BLOB");

            migrationBuilder.AddColumn<string>(
                name: "FileDataHash",
                table: "Logos",
                type: "TEXT",
                maxLength: 64,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "BlobHash",
                table: "Attachments",
                type: "TEXT",
                maxLength: 64,
                nullable: true);

            migrationBuilder.CreateTable(
                name: "CodecOverflows",
                columns: table => new
                {
                    Id = table.Column<string>(type: "TEXT", nullable: false, collation: "NOCASE"),
                    Data = table.Column<string>(type: "TEXT", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CodecOverflows", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ItemStats",
                columns: table => new
                {
                    ManifestId = table.Column<string>(type: "TEXT", nullable: false, collation: "NOCASE"),
                    Id = table.Column<string>(type: "TEXT", nullable: false, collation: "NOCASE"),
                    DeviceId = table.Column<string>(type: "TEXT", nullable: false, defaultValue: "", collation: "NOCASE"),
                    LastUsedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UseCount = table.Column<int>(type: "INTEGER", nullable: false),
                    LastAutofilledAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    AutofillCount = table.Column<int>(type: "INTEGER", nullable: false),
                    LastCopiedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CopyCount = table.Column<int>(type: "INTEGER", nullable: false),
                    LastPasskeyAuthAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    PasskeyAuthCount = table.Column<int>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
                    IsDeleted = table.Column<bool>(type: "INTEGER", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ItemStats", x => new { x.ManifestId, x.Id, x.DeviceId });
                });

            migrationBuilder.CreateTable(
                name: "Manifests",
                columns: table => new
                {
                    Id = table.Column<string>(type: "TEXT", nullable: false, collation: "NOCASE"),
                    Name = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Manifests", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_TotpCodes_ManifestId_ItemId",
                table: "TotpCodes",
                columns: new[] { "ManifestId", "ItemId" });

            migrationBuilder.CreateIndex(
                name: "IX_Tags_ManifestId_Name",
                table: "Tags",
                columns: new[] { "ManifestId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Passkeys_ManifestId_ItemId",
                table: "Passkeys",
                columns: new[] { "ManifestId", "ItemId" });

            migrationBuilder.CreateIndex(
                name: "IX_Logos_ManifestId_Kind_Source",
                table: "Logos",
                columns: new[] { "ManifestId", "Kind", "Source" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ItemTags_ManifestId_TagId",
                table: "ItemTags",
                columns: new[] { "ManifestId", "TagId" });

            migrationBuilder.CreateIndex(
                name: "IX_Items_ManifestId_FolderId",
                table: "Items",
                columns: new[] { "ManifestId", "FolderId" });

            migrationBuilder.CreateIndex(
                name: "IX_Items_ManifestId_LogoId",
                table: "Items",
                columns: new[] { "ManifestId", "LogoId" });

            migrationBuilder.CreateIndex(
                name: "IX_Folders_ManifestId_ParentFolderId",
                table: "Folders",
                columns: new[] { "ManifestId", "ParentFolderId" });

            migrationBuilder.CreateIndex(
                name: "IX_FieldValues_ManifestId_FieldDefinitionId",
                table: "FieldValues",
                columns: new[] { "ManifestId", "FieldDefinitionId" });

            migrationBuilder.CreateIndex(
                name: "IX_FieldValues_ManifestId_ItemId",
                table: "FieldValues",
                columns: new[] { "ManifestId", "ItemId" });

            migrationBuilder.CreateIndex(
                name: "IX_FieldHistories_ManifestId_FieldDefinitionId",
                table: "FieldHistories",
                columns: new[] { "ManifestId", "FieldDefinitionId" });

            migrationBuilder.CreateIndex(
                name: "IX_FieldHistories_ManifestId_ItemId",
                table: "FieldHistories",
                columns: new[] { "ManifestId", "ItemId" });

            migrationBuilder.CreateIndex(
                name: "IX_EncryptionKeys_ManifestId_IsPrimary",
                table: "EncryptionKeys",
                columns: new[] { "ManifestId", "IsPrimary" });

            migrationBuilder.CreateIndex(
                name: "IX_Attachments_ManifestId_ItemId",
                table: "Attachments",
                columns: new[] { "ManifestId", "ItemId" });

            migrationBuilder.AddForeignKey(
                name: "FK_Attachments_Items_ManifestId_ItemId",
                table: "Attachments",
                columns: new[] { "ManifestId", "ItemId" },
                principalTable: "Items",
                principalColumns: new[] { "ManifestId", "Id" },
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_FieldHistories_FieldDefinitions_ManifestId_FieldDefinitionId",
                table: "FieldHistories",
                columns: new[] { "ManifestId", "FieldDefinitionId" },
                principalTable: "FieldDefinitions",
                principalColumns: new[] { "ManifestId", "Id" },
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_FieldHistories_Items_ManifestId_ItemId",
                table: "FieldHistories",
                columns: new[] { "ManifestId", "ItemId" },
                principalTable: "Items",
                principalColumns: new[] { "ManifestId", "Id" },
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_FieldValues_FieldDefinitions_ManifestId_FieldDefinitionId",
                table: "FieldValues",
                columns: new[] { "ManifestId", "FieldDefinitionId" },
                principalTable: "FieldDefinitions",
                principalColumns: new[] { "ManifestId", "Id" },
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_FieldValues_Items_ManifestId_ItemId",
                table: "FieldValues",
                columns: new[] { "ManifestId", "ItemId" },
                principalTable: "Items",
                principalColumns: new[] { "ManifestId", "Id" },
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Folders_Folders_ManifestId_ParentFolderId",
                table: "Folders",
                columns: new[] { "ManifestId", "ParentFolderId" },
                principalTable: "Folders",
                principalColumns: new[] { "ManifestId", "Id" },
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Items_Folders_ManifestId_FolderId",
                table: "Items",
                columns: new[] { "ManifestId", "FolderId" },
                principalTable: "Folders",
                principalColumns: new[] { "ManifestId", "Id" });

            migrationBuilder.AddForeignKey(
                name: "FK_Items_Logos_ManifestId_LogoId",
                table: "Items",
                columns: new[] { "ManifestId", "LogoId" },
                principalTable: "Logos",
                principalColumns: new[] { "ManifestId", "Id" });

            migrationBuilder.AddForeignKey(
                name: "FK_ItemTags_Items_ManifestId_ItemId",
                table: "ItemTags",
                columns: new[] { "ManifestId", "ItemId" },
                principalTable: "Items",
                principalColumns: new[] { "ManifestId", "Id" },
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_ItemTags_Tags_ManifestId_TagId",
                table: "ItemTags",
                columns: new[] { "ManifestId", "TagId" },
                principalTable: "Tags",
                principalColumns: new[] { "ManifestId", "Id" },
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Passkeys_Items_ManifestId_ItemId",
                table: "Passkeys",
                columns: new[] { "ManifestId", "ItemId" },
                principalTable: "Items",
                principalColumns: new[] { "ManifestId", "Id" },
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_TotpCodes_Items_ManifestId_ItemId",
                table: "TotpCodes",
                columns: new[] { "ManifestId", "ItemId" },
                principalTable: "Items",
                principalColumns: new[] { "ManifestId", "Id" },
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Attachments_Items_ManifestId_ItemId",
                table: "Attachments");

            migrationBuilder.DropForeignKey(
                name: "FK_FieldHistories_FieldDefinitions_ManifestId_FieldDefinitionId",
                table: "FieldHistories");

            migrationBuilder.DropForeignKey(
                name: "FK_FieldHistories_Items_ManifestId_ItemId",
                table: "FieldHistories");

            migrationBuilder.DropForeignKey(
                name: "FK_FieldValues_FieldDefinitions_ManifestId_FieldDefinitionId",
                table: "FieldValues");

            migrationBuilder.DropForeignKey(
                name: "FK_FieldValues_Items_ManifestId_ItemId",
                table: "FieldValues");

            migrationBuilder.DropForeignKey(
                name: "FK_Folders_Folders_ManifestId_ParentFolderId",
                table: "Folders");

            migrationBuilder.DropForeignKey(
                name: "FK_Items_Folders_ManifestId_FolderId",
                table: "Items");

            migrationBuilder.DropForeignKey(
                name: "FK_Items_Logos_ManifestId_LogoId",
                table: "Items");

            migrationBuilder.DropForeignKey(
                name: "FK_ItemTags_Items_ManifestId_ItemId",
                table: "ItemTags");

            migrationBuilder.DropForeignKey(
                name: "FK_ItemTags_Tags_ManifestId_TagId",
                table: "ItemTags");

            migrationBuilder.DropForeignKey(
                name: "FK_Passkeys_Items_ManifestId_ItemId",
                table: "Passkeys");

            migrationBuilder.DropForeignKey(
                name: "FK_TotpCodes_Items_ManifestId_ItemId",
                table: "TotpCodes");

            migrationBuilder.DropTable(
                name: "CodecOverflows");

            migrationBuilder.DropTable(
                name: "ItemStats");

            migrationBuilder.DropTable(
                name: "Manifests");

            migrationBuilder.DropPrimaryKey(
                name: "PK_TotpCodes",
                table: "TotpCodes");

            migrationBuilder.DropIndex(
                name: "IX_TotpCodes_ManifestId_ItemId",
                table: "TotpCodes");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Tags",
                table: "Tags");

            migrationBuilder.DropIndex(
                name: "IX_Tags_ManifestId_Name",
                table: "Tags");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Settings",
                table: "Settings");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Passkeys",
                table: "Passkeys");

            migrationBuilder.DropIndex(
                name: "IX_Passkeys_ManifestId_ItemId",
                table: "Passkeys");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Logos",
                table: "Logos");

            migrationBuilder.DropIndex(
                name: "IX_Logos_ManifestId_Kind_Source",
                table: "Logos");

            migrationBuilder.DropPrimaryKey(
                name: "PK_ItemTags",
                table: "ItemTags");

            migrationBuilder.DropIndex(
                name: "IX_ItemTags_ManifestId_TagId",
                table: "ItemTags");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Items",
                table: "Items");

            migrationBuilder.DropIndex(
                name: "IX_Items_ManifestId_FolderId",
                table: "Items");

            migrationBuilder.DropIndex(
                name: "IX_Items_ManifestId_LogoId",
                table: "Items");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Folders",
                table: "Folders");

            migrationBuilder.DropIndex(
                name: "IX_Folders_ManifestId_ParentFolderId",
                table: "Folders");

            migrationBuilder.DropPrimaryKey(
                name: "PK_FieldValues",
                table: "FieldValues");

            migrationBuilder.DropIndex(
                name: "IX_FieldValues_ManifestId_FieldDefinitionId",
                table: "FieldValues");

            migrationBuilder.DropIndex(
                name: "IX_FieldValues_ManifestId_ItemId",
                table: "FieldValues");

            migrationBuilder.DropPrimaryKey(
                name: "PK_FieldHistories",
                table: "FieldHistories");

            migrationBuilder.DropIndex(
                name: "IX_FieldHistories_ManifestId_FieldDefinitionId",
                table: "FieldHistories");

            migrationBuilder.DropIndex(
                name: "IX_FieldHistories_ManifestId_ItemId",
                table: "FieldHistories");

            migrationBuilder.DropPrimaryKey(
                name: "PK_FieldDefinitions",
                table: "FieldDefinitions");

            migrationBuilder.DropPrimaryKey(
                name: "PK_EncryptionKeys",
                table: "EncryptionKeys");

            migrationBuilder.DropIndex(
                name: "IX_EncryptionKeys_ManifestId_IsPrimary",
                table: "EncryptionKeys");

            migrationBuilder.DropColumn(
                name: "FileDataHash",
                table: "Logos");

            migrationBuilder.DropColumn(
                name: "BlobHash",
                table: "Attachments");

            migrationBuilder.AlterColumn<byte[]>(
                name: "Blob",
                table: "Attachments",
                type: "BLOB",
                nullable: false,
                defaultValue: new byte[0],
                oldClrType: typeof(byte[]),
                oldType: "BLOB",
                oldNullable: true);

            migrationBuilder.DropPrimaryKey(
                name: "PK_Attachments",
                table: "Attachments");

            migrationBuilder.DropIndex(
                name: "IX_Attachments_ManifestId_ItemId",
                table: "Attachments");

            migrationBuilder.DropColumn(
                name: "ManifestId",
                table: "TotpCodes");

            migrationBuilder.DropColumn(
                name: "Algorithm",
                table: "TotpCodes");

            migrationBuilder.DropColumn(
                name: "Digits",
                table: "TotpCodes");

            migrationBuilder.DropColumn(
                name: "Period",
                table: "TotpCodes");

            migrationBuilder.DropColumn(
                name: "ManifestId",
                table: "Tags");

            migrationBuilder.DropColumn(
                name: "ManifestId",
                table: "Settings");

            migrationBuilder.DropColumn(
                name: "ManifestId",
                table: "Passkeys");

            migrationBuilder.DropColumn(
                name: "CredentialId",
                table: "Passkeys");

            migrationBuilder.DropColumn(
                name: "ManifestId",
                table: "Logos");

            migrationBuilder.DropColumn(
                name: "Kind",
                table: "Logos");

            migrationBuilder.DropColumn(
                name: "Name",
                table: "Logos");

            migrationBuilder.DropColumn(
                name: "ManifestId",
                table: "ItemTags");

            migrationBuilder.DropColumn(
                name: "ManifestId",
                table: "Items");

            migrationBuilder.DropColumn(
                name: "ArchivedAt",
                table: "Items");

            migrationBuilder.DropColumn(
                name: "ManifestId",
                table: "Folders");

            migrationBuilder.DropColumn(
                name: "ManifestId",
                table: "FieldValues");

            migrationBuilder.DropColumn(
                name: "IsDisabled",
                table: "FieldValues");

            migrationBuilder.DropColumn(
                name: "ValueIndex",
                table: "FieldValues");

            migrationBuilder.DropColumn(
                name: "ManifestId",
                table: "FieldHistories");

            migrationBuilder.DropColumn(
                name: "ManifestId",
                table: "FieldDefinitions");

            migrationBuilder.DropColumn(
                name: "ManifestId",
                table: "EncryptionKeys");

            migrationBuilder.DropColumn(
                name: "ManifestId",
                table: "Attachments");

            migrationBuilder.AlterColumn<Guid>(
                name: "ItemId",
                table: "TotpCodes",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "Id",
                table: "TotpCodes",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "Id",
                table: "Tags",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "ItemId",
                table: "Passkeys",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "Id",
                table: "Passkeys",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "Id",
                table: "Logos",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "TagId",
                table: "ItemTags",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "ItemId",
                table: "ItemTags",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AddColumn<Guid>(
                name: "Id",
                table: "ItemTags",
                type: "TEXT",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

            migrationBuilder.AlterColumn<Guid>(
                name: "LogoId",
                table: "Items",
                type: "TEXT",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldNullable: true,
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "FolderId",
                table: "Items",
                type: "TEXT",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldNullable: true,
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "Id",
                table: "Items",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "ParentFolderId",
                table: "Folders",
                type: "TEXT",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldNullable: true,
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "Id",
                table: "Folders",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "ItemId",
                table: "FieldValues",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "FieldDefinitionId",
                table: "FieldValues",
                type: "TEXT",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldNullable: true,
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "Id",
                table: "FieldValues",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "ItemId",
                table: "FieldHistories",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "FieldDefinitionId",
                table: "FieldHistories",
                type: "TEXT",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldNullable: true,
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "Id",
                table: "FieldHistories",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "Id",
                table: "FieldDefinitions",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "Id",
                table: "EncryptionKeys",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "ItemId",
                table: "Attachments",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AlterColumn<Guid>(
                name: "Id",
                table: "Attachments",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldCollation: "NOCASE");

            migrationBuilder.AddPrimaryKey(
                name: "PK_TotpCodes",
                table: "TotpCodes",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_Tags",
                table: "Tags",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_Settings",
                table: "Settings",
                column: "Key");

            migrationBuilder.AddPrimaryKey(
                name: "PK_Passkeys",
                table: "Passkeys",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_Logos",
                table: "Logos",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_ItemTags",
                table: "ItemTags",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_Items",
                table: "Items",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_Folders",
                table: "Folders",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_FieldValues",
                table: "FieldValues",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_FieldHistories",
                table: "FieldHistories",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_FieldDefinitions",
                table: "FieldDefinitions",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_EncryptionKeys",
                table: "EncryptionKeys",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_Attachments",
                table: "Attachments",
                column: "Id");

            migrationBuilder.CreateIndex(
                name: "IX_TotpCodes_ItemId",
                table: "TotpCodes",
                column: "ItemId");

            migrationBuilder.CreateIndex(
                name: "IX_Tags_Name",
                table: "Tags",
                column: "Name");

            migrationBuilder.CreateIndex(
                name: "IX_Passkeys_ItemId",
                table: "Passkeys",
                column: "ItemId");

            migrationBuilder.CreateIndex(
                name: "IX_Logos_Source",
                table: "Logos",
                column: "Source",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ItemTags_ItemId_TagId",
                table: "ItemTags",
                columns: new[] { "ItemId", "TagId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Items_FolderId",
                table: "Items",
                column: "FolderId");

            migrationBuilder.CreateIndex(
                name: "IX_Items_LogoId",
                table: "Items",
                column: "LogoId");

            migrationBuilder.CreateIndex(
                name: "IX_Attachments_ItemId",
                table: "Attachments",
                column: "ItemId");

            migrationBuilder.AddForeignKey(
                name: "FK_Attachments_Items_ItemId",
                table: "Attachments",
                column: "ItemId",
                principalTable: "Items",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_FieldHistories_FieldDefinitions_FieldDefinitionId",
                table: "FieldHistories",
                column: "FieldDefinitionId",
                principalTable: "FieldDefinitions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_FieldHistories_Items_ItemId",
                table: "FieldHistories",
                column: "ItemId",
                principalTable: "Items",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_FieldValues_FieldDefinitions_FieldDefinitionId",
                table: "FieldValues",
                column: "FieldDefinitionId",
                principalTable: "FieldDefinitions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_FieldValues_Items_ItemId",
                table: "FieldValues",
                column: "ItemId",
                principalTable: "Items",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Folders_Folders_ParentFolderId",
                table: "Folders",
                column: "ParentFolderId",
                principalTable: "Folders",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Items_Folders_FolderId",
                table: "Items",
                column: "FolderId",
                principalTable: "Folders",
                principalColumn: "Id",
                onDelete: ReferentialAction.SetNull);

            migrationBuilder.AddForeignKey(
                name: "FK_Items_Logos_LogoId",
                table: "Items",
                column: "LogoId",
                principalTable: "Logos",
                principalColumn: "Id",
                onDelete: ReferentialAction.SetNull);

            migrationBuilder.AddForeignKey(
                name: "FK_ItemTags_Items_ItemId",
                table: "ItemTags",
                column: "ItemId",
                principalTable: "Items",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_ItemTags_Tags_TagId",
                table: "ItemTags",
                column: "TagId",
                principalTable: "Tags",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Passkeys_Items_ItemId",
                table: "Passkeys",
                column: "ItemId",
                principalTable: "Items",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_TotpCodes_Items_ItemId",
                table: "TotpCodes",
                column: "ItemId",
                principalTable: "Items",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}