Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add reorder column migration (#2159)
Leendert de Borstc77456195fef
diff --git a/apps/server/AliasVault.Api/Program.cs b/apps/server/AliasVault.Api/Program.csindex 8f2c3baf1..efe3c1778 100644--- a/apps/server/AliasVault.Api/Program.cs+++ b/apps/server/AliasVault.Api/Program.cs@@ -221,6 +221,9 @@ using (var scope = app.Services.CreateScope()){var container = scope.ServiceProvider;await using var db = await container.GetRequiredService<IAliasServerDbContextFactory>().CreateDbContextAsync();++ // Raise the command timeout for migrations.+ db.Database.SetCommandTimeout((int)TimeSpan.FromMinutes(60).TotalSeconds);await db.Database.MigrateAsync();}diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260811194817_ReorderTableColumns.Designer.cs b/apps/server/Databases/AliasServerDb/Migrations/20260811194817_ReorderTableColumns.Designer.csnew file mode 100644index 000000000..9257e4374--- /dev/null+++ b/apps/server/Databases/AliasServerDb/Migrations/20260811194817_ReorderTableColumns.Designer.cs@@ -0,0 +1,1626 @@+// <auto-generated />+using System;+using AliasServerDb;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;++#nullable disable++namespace AliasServerDb.Migrations+{+ [DbContext(typeof(AliasServerDbContext))]+ [Migration("20260811194817_ReorderTableColumns")]+ partial class ReorderTableColumns+ {+ /// <inheritdoc />+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder+ .HasAnnotation("ProductVersion", "10.0.10")+ .HasAnnotation("Proxies:ChangeTracking", false)+ .HasAnnotation("Proxies:CheckEquality", false)+ .HasAnnotation("Proxies:LazyLoading", true)+ .HasAnnotation("Relational:MaxIdentifierLength", 63);++ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);++ modelBuilder.Entity("AliasServerDb.AdminUser", b =>+ {+ b.Property<string>("Id")+ .HasColumnType("text");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("integer");++ b.Property<string>("ConcurrencyStamp")+ .HasColumnType("text");++ b.Property<string>("Email")+ .HasColumnType("text");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("boolean");++ b.Property<DateTime?>("LastPasswordChanged")+ .HasColumnType("timestamp with time zone");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("boolean");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("NormalizedEmail")+ .HasColumnType("text");++ b.Property<string>("NormalizedUserName")+ .HasColumnType("text");++ b.Property<string>("PasswordHash")+ .HasColumnType("text");++ b.Property<string>("PhoneNumber")+ .HasColumnType("text");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("boolean");++ b.Property<string>("SecurityStamp")+ .HasColumnType("text");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("boolean");++ b.Property<string>("UserName")+ .HasColumnType("text");++ b.HasKey("Id");++ b.ToTable("AdminUsers");+ });++ modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>+ {+ b.Property<string>("Id")+ .HasColumnType("text");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("integer");++ b.Property<bool>("Blocked")+ .HasColumnType("boolean");++ b.Property<DateTime?>("BlockedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("ConcurrencyStamp")+ .HasColumnType("text");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("Email")+ .HasColumnType("text");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("boolean");++ b.Property<DateTime?>("LastActivityDate")+ .HasColumnType("timestamp with time zone");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("boolean");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("NormalizedEmail")+ .HasColumnType("text");++ b.Property<string>("NormalizedUserName")+ .HasColumnType("text");++ b.Property<DateTime>("PasswordChangedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("PasswordHash")+ .HasColumnType("text");++ b.Property<Guid>("PersonalGroupId")+ .HasColumnType("uuid");++ b.Property<string>("PhoneNumber")+ .HasColumnType("text");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("boolean");++ b.Property<string>("SecurityStamp")+ .HasColumnType("text");++ b.Property<string>("SrpIdentity")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("boolean");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("UserName")+ .HasColumnType("text");++ b.HasKey("Id");++ b.HasIndex("PersonalGroupId")+ .IsUnique()+ .HasDatabaseName("UX_AliasVaultUsers_PersonalGroupId");++ b.ToTable("AliasVaultUsers");+ });++ modelBuilder.Entity("AliasServerDb.AliasVaultUserRefreshToken", b =>+ {+ b.Property<Guid>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("uuid");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("DeviceIdentifier")+ .IsRequired()+ .HasColumnType("text");++ b.Property<DateTime>("ExpireDate")+ .HasMaxLength(255)+ .HasColumnType("timestamp with time zone");++ b.Property<string>("IpAddress")+ .HasMaxLength(45)+ .HasColumnType("character varying(45)");++ b.Property<string>("PreviousTokenValue")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<string>("UserId")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<string>("Value")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("AliasVaultUserRefreshTokens");+ });++ modelBuilder.Entity("AliasServerDb.AuthLog", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("integer");++ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));++ b.Property<string>("AdditionalInfo")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<string>("Browser")+ .HasMaxLength(100)+ .HasColumnType("character varying(100)");++ b.Property<string>("Client")+ .HasMaxLength(100)+ .HasColumnType("character varying(100)");++ b.Property<string>("Country")+ .HasMaxLength(50)+ .HasColumnType("character varying(50)");++ b.Property<string>("DeviceType")+ .HasMaxLength(100)+ .HasColumnType("character varying(100)");++ b.Property<int>("EventType")+ .HasColumnType("integer");++ b.Property<int?>("FailureReason")+ .HasColumnType("integer");++ b.Property<string>("IpAddress")+ .HasMaxLength(50)+ .HasColumnType("character varying(50)");++ b.Property<bool>("IsSuccess")+ .HasColumnType("boolean");++ b.Property<bool>("IsSuspiciousActivity")+ .HasColumnType("boolean");++ b.Property<string>("OperatingSystem")+ .HasMaxLength(100)+ .HasColumnType("character varying(100)");++ b.Property<string>("RequestPath")+ .HasMaxLength(100)+ .HasColumnType("character varying(100)");++ b.Property<DateTime>("Timestamp")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("Username")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.HasKey("Id");++ b.HasIndex(new[] { "EventType" }, "IX_EventType");++ b.HasIndex(new[] { "IpAddress" }, "IX_IpAddress");++ b.HasIndex(new[] { "Timestamp" }, "IX_Timestamp");++ b.HasIndex(new[] { "Username", "IsSuccess", "Timestamp" }, "IX_Username_IsSuccess_Timestamp")+ .IsDescending(false, false, true);++ b.HasIndex(new[] { "Username", "Timestamp" }, "IX_Username_Timestamp")+ .IsDescending(false, true);++ b.ToTable("AuthLogs");+ });++ modelBuilder.Entity("AliasServerDb.BlockedIpRange", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("integer");++ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));++ b.Property<bool>("BlockLogin")+ .HasColumnType("boolean");++ b.Property<bool>("BlockRegistration")+ .HasColumnType("boolean");++ b.Property<bool>("BlockShadow")+ .HasColumnType("boolean");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("CreatedBy")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<bool>("Enabled")+ .HasColumnType("boolean");++ b.Property<string>("IpRange")+ .IsRequired()+ .HasMaxLength(50)+ .HasColumnType("character varying(50)");++ b.Property<string>("Reason")+ .HasMaxLength(500)+ .HasColumnType("character varying(500)");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.HasKey("Id");++ b.HasIndex(new[] { "Enabled" }, "IX_BlockedIpRange_Enabled");++ b.HasIndex(new[] { "IpRange" }, "IX_BlockedIpRange_IpRange")+ .IsUnique();++ b.ToTable("BlockedIpRanges");+ });++ modelBuilder.Entity("AliasServerDb.Email", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("integer");++ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));++ b.Property<int>("AttachmentCount")+ .HasColumnType("integer");++ b.Property<DateTime>("Date")+ .HasColumnType("timestamp with time zone");++ b.Property<DateTime>("DateSystem")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("From")+ .IsRequired()+ .HasColumnType("text");++ b.Property<string>("FromDomain")+ .IsRequired()+ .HasColumnType("text");++ b.Property<string>("FromLocal")+ .IsRequired()+ .HasColumnType("text");++ b.Property<string>("MessageHtml")+ .HasColumnType("text");++ b.Property<string>("MessagePlain")+ .HasColumnType("text");++ b.Property<string>("MessagePreview")+ .HasColumnType("text");++ b.Property<string>("MessageSource")+ .HasColumnType("text");++ b.Property<byte[]>("MessageSourceBytes")+ .HasColumnType("bytea");++ b.Property<bool>("PushNotificationSent")+ .HasColumnType("boolean");++ b.Property<string>("Subject")+ .IsRequired()+ .HasColumnType("text");++ b.Property<string>("To")+ .IsRequired()+ .HasColumnType("text");++ b.Property<string>("ToDomain")+ .IsRequired()+ .HasColumnType("text");++ b.Property<string>("ToLocal")+ .IsRequired()+ .HasColumnType("text");++ b.Property<bool>("Visible")+ .HasColumnType("boolean");++ b.HasKey("Id");++ b.HasIndex("Date");++ b.HasIndex("DateSystem");++ b.HasIndex("PushNotificationSent");++ b.HasIndex("Visible");++ b.HasIndex("To", "DateSystem");++ b.ToTable("Emails");+ });++ modelBuilder.Entity("AliasServerDb.EmailAttachment", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("integer");++ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));++ b.Property<byte[]>("Bytes")+ .IsRequired()+ .HasColumnType("bytea");++ b.Property<DateTime>("Date")+ .HasColumnType("timestamp with time zone");++ b.Property<int>("EmailId")+ .HasColumnType("integer");++ b.Property<string>("Filename")+ .IsRequired()+ .HasColumnType("text");++ b.Property<int>("Filesize")+ .HasColumnType("integer");++ b.Property<string>("MimeType")+ .IsRequired()+ .HasColumnType("text");++ b.HasKey("Id");++ b.HasIndex("EmailId");++ b.ToTable("EmailAttachments");+ });++ modelBuilder.Entity("AliasServerDb.EmailClaim", b =>+ {+ b.Property<Guid>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("uuid");++ b.Property<string>("Address")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<string>("AddressDomain")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<string>("AddressLocal")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<bool>("Disabled")+ .HasColumnType("boolean");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.HasKey("Id");++ b.HasIndex("Address")+ .IsUnique();++ b.ToTable("EmailClaims");+ });++ modelBuilder.Entity("AliasServerDb.EmailClaimLink", b =>+ {+ b.Property<Guid>("EmailClaimId")+ .HasColumnType("uuid");++ b.Property<Guid>("VaultManifestId")+ .HasColumnType("uuid");++ b.HasKey("EmailClaimId", "VaultManifestId");++ b.HasIndex("VaultManifestId", "EmailClaimId");++ b.ToTable("EmailClaimLinks");+ });++ modelBuilder.Entity("AliasServerDb.EmailKeyWrap", b =>+ {+ b.Property<int>("EmailId")+ .HasColumnType("integer");++ b.Property<Guid>("EncryptionKeyId")+ .HasColumnType("uuid");++ b.Property<string>("EncryptedSymmetricKey")+ .IsRequired()+ .HasColumnType("text");++ b.HasKey("EmailId", "EncryptionKeyId");++ b.HasIndex("EncryptionKeyId", "EmailId");++ b.ToTable("EmailKeyWraps");+ });++ modelBuilder.Entity("AliasServerDb.Group", b =>+ {+ b.Property<Guid>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("uuid");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<int>("EmailsReceived")+ .HasColumnType("integer");++ b.Property<int>("MaxEmailAgeDays")+ .HasColumnType("integer");++ b.Property<int>("MaxEmails")+ .HasColumnType("integer");++ b.Property<string>("Name")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<bool>("ShadowBlocked")+ .HasColumnType("boolean");++ b.Property<DateTime?>("ShadowBlockedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<int>("Type")+ .HasColumnType("integer");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.HasKey("Id");++ b.ToTable("Groups");+ });++ modelBuilder.Entity("AliasServerDb.GroupMember", b =>+ {+ b.Property<Guid>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("uuid");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<Guid>("GroupId")+ .HasColumnType("uuid");++ b.Property<int>("Role")+ .HasColumnType("integer");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("UserId")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.HasIndex("GroupId", "UserId")+ .IsUnique();++ b.ToTable("GroupMembers");+ });++ modelBuilder.Entity("AliasServerDb.Log", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("integer");++ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));++ b.Property<string>("Application")+ .IsRequired()+ .HasMaxLength(50)+ .HasColumnType("character varying(50)");++ b.Property<string>("Exception")+ .IsRequired()+ .HasColumnType("text");++ b.Property<string>("Level")+ .IsRequired()+ .HasMaxLength(128)+ .HasColumnType("character varying(128)");++ b.Property<string>("LogEvent")+ .IsRequired()+ .HasColumnType("text")+ .HasColumnName("LogEvent");++ b.Property<string>("Message")+ .IsRequired()+ .HasColumnType("text");++ b.Property<string>("MessageTemplate")+ .IsRequired()+ .HasColumnType("text");++ b.Property<string>("Properties")+ .IsRequired()+ .HasColumnType("text");++ b.Property<string>("SourceContext")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<DateTime>("TimeStamp")+ .HasColumnType("timestamp with time zone");++ b.HasKey("Id");++ b.HasIndex("Application");++ b.HasIndex("TimeStamp");++ b.ToTable("Logs", (string)null);+ });++ modelBuilder.Entity("AliasServerDb.MobileLoginRequest", b =>+ {+ b.Property<string>("Id")+ .HasColumnType("text");++ b.Property<DateTime?>("ClearedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("ClientIpAddress")+ .HasColumnType("text");++ b.Property<string>("ClientPublicKey")+ .IsRequired()+ .HasColumnType("text");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("EncryptedDecryptionKey")+ .HasColumnType("text");++ b.Property<DateTime?>("FulfilledAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("MobileIpAddress")+ .HasColumnType("text");++ b.Property<DateTime?>("RetrievedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("UserId")+ .HasColumnType("text");++ b.HasKey("Id");++ b.HasIndex(new[] { "ClientIpAddress" }, "IX_ClientIpAddress");++ b.HasIndex(new[] { "CreatedAt" }, "IX_CreatedAt");++ b.HasIndex(new[] { "MobileIpAddress" }, "IX_MobileIpAddress");++ b.HasIndex(new[] { "RetrievedAt", "ClearedAt", "FulfilledAt" }, "IX_RetrievedAt_ClearedAt_FulfilledAt");++ b.HasIndex(new[] { "UserId" }, "IX_UserId");++ b.ToTable("MobileLoginRequests");+ });++ modelBuilder.Entity("AliasServerDb.RateLimit", b =>+ {+ b.Property<Guid>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("uuid");++ b.Property<int?>("AppliesToAccountAgeMaxDays")+ .HasColumnType("integer");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("CreatedBy")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<DateTime?>("EffectiveFrom")+ .HasColumnType("timestamp with time zone");++ b.Property<DateTime?>("EffectiveUntil")+ .HasColumnType("timestamp with time zone");++ b.Property<bool>("Enabled")+ .HasColumnType("boolean");++ b.Property<Guid?>("GroupId")+ .HasColumnType("uuid");++ b.Property<int>("LimitType")+ .HasColumnType("integer");++ b.Property<int>("MaxCount")+ .HasColumnType("integer");++ b.Property<string>("Notes")+ .HasMaxLength(1000)+ .HasColumnType("character varying(1000)");++ b.Property<int?>("Tier")+ .HasColumnType("integer");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<int>("WindowSeconds")+ .HasColumnType("integer");++ b.HasKey("Id");++ b.HasIndex("GroupId");++ b.HasIndex("Tier");++ b.HasIndex("LimitType", "Enabled");++ b.ToTable("RateLimits");+ });++ modelBuilder.Entity("AliasServerDb.ServerSetting", b =>+ {+ b.Property<string>("Key")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("Value")+ .HasColumnType("text");++ b.HasKey("Key");++ b.ToTable("ServerSettings");+ });++ modelBuilder.Entity("AliasServerDb.TaskRunnerJob", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("integer");++ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));++ b.Property<TimeOnly?>("EndTime")+ .HasColumnType("time without time zone");++ b.Property<string>("ErrorMessage")+ .HasColumnType("text");++ b.Property<bool>("IsOnDemand")+ .HasColumnType("boolean");++ b.Property<string>("Name")+ .IsRequired()+ .HasMaxLength(50)+ .HasColumnType("character varying(50)");++ b.Property<DateTime>("RunDate")+ .HasColumnType("timestamp with time zone");++ b.Property<TimeOnly>("StartTime")+ .HasColumnType("time without time zone");++ b.Property<int>("Status")+ .HasColumnType("integer");++ b.HasKey("Id");++ b.ToTable("TaskRunnerJobs");+ });++ modelBuilder.Entity("AliasServerDb.UserGrantKey", b =>+ {+ b.Property<Guid>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("uuid");++ b.Property<int>("AccountKeyVersion")+ .HasColumnType("integer");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("EncryptedPrivateKey")+ .IsRequired()+ .HasMaxLength(4000)+ .HasColumnType("character varying(4000)");++ b.Property<bool>("IsPrimary")+ .HasColumnType("boolean");++ b.Property<string>("PublicKey")+ .IsRequired()+ .HasMaxLength(2000)+ .HasColumnType("character varying(2000)");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("UserId")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.HasKey("Id");++ b.HasIndex("UserId")+ .IsUnique()+ .HasDatabaseName("UX_UserGrantKeys_User_Primary")+ .HasFilter("\"IsPrimary\"");++ b.ToTable("UserGrantKeys");+ });++ modelBuilder.Entity("AliasServerDb.UserUnlockKey", b =>+ {+ b.Property<Guid>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("uuid");++ b.Property<int>("AccountKeyVersion")+ .HasColumnType("integer");++ b.Property<string>("Algorithm")+ .IsRequired()+ .HasMaxLength(30)+ .HasColumnType("character varying(30)");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("EncryptedAccountKey")+ .IsRequired()+ .HasColumnType("text");++ b.Property<string>("Label")+ .IsRequired()+ .HasMaxLength(100)+ .HasColumnType("character varying(100)");++ b.Property<DateTime?>("LastUsedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("Metadata")+ .HasColumnType("jsonb");++ b.Property<string>("Type")+ .IsRequired()+ .HasMaxLength(30)+ .HasColumnType("character varying(30)");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("UserId")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.HasKey("Id");++ b.HasIndex("UserId", "Type", "Label")+ .IsUnique()+ .HasDatabaseName("UX_UserUnlockKeys_UserId_Type_Label");++ b.ToTable("UserUnlockKeys");+ });++ modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>+ {+ b.Property<string>("Hash")+ .HasMaxLength(64)+ .HasColumnType("character varying(64)");++ b.Property<string>("OwnerUserId")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<string>("Category")+ .IsRequired()+ .HasMaxLength(20)+ .HasColumnType("character varying(20)");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<byte[]>("EncryptedData")+ .IsRequired()+ .HasColumnType("bytea");++ b.Property<int>("KeyVersion")+ .HasColumnType("integer");++ b.Property<DateTime>("LastReferencedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<int>("SizeBytes")+ .HasColumnType("integer");++ b.HasKey("Hash", "OwnerUserId");++ b.HasIndex("OwnerUserId", "Category");++ b.ToTable("VaultBlobObjects");+ });++ modelBuilder.Entity("AliasServerDb.VaultBlobReference", b =>+ {+ b.Property<Guid>("ManifestId")+ .HasColumnType("uuid");++ b.Property<long>("RevisionNumber")+ .HasColumnType("bigint");++ b.Property<string>("BlobHash")+ .HasMaxLength(64)+ .HasColumnType("character varying(64)");++ b.HasKey("ManifestId", "RevisionNumber", "BlobHash");++ b.ToTable("VaultBlobReferences");+ });++ modelBuilder.Entity("AliasServerDb.VaultDataBucket", b =>+ {+ b.Property<Guid>("ManifestId")+ .HasColumnType("uuid");++ b.Property<string>("Category")+ .HasMaxLength(50)+ .HasColumnType("character varying(50)");++ b.Property<string>("CiphertextHash")+ .HasMaxLength(64)+ .HasColumnType("character varying(64)");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<byte[]>("EncryptedData")+ .IsRequired()+ .HasColumnType("bytea");++ b.Property<int>("KeyVersion")+ .HasColumnType("integer");++ b.Property<long>("RevisionNumber")+ .HasColumnType("bigint");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.HasKey("ManifestId", "Category");++ b.ToTable("VaultDataBuckets");+ });++ modelBuilder.Entity("AliasServerDb.VaultDataBucketsHistory", b =>+ {+ b.Property<Guid>("ManifestId")+ .HasColumnType("uuid");++ b.Property<string>("Category")+ .HasMaxLength(50)+ .HasColumnType("character varying(50)");++ b.Property<long>("RevisionNumber")+ .HasColumnType("bigint");++ b.Property<string>("CiphertextHash")+ .HasMaxLength(64)+ .HasColumnType("character varying(64)");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<byte[]>("EncryptedData")+ .IsRequired()+ .HasColumnType("bytea");++ b.Property<int>("KeyVersion")+ .HasColumnType("integer");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.HasKey("ManifestId", "Category", "RevisionNumber");++ b.ToTable("VaultDataBucketsHistory");+ });++ modelBuilder.Entity("AliasServerDb.VaultManifest", b =>+ {+ b.Property<Guid>("ManifestId")+ .ValueGeneratedOnAdd()+ .HasColumnType("uuid");++ b.Property<string>("Client")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<int>("CredentialsCount")+ .HasColumnType("integer");++ b.Property<int>("EmailClaimsCount")+ .HasColumnType("integer");++ b.Property<string>("EncryptionSettings")+ .HasColumnType("text");++ b.Property<string>("EncryptionType")+ .HasColumnType("text");++ b.Property<int>("FileSize")+ .HasColumnType("integer");++ b.Property<int>("KeyVersion")+ .HasColumnType("integer");++ b.Property<byte[]>("ManifestBlob")+ .HasColumnType("bytea");++ b.Property<string>("ManifestCiphertextHash")+ .HasMaxLength(64)+ .HasColumnType("character varying(64)");++ b.Property<string>("Name")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<Guid>("OwnerGroupId")+ .HasColumnType("uuid");++ b.Property<long>("RevisionNumber")+ .HasColumnType("bigint");++ b.Property<string>("Salt")+ .HasMaxLength(100)+ .HasColumnType("character varying(100)");++ b.Property<string>("StorageFormat")+ .IsRequired()+ .HasMaxLength(20)+ .HasColumnType("character varying(20)");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("VaultBlob")+ .HasColumnType("text");++ b.Property<string>("Verifier")+ .HasMaxLength(1000)+ .HasColumnType("character varying(1000)");++ b.Property<string>("Version")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.HasKey("ManifestId");++ b.HasIndex("OwnerGroupId");++ b.ToTable("VaultManifests");+ });++ modelBuilder.Entity("AliasServerDb.VaultManifestAccessKey", b =>+ {+ b.Property<Guid>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("uuid");++ b.Property<int?>("AccountKeyVersion")+ .HasColumnType("integer");++ b.Property<string>("Algorithm")+ .IsRequired()+ .HasMaxLength(30)+ .HasColumnType("character varying(30)");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("EncryptedVek")+ .IsRequired()+ .HasColumnType("text");++ b.Property<int>("KeyVersion")+ .HasColumnType("integer");++ b.Property<DateTime?>("LastUsedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("Metadata")+ .HasColumnType("jsonb");++ b.Property<string>("Type")+ .IsRequired()+ .HasMaxLength(30)+ .HasColumnType("character varying(30)");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<Guid?>("UserGrantKeyId")+ .HasColumnType("uuid");++ b.Property<string>("UserId")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<Guid>("VaultManifestId")+ .HasColumnType("uuid");++ b.HasKey("Id");++ b.HasIndex("UserGrantKeyId");++ b.HasIndex("VaultManifestId")+ .HasDatabaseName("IX_VaultManifestAccessKeys_VaultManifestId");++ b.HasIndex("UserId", "Type", "VaultManifestId", "KeyVersion")+ .IsUnique()+ .HasDatabaseName("UX_VaultManifestAccessKeys_UserId_Type_Manifest_Version");++ b.ToTable("VaultManifestAccessKeys");+ });++ modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>+ {+ b.Property<Guid>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("uuid");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<bool>("IsPrimary")+ .HasColumnType("boolean");++ b.Property<string>("PublicKey")+ .IsRequired()+ .HasMaxLength(2000)+ .HasColumnType("character varying(2000)");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<Guid>("VaultManifestId")+ .HasColumnType("uuid");++ b.HasKey("Id");++ b.HasIndex("VaultManifestId")+ .IsUnique()+ .HasDatabaseName("UX_VaultManifestDeliveryKeys_Manifest_Primary")+ .HasFilter("\"IsPrimary\"");++ b.HasIndex("VaultManifestId", "IsPrimary");++ b.ToTable("VaultManifestDeliveryKeys");+ });++ modelBuilder.Entity("AliasServerDb.VaultManifestsHistory", b =>+ {+ b.Property<Guid>("ManifestId")+ .HasColumnType("uuid");++ b.Property<long>("RevisionNumber")+ .HasColumnType("bigint");++ b.Property<string>("Client")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<int>("CredentialsCount")+ .HasColumnType("integer");++ b.Property<int>("EmailClaimsCount")+ .HasColumnType("integer");++ b.Property<string>("EncryptionSettings")+ .HasColumnType("text");++ b.Property<string>("EncryptionType")+ .HasColumnType("text");++ b.Property<int>("FileSize")+ .HasColumnType("integer");++ b.Property<int>("KeyVersion")+ .HasColumnType("integer");++ b.Property<byte[]>("ManifestBlob")+ .HasColumnType("bytea");++ b.Property<string>("ManifestCiphertextHash")+ .HasMaxLength(64)+ .HasColumnType("character varying(64)");++ b.Property<string>("Salt")+ .HasMaxLength(100)+ .HasColumnType("character varying(100)");++ b.Property<string>("StorageFormat")+ .IsRequired()+ .HasMaxLength(20)+ .HasColumnType("character varying(20)");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("VaultBlob")+ .HasColumnType("text");++ b.Property<string>("Verifier")+ .HasMaxLength(1000)+ .HasColumnType("character varying(1000)");++ b.Property<string>("Version")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.HasKey("ManifestId", "RevisionNumber");++ b.ToTable("VaultManifestsHistory", (string)null);+ });++ modelBuilder.Entity("AliasVault.WorkerStatus.Database.WorkerServiceStatus", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("integer");++ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));++ b.Property<string>("CurrentStatus")+ .IsRequired()+ .HasMaxLength(50)+ .HasColumnType("character varying(50)");++ b.Property<string>("DesiredStatus")+ .IsRequired()+ .HasMaxLength(50)+ .HasColumnType("character varying(50)");++ b.Property<DateTime>("Heartbeat")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("ServiceName")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.HasKey("Id");++ b.ToTable("WorkerServiceStatuses");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.DataProtectionKey", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("integer");++ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));++ b.Property<string>("FriendlyName")+ .HasColumnType("text");++ b.Property<string>("Xml")+ .HasColumnType("text");++ b.HasKey("Id");++ b.ToTable("DataProtectionKeys");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("integer");++ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));++ b.Property<string>("ClaimType")+ .HasColumnType("text");++ b.Property<string>("ClaimValue")+ .HasColumnType("text");++ b.Property<string>("UserId")+ .HasColumnType("text");++ b.HasKey("Id");++ b.ToTable("UserClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>+ {+ b.Property<string>("UserId")+ .HasColumnType("text");++ b.Property<string>("LoginProvider")+ .HasColumnType("text");++ b.Property<string>("Name")+ .HasColumnType("text");++ b.Property<string>("Value")+ .HasColumnType("text");++ b.HasKey("UserId", "LoginProvider", "Name");++ b.ToTable("UserTokens", (string)null);+ });++ modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>+ {+ b.HasOne("AliasServerDb.Group", "PersonalGroup")+ .WithOne()+ .HasForeignKey("AliasServerDb.AliasVaultUser", "PersonalGroupId")+ .OnDelete(DeleteBehavior.Restrict)+ .IsRequired();++ b.Navigation("PersonalGroup");+ });++ modelBuilder.Entity("AliasServerDb.AliasVaultUserRefreshToken", b =>+ {+ b.HasOne("AliasServerDb.AliasVaultUser", "User")+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("User");+ });++ modelBuilder.Entity("AliasServerDb.EmailAttachment", b =>+ {+ b.HasOne("AliasServerDb.Email", "Email")+ .WithMany("Attachments")+ .HasForeignKey("EmailId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Email");+ });++ modelBuilder.Entity("AliasServerDb.EmailClaimLink", b =>+ {+ b.HasOne("AliasServerDb.EmailClaim", "EmailClaim")+ .WithMany("Links")+ .HasForeignKey("EmailClaimId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("AliasServerDb.VaultManifest", "VaultManifest")+ .WithMany()+ .HasForeignKey("VaultManifestId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("EmailClaim");++ b.Navigation("VaultManifest");+ });++ modelBuilder.Entity("AliasServerDb.EmailKeyWrap", b =>+ {+ b.HasOne("AliasServerDb.Email", "Email")+ .WithMany("Wraps")+ .HasForeignKey("EmailId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("AliasServerDb.VaultManifestDeliveryKey", "EncryptionKey")+ .WithMany("Wraps")+ .HasForeignKey("EncryptionKeyId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Email");++ b.Navigation("EncryptionKey");+ });++ modelBuilder.Entity("AliasServerDb.GroupMember", b =>+ {+ b.HasOne("AliasServerDb.Group", "Group")+ .WithMany("Members")+ .HasForeignKey("GroupId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("AliasServerDb.AliasVaultUser", "User")+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Group");++ b.Navigation("User");+ });++ modelBuilder.Entity("AliasServerDb.MobileLoginRequest", b =>+ {+ b.HasOne("AliasServerDb.AliasVaultUser", "User")+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade);++ b.Navigation("User");+ });++ modelBuilder.Entity("AliasServerDb.RateLimit", b =>+ {+ b.HasOne("AliasServerDb.Group", "Group")+ .WithMany()+ .HasForeignKey("GroupId")+ .OnDelete(DeleteBehavior.Cascade);++ b.Navigation("Group");+ });++ modelBuilder.Entity("AliasServerDb.UserGrantKey", b =>+ {+ b.HasOne("AliasServerDb.AliasVaultUser", "User")+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("User");+ });++ modelBuilder.Entity("AliasServerDb.UserUnlockKey", b =>+ {+ b.HasOne("AliasServerDb.AliasVaultUser", "User")+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("User");+ });++ modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>+ {+ b.HasOne("AliasServerDb.AliasVaultUser", "User")+ .WithMany()+ .HasForeignKey("OwnerUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("User");+ });++ modelBuilder.Entity("AliasServerDb.VaultBlobReference", b =>+ {+ b.HasOne("AliasServerDb.VaultManifest", "Manifest")+ .WithMany()+ .HasForeignKey("ManifestId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Manifest");+ });++ modelBuilder.Entity("AliasServerDb.VaultDataBucket", b =>+ {+ b.HasOne("AliasServerDb.VaultManifest", "Manifest")+ .WithMany()+ .HasForeignKey("ManifestId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Manifest");+ });++ modelBuilder.Entity("AliasServerDb.VaultDataBucketsHistory", b =>+ {+ b.HasOne("AliasServerDb.VaultDataBucket", "Bucket")+ .WithMany()+ .HasForeignKey("ManifestId", "Category")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Bucket");+ });++ modelBuilder.Entity("AliasServerDb.VaultManifest", b =>+ {+ b.HasOne("AliasServerDb.Group", "OwnerGroup")+ .WithMany()+ .HasForeignKey("OwnerGroupId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("OwnerGroup");+ });++ modelBuilder.Entity("AliasServerDb.VaultManifestAccessKey", b =>+ {+ b.HasOne("AliasServerDb.UserGrantKey", "UserGrantKey")+ .WithMany()+ .HasForeignKey("UserGrantKeyId")+ .OnDelete(DeleteBehavior.SetNull);++ b.HasOne("AliasServerDb.AliasVaultUser", "User")+ .WithMany("VaultManifestAccessKeys")+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("User");++ b.Navigation("UserGrantKey");+ });++ modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>+ {+ b.HasOne("AliasServerDb.VaultManifest", "VaultManifest")+ .WithMany()+ .HasForeignKey("VaultManifestId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("VaultManifest");+ });++ modelBuilder.Entity("AliasServerDb.VaultManifestsHistory", b =>+ {+ b.HasOne("AliasServerDb.VaultManifest", "Manifest")+ .WithMany()+ .HasForeignKey("ManifestId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Manifest");+ });++ modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>+ {+ b.Navigation("VaultManifestAccessKeys");+ });++ modelBuilder.Entity("AliasServerDb.Email", b =>+ {+ b.Navigation("Attachments");++ b.Navigation("Wraps");+ });++ modelBuilder.Entity("AliasServerDb.EmailClaim", b =>+ {+ b.Navigation("Links");+ });++ modelBuilder.Entity("AliasServerDb.Group", b =>+ {+ b.Navigation("Members");+ });++ modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>+ {+ b.Navigation("Wraps");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260811194817_ReorderTableColumns.cs b/apps/server/Databases/AliasServerDb/Migrations/20260811194817_ReorderTableColumns.csnew file mode 100644index 000000000..918a369f5--- /dev/null+++ b/apps/server/Databases/AliasServerDb/Migrations/20260811194817_ReorderTableColumns.cs@@ -0,0 +1,556 @@+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace AliasServerDb.Migrations+{+ /// <summary>+ /// Reorders the physical columns of the tables.+ /// </summary>+ public partial class ReorderTableColumns : Migration+ {+ /// <inheritdoc />+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ DropForeignKeys(migrationBuilder);++ RebuildAliasVaultUsers(migrationBuilder);+ RebuildEmails(migrationBuilder);+ RebuildRateLimits(migrationBuilder);+ RebuildVaultManifests(migrationBuilder);+ RebuildVaultManifestsHistory(migrationBuilder);+ RebuildVaultManifestDeliveryKeys(migrationBuilder);+ RebuildVaultManifestAccessKeys(migrationBuilder);+ RebuildVaultDataBuckets(migrationBuilder);+ RebuildVaultDataBucketsHistory(migrationBuilder);+ RebuildVaultBlobObjects(migrationBuilder);+ RebuildUserGrantKeys(migrationBuilder);+ RebuildUserUnlockKeys(migrationBuilder);++ RecreateForeignKeys(migrationBuilder);+ }++ /// <inheritdoc />+ /// <remarks>+ /// Intentionally empty: this migration only changes the order in which the columns are stored, which no+ /// application code and no EF Core model depends on. A database that is rolled back to the previous migration+ /// is identical to one that never ran this migration apart from that order, so there is nothing to undo.+ /// </remarks>+ protected override void Down(MigrationBuilder migrationBuilder)+ {+ }++ /// <summary>+ /// Drops every foreign key that touches a table this migration rebuilds, on either side of the relation. This+ /// makes the order in which the tables are rebuilt irrelevant: no table can be held down by a constraint that+ /// lives on a table that has not been rebuilt yet.+ /// </summary>+ /// <param name="migrationBuilder">Migration builder.</param>+ private static void DropForeignKeys(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("""+ ALTER TABLE "AliasVaultUserRefreshTokens" DROP CONSTRAINT "FK_AliasVaultUserRefreshTokens_AliasVaultUsers_UserId";+ ALTER TABLE "AliasVaultUsers" DROP CONSTRAINT "FK_AliasVaultUsers_Groups_PersonalGroupId";+ ALTER TABLE "EmailAttachments" DROP CONSTRAINT "FK_EmailAttachments_Emails_EmailId";+ ALTER TABLE "EmailClaimLinks" DROP CONSTRAINT "FK_EmailClaimLinks_VaultManifests_VaultManifestId";+ ALTER TABLE "EmailKeyWraps" DROP CONSTRAINT "FK_EmailKeyWraps_Emails_EmailId";+ ALTER TABLE "EmailKeyWraps" DROP CONSTRAINT "FK_EmailKeyWraps_VaultManifestDeliveryKeys_EncryptionKeyId";+ ALTER TABLE "GroupMembers" DROP CONSTRAINT "FK_GroupMembers_AliasVaultUsers_UserId";+ ALTER TABLE "MobileLoginRequests" DROP CONSTRAINT "FK_MobileLoginRequests_AliasVaultUsers_UserId";+ ALTER TABLE "RateLimits" DROP CONSTRAINT "FK_RateLimits_Groups_GroupId";+ ALTER TABLE "UserGrantKeys" DROP CONSTRAINT "FK_UserGrantKeys_AliasVaultUsers_UserId";+ ALTER TABLE "UserUnlockKeys" DROP CONSTRAINT "FK_UserUnlockKeys_AliasVaultUsers_UserId";+ ALTER TABLE "VaultBlobObjects" DROP CONSTRAINT "FK_VaultBlobObjects_AliasVaultUsers_OwnerUserId";+ ALTER TABLE "VaultBlobReferences" DROP CONSTRAINT "FK_VaultBlobReferences_VaultManifests_ManifestId";+ ALTER TABLE "VaultDataBuckets" DROP CONSTRAINT "FK_VaultDataBuckets_VaultManifests_ManifestId";+ ALTER TABLE "VaultDataBucketsHistory" DROP CONSTRAINT "FK_VaultDataBucketsHistory_VaultDataBuckets_ManifestId_Category";+ ALTER TABLE "VaultManifestAccessKeys" DROP CONSTRAINT "FK_VaultManifestAccessKeys_AliasVaultUsers_UserId";+ ALTER TABLE "VaultManifestAccessKeys" DROP CONSTRAINT "FK_VaultManifestAccessKeys_UserGrantKeys_UserGrantKeyId";+ ALTER TABLE "VaultManifestDeliveryKeys" DROP CONSTRAINT "FK_VaultManifestDeliveryKeys_VaultManifests_VaultManifestId";+ ALTER TABLE "VaultManifests" DROP CONSTRAINT "FK_VaultManifests_Groups_OwnerGroupId";+ ALTER TABLE "VaultManifestsHistory" DROP CONSTRAINT "FK_VaultManifestsHistory_VaultManifests_ManifestId";+ """);+ }++ /// <summary>+ /// Puts the identity of the user first, then the account state AliasVault itself maintains, and moves the+ /// ASP.NET Identity columns that AliasVault does not use (phone, two factor, lockout) to the back.+ /// </summary>+ /// <param name="migrationBuilder">Migration builder.</param>+ private static void RebuildAliasVaultUsers(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("""+ CREATE TABLE "AliasVaultUsers_reordered" (+ "Id" text NOT NULL,+ "UserName" text,+ "NormalizedUserName" text,+ "Email" text,+ "NormalizedEmail" text,+ "EmailConfirmed" boolean NOT NULL,+ "SrpIdentity" character varying(255),+ "PersonalGroupId" uuid NOT NULL,+ "PasswordHash" text,+ "SecurityStamp" text,+ "ConcurrencyStamp" text,+ "Blocked" boolean NOT NULL,+ "BlockedAt" timestamp with time zone,+ "LastActivityDate" timestamp with time zone,+ "PasswordChangedAt" timestamp with time zone NOT NULL,+ "CreatedAt" timestamp with time zone NOT NULL,+ "UpdatedAt" timestamp with time zone NOT NULL,+ "PhoneNumber" text,+ "PhoneNumberConfirmed" boolean NOT NULL,+ "TwoFactorEnabled" boolean NOT NULL,+ "LockoutEnd" timestamp with time zone,+ "LockoutEnabled" boolean NOT NULL,+ "AccessFailedCount" integer NOT NULL+ );++ INSERT INTO "AliasVaultUsers_reordered" ("Id", "UserName", "NormalizedUserName", "Email", "NormalizedEmail", "EmailConfirmed", "SrpIdentity", "PersonalGroupId", "PasswordHash", "SecurityStamp", "ConcurrencyStamp", "Blocked", "BlockedAt", "LastActivityDate", "PasswordChangedAt", "CreatedAt", "UpdatedAt", "PhoneNumber", "PhoneNumberConfirmed", "TwoFactorEnabled", "LockoutEnd", "LockoutEnabled", "AccessFailedCount")+ SELECT "Id", "UserName", "NormalizedUserName", "Email", "NormalizedEmail", "EmailConfirmed", "SrpIdentity", "PersonalGroupId", "PasswordHash", "SecurityStamp", "ConcurrencyStamp", "Blocked", "BlockedAt", "LastActivityDate", "PasswordChangedAt", "CreatedAt", "UpdatedAt", "PhoneNumber", "PhoneNumberConfirmed", "TwoFactorEnabled", "LockoutEnd", "LockoutEnabled", "AccessFailedCount"+ FROM "AliasVaultUsers";++ DROP TABLE "AliasVaultUsers";+ ALTER TABLE "AliasVaultUsers_reordered" RENAME TO "AliasVaultUsers";++ ALTER TABLE "AliasVaultUsers" ADD CONSTRAINT "PK_AliasVaultUsers" PRIMARY KEY ("Id");+ CREATE UNIQUE INDEX "UX_AliasVaultUsers_PersonalGroupId" ON "AliasVaultUsers" ("PersonalGroupId");+ """);+ }++ /// <summary>+ /// Groups the recipient and sender columns, moves the message body columns the current storage format uses+ /// (preview, source bytes and the attachment counter) up next to each other, and pushes the v1 body columns+ /// that are no longer written to the back.+ /// </summary>+ /// <param name="migrationBuilder">Migration builder.</param>+ private static void RebuildEmails(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("""+ CREATE TABLE "Emails_reordered" (+ "Id" integer NOT NULL,+ "Subject" text NOT NULL,+ "From" text NOT NULL,+ "FromLocal" text NOT NULL,+ "FromDomain" text NOT NULL,+ "To" text NOT NULL,+ "ToLocal" text NOT NULL,+ "ToDomain" text NOT NULL,+ "Date" timestamp with time zone NOT NULL,+ "DateSystem" timestamp with time zone NOT NULL,+ "MessagePreview" text,+ "MessageSourceBytes" bytea,+ "AttachmentCount" integer DEFAULT 0 NOT NULL,+ "Visible" boolean NOT NULL,+ "PushNotificationSent" boolean NOT NULL,+ "MessageHtml" text,+ "MessagePlain" text,+ "MessageSource" text+ );++ ALTER TABLE "Emails_reordered" ALTER COLUMN "MessageSourceBytes" SET STORAGE EXTERNAL;++ INSERT INTO "Emails_reordered" ("Id", "Subject", "From", "FromLocal", "FromDomain", "To", "ToLocal", "ToDomain", "Date", "DateSystem", "MessagePreview", "MessageSourceBytes", "AttachmentCount", "Visible", "PushNotificationSent", "MessageHtml", "MessagePlain", "MessageSource")+ SELECT "Id", "Subject", "From", "FromLocal", "FromDomain", "To", "ToLocal", "ToDomain", "Date", "DateSystem", "MessagePreview", "MessageSourceBytes", "AttachmentCount", "Visible", "PushNotificationSent", "MessageHtml", "MessagePlain", "MessageSource"+ FROM "Emails";++ DROP TABLE "Emails";+ ALTER TABLE "Emails_reordered" RENAME TO "Emails";++ ALTER TABLE "Emails" ADD CONSTRAINT "PK_Emails" PRIMARY KEY ("Id");+ ALTER TABLE "Emails" ALTER COLUMN "Id" ADD GENERATED BY DEFAULT AS IDENTITY;+ SELECT setval(pg_get_serial_sequence('"Emails"', 'Id'), COALESCE((SELECT MAX("Id") FROM "Emails"), 0) + 1, false);++ CREATE INDEX "IX_Emails_Date" ON "Emails" ("Date");+ CREATE INDEX "IX_Emails_DateSystem" ON "Emails" ("DateSystem");+ CREATE INDEX "IX_Emails_PushNotificationSent" ON "Emails" ("PushNotificationSent");+ CREATE INDEX "IX_Emails_To_DateSystem" ON "Emails" ("To", "DateSystem");+ CREATE INDEX "IX_Emails_Visible" ON "Emails" ("Visible");+ """);+ }++ /// <summary>+ /// Moves the group a rate limit override applies to up next to the primary key instead of leaving it behind+ /// the audit columns.+ /// </summary>+ /// <param name="migrationBuilder">Migration builder.</param>+ private static void RebuildRateLimits(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("""+ CREATE TABLE "RateLimits_reordered" (+ "Id" uuid NOT NULL,+ "GroupId" uuid,+ "LimitType" integer NOT NULL,+ "Tier" integer,+ "WindowSeconds" integer NOT NULL,+ "MaxCount" integer NOT NULL,+ "AppliesToAccountAgeMaxDays" integer,+ "Enabled" boolean NOT NULL,+ "Notes" character varying(1000),+ "EffectiveFrom" timestamp with time zone,+ "EffectiveUntil" timestamp with time zone,+ "CreatedBy" character varying(255),+ "CreatedAt" timestamp with time zone NOT NULL,+ "UpdatedAt" timestamp with time zone NOT NULL+ );++ INSERT INTO "RateLimits_reordered" ("Id", "GroupId", "LimitType", "Tier", "WindowSeconds", "MaxCount", "AppliesToAccountAgeMaxDays", "Enabled", "Notes", "EffectiveFrom", "EffectiveUntil", "CreatedBy", "CreatedAt", "UpdatedAt")+ SELECT "Id", "GroupId", "LimitType", "Tier", "WindowSeconds", "MaxCount", "AppliesToAccountAgeMaxDays", "Enabled", "Notes", "EffectiveFrom", "EffectiveUntil", "CreatedBy", "CreatedAt", "UpdatedAt"+ FROM "RateLimits";++ DROP TABLE "RateLimits";+ ALTER TABLE "RateLimits_reordered" RENAME TO "RateLimits";++ ALTER TABLE "RateLimits" ADD CONSTRAINT "PK_RateLimits" PRIMARY KEY ("Id");+ CREATE INDEX "IX_RateLimits_GroupId" ON "RateLimits" ("GroupId");+ CREATE INDEX "IX_RateLimits_LimitType_Enabled" ON "RateLimits" ("LimitType", "Enabled");+ CREATE INDEX "IX_RateLimits_Tier" ON "RateLimits" ("Tier");+ """);+ }++ /// <summary>+ /// Leads with the manifest identity and its owning group, followed by the manifest-v1 payload and the+ /// bookkeeping counters, and ends with the legacy sqlite-blob and SRP columns.+ /// </summary>+ /// <param name="migrationBuilder">Migration builder.</param>+ private static void RebuildVaultManifests(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("""+ CREATE TABLE "VaultManifests_reordered" (+ "ManifestId" uuid NOT NULL,+ "OwnerGroupId" uuid NOT NULL,+ "Name" character varying(255),+ "StorageFormat" character varying(20) NOT NULL,+ "ManifestBlob" bytea,+ "ManifestCiphertextHash" character varying(64),+ "KeyVersion" integer DEFAULT 0 NOT NULL,+ "RevisionNumber" bigint NOT NULL,+ "FileSize" integer NOT NULL,+ "CredentialsCount" integer NOT NULL,+ "EmailClaimsCount" integer NOT NULL,+ "Client" character varying(255),+ "CreatedAt" timestamp with time zone NOT NULL,+ "UpdatedAt" timestamp with time zone NOT NULL,+ "VaultBlob" text,+ "Version" character varying(255),+ "Salt" character varying(100),+ "Verifier" character varying(1000),+ "EncryptionType" text,+ "EncryptionSettings" text+ );++ ALTER TABLE "VaultManifests_reordered" ALTER COLUMN "ManifestBlob" SET STORAGE EXTERNAL;++ INSERT INTO "VaultManifests_reordered" ("ManifestId", "OwnerGroupId", "Name", "StorageFormat", "ManifestBlob", "ManifestCiphertextHash", "KeyVersion", "RevisionNumber", "FileSize", "CredentialsCount", "EmailClaimsCount", "Client", "CreatedAt", "UpdatedAt", "VaultBlob", "Version", "Salt", "Verifier", "EncryptionType", "EncryptionSettings")+ SELECT "ManifestId", "OwnerGroupId", "Name", "StorageFormat", "ManifestBlob", "ManifestCiphertextHash", "KeyVersion", "RevisionNumber", "FileSize", "CredentialsCount", "EmailClaimsCount", "Client", "CreatedAt", "UpdatedAt", "VaultBlob", "Version", "Salt", "Verifier", "EncryptionType", "EncryptionSettings"+ FROM "VaultManifests";++ DROP TABLE "VaultManifests";+ ALTER TABLE "VaultManifests_reordered" RENAME TO "VaultManifests";++ ALTER TABLE "VaultManifests" ADD CONSTRAINT "PK_VaultManifests" PRIMARY KEY ("ManifestId");+ CREATE INDEX "IX_VaultManifests_OwnerGroupId" ON "VaultManifests" ("OwnerGroupId");+ """);+ }++ /// <summary>+ /// Mirrors the column order of the VaultManifests head table, with the revision number directly behind the+ /// manifest id because the two together identify a history row.+ /// </summary>+ /// <param name="migrationBuilder">Migration builder.</param>+ private static void RebuildVaultManifestsHistory(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("""+ CREATE TABLE "VaultManifestsHistory_reordered" (+ "ManifestId" uuid NOT NULL,+ "RevisionNumber" bigint NOT NULL,+ "StorageFormat" character varying(20) NOT NULL,+ "ManifestBlob" bytea,+ "ManifestCiphertextHash" character varying(64),+ "KeyVersion" integer DEFAULT 0 NOT NULL,+ "FileSize" integer NOT NULL,+ "CredentialsCount" integer NOT NULL,+ "EmailClaimsCount" integer NOT NULL,+ "Client" character varying(255),+ "CreatedAt" timestamp with time zone NOT NULL,+ "UpdatedAt" timestamp with time zone NOT NULL,+ "VaultBlob" text,+ "Version" character varying(255),+ "Salt" character varying(100),+ "Verifier" character varying(1000),+ "EncryptionType" text,+ "EncryptionSettings" text+ );++ ALTER TABLE "VaultManifestsHistory_reordered" ALTER COLUMN "ManifestBlob" SET STORAGE EXTERNAL;++ INSERT INTO "VaultManifestsHistory_reordered" ("ManifestId", "RevisionNumber", "StorageFormat", "ManifestBlob", "ManifestCiphertextHash", "KeyVersion", "FileSize", "CredentialsCount", "EmailClaimsCount", "Client", "CreatedAt", "UpdatedAt", "VaultBlob", "Version", "Salt", "Verifier", "EncryptionType", "EncryptionSettings")+ SELECT "ManifestId", "RevisionNumber", "StorageFormat", "ManifestBlob", "ManifestCiphertextHash", "KeyVersion", "FileSize", "CredentialsCount", "EmailClaimsCount", "Client", "CreatedAt", "UpdatedAt", "VaultBlob", "Version", "Salt", "Verifier", "EncryptionType", "EncryptionSettings"+ FROM "VaultManifestsHistory";++ DROP TABLE "VaultManifestsHistory";+ ALTER TABLE "VaultManifestsHistory_reordered" RENAME TO "VaultManifestsHistory";++ ALTER TABLE "VaultManifestsHistory" ADD CONSTRAINT "PK_VaultManifestsHistory" PRIMARY KEY ("ManifestId", "RevisionNumber");+ """);+ }++ /// <summary>+ /// Moves the manifest a delivery key belongs to up to the second column instead of leaving it behind the+ /// timestamps.+ /// </summary>+ /// <param name="migrationBuilder">Migration builder.</param>+ private static void RebuildVaultManifestDeliveryKeys(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("""+ CREATE TABLE "VaultManifestDeliveryKeys_reordered" (+ "Id" uuid NOT NULL,+ "VaultManifestId" uuid NOT NULL,+ "PublicKey" character varying(2000) NOT NULL,+ "IsPrimary" boolean NOT NULL,+ "CreatedAt" timestamp with time zone NOT NULL,+ "UpdatedAt" timestamp with time zone NOT NULL+ );++ INSERT INTO "VaultManifestDeliveryKeys_reordered" ("Id", "VaultManifestId", "PublicKey", "IsPrimary", "CreatedAt", "UpdatedAt")+ SELECT "Id", "VaultManifestId", "PublicKey", "IsPrimary", "CreatedAt", "UpdatedAt"+ FROM "VaultManifestDeliveryKeys";++ DROP TABLE "VaultManifestDeliveryKeys";+ ALTER TABLE "VaultManifestDeliveryKeys_reordered" RENAME TO "VaultManifestDeliveryKeys";++ ALTER TABLE "VaultManifestDeliveryKeys" ADD CONSTRAINT "PK_VaultManifestDeliveryKeys" PRIMARY KEY ("Id");+ CREATE INDEX "IX_VaultManifestDeliveryKeys_VaultManifestId_IsPrimary" ON "VaultManifestDeliveryKeys" ("VaultManifestId", "IsPrimary");+ CREATE UNIQUE INDEX "UX_VaultManifestDeliveryKeys_Manifest_Primary" ON "VaultManifestDeliveryKeys" ("VaultManifestId") WHERE "IsPrimary";+ """);+ }++ /// <summary>+ /// Puts the version of the VEK next to the wrapped VEK it describes, and the account key version next to the+ /// grant key it belongs to, instead of both trailing the timestamps.+ /// </summary>+ /// <param name="migrationBuilder">Migration builder.</param>+ private static void RebuildVaultManifestAccessKeys(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("""+ CREATE TABLE "VaultManifestAccessKeys_reordered" (+ "Id" uuid NOT NULL,+ "UserId" character varying(255) NOT NULL,+ "VaultManifestId" uuid NOT NULL,+ "Type" character varying(30) NOT NULL,+ "Algorithm" character varying(30) NOT NULL,+ "EncryptedVek" text NOT NULL,+ "KeyVersion" integer DEFAULT 0 NOT NULL,+ "UserGrantKeyId" uuid,+ "AccountKeyVersion" integer,+ "Metadata" jsonb,+ "CreatedAt" timestamp with time zone NOT NULL,+ "UpdatedAt" timestamp with time zone NOT NULL,+ "LastUsedAt" timestamp with time zone+ );++ INSERT INTO "VaultManifestAccessKeys_reordered" ("Id", "UserId", "VaultManifestId", "Type", "Algorithm", "EncryptedVek", "KeyVersion", "UserGrantKeyId", "AccountKeyVersion", "Metadata", "CreatedAt", "UpdatedAt", "LastUsedAt")+ SELECT "Id", "UserId", "VaultManifestId", "Type", "Algorithm", "EncryptedVek", "KeyVersion", "UserGrantKeyId", "AccountKeyVersion", "Metadata", "CreatedAt", "UpdatedAt", "LastUsedAt"+ FROM "VaultManifestAccessKeys";++ DROP TABLE "VaultManifestAccessKeys";+ ALTER TABLE "VaultManifestAccessKeys_reordered" RENAME TO "VaultManifestAccessKeys";++ ALTER TABLE "VaultManifestAccessKeys" ADD CONSTRAINT "PK_VaultManifestAccessKeys" PRIMARY KEY ("Id");+ CREATE INDEX "IX_VaultManifestAccessKeys_UserGrantKeyId" ON "VaultManifestAccessKeys" ("UserGrantKeyId");+ CREATE INDEX "IX_VaultManifestAccessKeys_VaultManifestId" ON "VaultManifestAccessKeys" ("VaultManifestId");+ CREATE UNIQUE INDEX "UX_VaultManifestAccessKeys_UserId_Type_Manifest_Version" ON "VaultManifestAccessKeys" ("UserId", "Type", "VaultManifestId", "KeyVersion");+ """);+ }++ /// <summary>+ /// Leads with the composite key, then the revision the bucket is at, and keeps the ciphertext together with+ /// its hash and key version before the timestamps.+ /// </summary>+ /// <param name="migrationBuilder">Migration builder.</param>+ private static void RebuildVaultDataBuckets(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("""+ CREATE TABLE "VaultDataBuckets_reordered" (+ "ManifestId" uuid NOT NULL,+ "Category" character varying(50) NOT NULL,+ "RevisionNumber" bigint NOT NULL,+ "EncryptedData" bytea NOT NULL,+ "CiphertextHash" character varying(64),+ "KeyVersion" integer DEFAULT 0 NOT NULL,+ "CreatedAt" timestamp with time zone NOT NULL,+ "UpdatedAt" timestamp with time zone NOT NULL+ );++ ALTER TABLE "VaultDataBuckets_reordered" ALTER COLUMN "EncryptedData" SET STORAGE EXTERNAL;++ INSERT INTO "VaultDataBuckets_reordered" ("ManifestId", "Category", "RevisionNumber", "EncryptedData", "CiphertextHash", "KeyVersion", "CreatedAt", "UpdatedAt")+ SELECT "ManifestId", "Category", "RevisionNumber", "EncryptedData", "CiphertextHash", "KeyVersion", "CreatedAt", "UpdatedAt"+ FROM "VaultDataBuckets";++ DROP TABLE "VaultDataBuckets";+ ALTER TABLE "VaultDataBuckets_reordered" RENAME TO "VaultDataBuckets";++ ALTER TABLE "VaultDataBuckets" ADD CONSTRAINT "PK_VaultDataBuckets" PRIMARY KEY ("ManifestId", "Category");+ """);+ }++ /// <summary>+ /// Mirrors the column order of the VaultDataBuckets head table, which also puts the columns in the same order+ /// as the composite primary key of the history table.+ /// </summary>+ /// <param name="migrationBuilder">Migration builder.</param>+ private static void RebuildVaultDataBucketsHistory(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("""+ CREATE TABLE "VaultDataBucketsHistory_reordered" (+ "ManifestId" uuid NOT NULL,+ "Category" character varying(50) NOT NULL,+ "RevisionNumber" bigint NOT NULL,+ "EncryptedData" bytea NOT NULL,+ "CiphertextHash" character varying(64),+ "KeyVersion" integer DEFAULT 0 NOT NULL,+ "CreatedAt" timestamp with time zone NOT NULL,+ "UpdatedAt" timestamp with time zone NOT NULL+ );++ ALTER TABLE "VaultDataBucketsHistory_reordered" ALTER COLUMN "EncryptedData" SET STORAGE EXTERNAL;++ INSERT INTO "VaultDataBucketsHistory_reordered" ("ManifestId", "Category", "RevisionNumber", "EncryptedData", "CiphertextHash", "KeyVersion", "CreatedAt", "UpdatedAt")+ SELECT "ManifestId", "Category", "RevisionNumber", "EncryptedData", "CiphertextHash", "KeyVersion", "CreatedAt", "UpdatedAt"+ FROM "VaultDataBucketsHistory";++ DROP TABLE "VaultDataBucketsHistory";+ ALTER TABLE "VaultDataBucketsHistory_reordered" RENAME TO "VaultDataBucketsHistory";++ ALTER TABLE "VaultDataBucketsHistory" ADD CONSTRAINT "PK_VaultDataBucketsHistory" PRIMARY KEY ("ManifestId", "Category", "RevisionNumber");+ """);+ }++ /// <summary>+ /// Moves the key version next to the ciphertext it applies to, leaving the timestamps at the end.+ /// </summary>+ /// <param name="migrationBuilder">Migration builder.</param>+ private static void RebuildVaultBlobObjects(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("""+ CREATE TABLE "VaultBlobObjects_reordered" (+ "Hash" character varying(64) NOT NULL,+ "OwnerUserId" character varying(255) NOT NULL,+ "Category" character varying(20) NOT NULL,+ "EncryptedData" bytea NOT NULL,+ "SizeBytes" integer NOT NULL,+ "KeyVersion" integer DEFAULT 0 NOT NULL,+ "CreatedAt" timestamp with time zone NOT NULL,+ "LastReferencedAt" timestamp with time zone NOT NULL+ );++ ALTER TABLE "VaultBlobObjects_reordered" ALTER COLUMN "EncryptedData" SET STORAGE EXTERNAL;++ INSERT INTO "VaultBlobObjects_reordered" ("Hash", "OwnerUserId", "Category", "EncryptedData", "SizeBytes", "KeyVersion", "CreatedAt", "LastReferencedAt")+ SELECT "Hash", "OwnerUserId", "Category", "EncryptedData", "SizeBytes", "KeyVersion", "CreatedAt", "LastReferencedAt"+ FROM "VaultBlobObjects";++ DROP TABLE "VaultBlobObjects";+ ALTER TABLE "VaultBlobObjects_reordered" RENAME TO "VaultBlobObjects";++ ALTER TABLE "VaultBlobObjects" ADD CONSTRAINT "PK_VaultBlobObjects" PRIMARY KEY ("Hash", "OwnerUserId");+ CREATE INDEX "IX_VaultBlobObjects_OwnerUserId_Category" ON "VaultBlobObjects" ("OwnerUserId", "Category");+ """);+ }++ /// <summary>+ /// Moves the account key version next to the key material it applies to instead of behind the timestamps.+ /// </summary>+ /// <param name="migrationBuilder">Migration builder.</param>+ private static void RebuildUserGrantKeys(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("""+ CREATE TABLE "UserGrantKeys_reordered" (+ "Id" uuid NOT NULL,+ "UserId" character varying(255) NOT NULL,+ "PublicKey" character varying(2000) NOT NULL,+ "EncryptedPrivateKey" character varying(4000) NOT NULL,+ "AccountKeyVersion" integer DEFAULT 0 NOT NULL,+ "IsPrimary" boolean NOT NULL,+ "CreatedAt" timestamp with time zone NOT NULL,+ "UpdatedAt" timestamp with time zone NOT NULL+ );++ INSERT INTO "UserGrantKeys_reordered" ("Id", "UserId", "PublicKey", "EncryptedPrivateKey", "AccountKeyVersion", "IsPrimary", "CreatedAt", "UpdatedAt")+ SELECT "Id", "UserId", "PublicKey", "EncryptedPrivateKey", "AccountKeyVersion", "IsPrimary", "CreatedAt", "UpdatedAt"+ FROM "UserGrantKeys";++ DROP TABLE "UserGrantKeys";+ ALTER TABLE "UserGrantKeys_reordered" RENAME TO "UserGrantKeys";++ ALTER TABLE "UserGrantKeys" ADD CONSTRAINT "PK_UserGrantKeys" PRIMARY KEY ("Id");+ CREATE UNIQUE INDEX "UX_UserGrantKeys_User_Primary" ON "UserGrantKeys" ("UserId") WHERE "IsPrimary";+ """);+ }++ /// <summary>+ /// Moves the label up next to the type it names, and the account key version next to the account key it+ /// applies to, matching the order of the unique index on the table.+ /// </summary>+ /// <param name="migrationBuilder">Migration builder.</param>+ private static void RebuildUserUnlockKeys(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("""+ CREATE TABLE "UserUnlockKeys_reordered" (+ "Id" uuid NOT NULL,+ "UserId" character varying(255) NOT NULL,+ "Type" character varying(30) NOT NULL,+ "Label" character varying(100) DEFAULT ''::character varying NOT NULL,+ "Algorithm" character varying(30) NOT NULL,+ "EncryptedAccountKey" text NOT NULL,+ "AccountKeyVersion" integer DEFAULT 0 NOT NULL,+ "Metadata" jsonb,+ "CreatedAt" timestamp with time zone NOT NULL,+ "UpdatedAt" timestamp with time zone NOT NULL,+ "LastUsedAt" timestamp with time zone+ );++ INSERT INTO "UserUnlockKeys_reordered" ("Id", "UserId", "Type", "Label", "Algorithm", "EncryptedAccountKey", "AccountKeyVersion", "Metadata", "CreatedAt", "UpdatedAt", "LastUsedAt")+ SELECT "Id", "UserId", "Type", "Label", "Algorithm", "EncryptedAccountKey", "AccountKeyVersion", "Metadata", "CreatedAt", "UpdatedAt", "LastUsedAt"+ FROM "UserUnlockKeys";++ DROP TABLE "UserUnlockKeys";+ ALTER TABLE "UserUnlockKeys_reordered" RENAME TO "UserUnlockKeys";++ ALTER TABLE "UserUnlockKeys" ADD CONSTRAINT "PK_UserUnlockKeys" PRIMARY KEY ("Id");+ CREATE UNIQUE INDEX "UX_UserUnlockKeys_UserId_Type_Label" ON "UserUnlockKeys" ("UserId", "Type", "Label");+ """);+ }++ /// <summary>+ /// Recreates every foreign key that was dropped up front, with the same names and delete behaviour as before.+ /// </summary>+ /// <param name="migrationBuilder">Migration builder.</param>+ private static void RecreateForeignKeys(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("""+ ALTER TABLE "AliasVaultUserRefreshTokens" ADD CONSTRAINT "FK_AliasVaultUserRefreshTokens_AliasVaultUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AliasVaultUsers"("Id") ON DELETE CASCADE;+ ALTER TABLE "AliasVaultUsers" ADD CONSTRAINT "FK_AliasVaultUsers_Groups_PersonalGroupId" FOREIGN KEY ("PersonalGroupId") REFERENCES "Groups"("Id") ON DELETE RESTRICT;+ ALTER TABLE "EmailAttachments" ADD CONSTRAINT "FK_EmailAttachments_Emails_EmailId" FOREIGN KEY ("EmailId") REFERENCES "Emails"("Id") ON DELETE CASCADE;+ ALTER TABLE "EmailClaimLinks" ADD CONSTRAINT "FK_EmailClaimLinks_VaultManifests_VaultManifestId" FOREIGN KEY ("VaultManifestId") REFERENCES "VaultManifests"("ManifestId") ON DELETE CASCADE;+ ALTER TABLE "EmailKeyWraps" ADD CONSTRAINT "FK_EmailKeyWraps_Emails_EmailId" FOREIGN KEY ("EmailId") REFERENCES "Emails"("Id") ON DELETE CASCADE;+ ALTER TABLE "EmailKeyWraps" ADD CONSTRAINT "FK_EmailKeyWraps_VaultManifestDeliveryKeys_EncryptionKeyId" FOREIGN KEY ("EncryptionKeyId") REFERENCES "VaultManifestDeliveryKeys"("Id") ON DELETE CASCADE;+ ALTER TABLE "GroupMembers" ADD CONSTRAINT "FK_GroupMembers_AliasVaultUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AliasVaultUsers"("Id") ON DELETE CASCADE;+ ALTER TABLE "MobileLoginRequests" ADD CONSTRAINT "FK_MobileLoginRequests_AliasVaultUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AliasVaultUsers"("Id") ON DELETE CASCADE;+ ALTER TABLE "RateLimits" ADD CONSTRAINT "FK_RateLimits_Groups_GroupId" FOREIGN KEY ("GroupId") REFERENCES "Groups"("Id") ON DELETE CASCADE;+ ALTER TABLE "UserGrantKeys" ADD CONSTRAINT "FK_UserGrantKeys_AliasVaultUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AliasVaultUsers"("Id") ON DELETE CASCADE;+ ALTER TABLE "UserUnlockKeys" ADD CONSTRAINT "FK_UserUnlockKeys_AliasVaultUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AliasVaultUsers"("Id") ON DELETE CASCADE;+ ALTER TABLE "VaultBlobObjects" ADD CONSTRAINT "FK_VaultBlobObjects_AliasVaultUsers_OwnerUserId" FOREIGN KEY ("OwnerUserId") REFERENCES "AliasVaultUsers"("Id") ON DELETE CASCADE;+ ALTER TABLE "VaultBlobReferences" ADD CONSTRAINT "FK_VaultBlobReferences_VaultManifests_ManifestId" FOREIGN KEY ("ManifestId") REFERENCES "VaultManifests"("ManifestId") ON DELETE CASCADE;+ ALTER TABLE "VaultDataBuckets" ADD CONSTRAINT "FK_VaultDataBuckets_VaultManifests_ManifestId" FOREIGN KEY ("ManifestId") REFERENCES "VaultManifests"("ManifestId") ON DELETE CASCADE;+ ALTER TABLE "VaultDataBucketsHistory" ADD CONSTRAINT "FK_VaultDataBucketsHistory_VaultDataBuckets_ManifestId_Category" FOREIGN KEY ("ManifestId", "Category") REFERENCES "VaultDataBuckets"("ManifestId", "Category") ON DELETE CASCADE;+ ALTER TABLE "VaultManifestAccessKeys" ADD CONSTRAINT "FK_VaultManifestAccessKeys_AliasVaultUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AliasVaultUsers"("Id") ON DELETE CASCADE;+ ALTER TABLE "VaultManifestAccessKeys" ADD CONSTRAINT "FK_VaultManifestAccessKeys_UserGrantKeys_UserGrantKeyId" FOREIGN KEY ("UserGrantKeyId") REFERENCES "UserGrantKeys"("Id") ON DELETE SET NULL;+ ALTER TABLE "VaultManifestDeliveryKeys" ADD CONSTRAINT "FK_VaultManifestDeliveryKeys_VaultManifests_VaultManifestId" FOREIGN KEY ("VaultManifestId") REFERENCES "VaultManifests"("ManifestId") ON DELETE CASCADE;+ ALTER TABLE "VaultManifests" ADD CONSTRAINT "FK_VaultManifests_Groups_OwnerGroupId" FOREIGN KEY ("OwnerGroupId") REFERENCES "Groups"("Id") ON DELETE CASCADE;+ ALTER TABLE "VaultManifestsHistory" ADD CONSTRAINT "FK_VaultManifestsHistory_VaultManifests_ManifestId" FOREIGN KEY ("ManifestId") REFERENCES "VaultManifests"("ManifestId") ON DELETE CASCADE;+ """);+ }+ }+}diff --git a/core/rust/src/wasm.rs b/core/rust/src/wasm.rsindex 74f50b3db..79995533e 100644--- a/core/rust/src/wasm.rs+++ b/core/rust/src/wasm.rs@@ -384,9 +384,11 @@ pub fn decode_email_source_js(source: &[u8]) -> Result<Vec<u8>, JsValue> {}/// Extract the decoded bytes of one attachment, identified by its index in the parsed attachment list.+/// An attachment the parse result flagged as `detached` carries no body in the source; pass its separately+/// fetched body as `detachedBody`. It is ignored for attachments that are still inline.#[wasm_bindgen(js_name = extractEmailAttachment)]-pub fn extract_email_attachment_js(source: &[u8], index: usize) -> Result<Vec<u8>, JsValue> {- crate::email_parser::extract_email_attachment(source, index)+pub fn extract_email_attachment_js(source: &[u8], index: usize, detached_body: Option<Box<[u8]>>) -> Result<Vec<u8>, JsValue> {+ crate::email_parser::extract_email_attachment(source, index, detached_body.as_deref()).map_err(|e| JsValue::from_str(&format!("Email attachment extraction failed: {}", e)))}