Skip to content

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

Update and squash DB migrations (#2159)

Leendert de Borst4c8e151baf26
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.Designer.cs b/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.Designer.cs
index 9223ffd5e..58473acfc 100644
--- a/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.Designer.cs
+++ b/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.Designer.cs
@@ -28,25 +28,6 @@ namespace AliasServerDb.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
- modelBuilder.Entity("AliasServerDb.AdminRole", b =>
- {
- b.Property<string>("Id")
- .HasColumnType("text");
-
- b.Property<string>("ConcurrencyStamp")
- .HasColumnType("text");
-
- b.Property<string>("Name")
- .HasColumnType("text");
-
- b.Property<string>("NormalizedName")
- .HasColumnType("text");
-
- b.HasKey("Id");
-
- b.ToTable("AdminRoles");
- });
-
modelBuilder.Entity("AliasServerDb.AdminUser", b =>
{
b.Property<string>("Id")
@@ -102,25 +83,6 @@ namespace AliasServerDb.Migrations
b.ToTable("AdminUsers");
});
- modelBuilder.Entity("AliasServerDb.AliasVaultRole", b =>
- {
- b.Property<string>("Id")
- .HasColumnType("text");
-
- b.Property<string>("ConcurrencyStamp")
- .HasColumnType("text");
-
- b.Property<string>("Name")
- .HasColumnType("text");
-
- b.Property<string>("NormalizedName")
- .HasColumnType("text");
-
- b.HasKey("Id");
-
- b.ToTable("AliasVaultRoles");
- });
-
modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>
{
b.Property<string>("Id")
@@ -378,20 +340,15 @@ namespace AliasServerDb.Migrations
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>("EncryptedSymmetricKey")
- .IsRequired()
- .HasColumnType("text");
-
- b.Property<Guid>("EncryptionKeyId")
- .HasMaxLength(255)
- .HasColumnType("uuid");
-
b.Property<string>("From")
.IsRequired()
.HasColumnType("text");
@@ -414,9 +371,11 @@ namespace AliasServerDb.Migrations
.HasColumnType("text");
b.Property<string>("MessageSource")
- .IsRequired()
.HasColumnType("text");
+ b.Property<byte[]>("MessageSourceBytes")
+ .HasColumnType("bytea");
+
b.Property<bool>("PushNotificationSent")
.HasColumnType("boolean");
@@ -445,8 +404,6 @@ namespace AliasServerDb.Migrations
b.HasIndex("DateSystem");
- b.HasIndex("EncryptionKeyId");
-
b.HasIndex("PushNotificationSent");
b.HasIndex("Visible");
@@ -513,28 +470,90 @@ namespace AliasServerDb.Migrations
.HasMaxLength(255)
.HasColumnType("character varying(255)");
+ b.Property<bool>("AnonymizedSenderCounted")
+ .HasColumnType("boolean");
+
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.Property<Guid?>("VaultManifestId")
- .HasColumnType("uuid");
-
b.HasKey("Id");
b.HasIndex("Address")
.IsUnique();
- b.HasIndex("VaultManifestId", "CreatedAt");
+ b.ToTable("EmailClaims");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailClaimLink", b =>
+ {
+ b.Property<Guid>("EmailClaimId")
+ .HasColumnType("uuid");
- b.HasIndex("VaultManifestId", "Disabled");
+ b.Property<Guid>("VaultManifestId")
+ .HasColumnType("uuid");
- b.ToTable("EmailClaims");
+ b.Property<string>("State")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.HasKey("EmailClaimId", "VaultManifestId");
+
+ b.HasIndex("EmailClaimId")
+ .HasDatabaseName("IX_EmailClaimLinks_EmailClaimId_Live")
+ .HasFilter("\"State\" <> 'Removed'");
+
+ b.HasIndex("VaultManifestId", "EmailClaimId");
+
+ b.ToTable("EmailClaimLinks");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailDecryptionKey", b =>
+ {
+ b.Property<int>("EmailId")
+ .HasColumnType("integer");
+
+ b.Property<Guid>("VaultManifestDeliveryKeyId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("EncryptedSymmetricKey")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("EmailId", "VaultManifestDeliveryKeyId");
+
+ b.HasIndex("VaultManifestDeliveryKeyId", "EmailId");
+
+ b.ToTable("EmailDecryptionKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailPart", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<byte[]>("Bytes")
+ .IsRequired()
+ .HasColumnType("bytea");
+
+ b.Property<int>("EmailId")
+ .HasColumnType("integer");
+
+ b.Property<int>("PartIndex")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("EmailId", "PartIndex")
+ .IsUnique();
+
+ b.ToTable("EmailParts");
});
modelBuilder.Entity("AliasServerDb.Group", b =>
@@ -543,6 +562,12 @@ namespace AliasServerDb.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
+ b.PrimitiveCollection<int[]>("AnonymizedEmailAliasSenderCounts")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer[]")
+ .HasDefaultValueSql("array_fill(0, ARRAY[64])");
+
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
@@ -1422,28 +1447,6 @@ namespace AliasServerDb.Migrations
b.ToTable("DataProtectionKeys");
});
- modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<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>("RoleId")
- .HasColumnType("text");
-
- b.HasKey("Id");
-
- b.ToTable("RoleClaims", (string)null);
- });
-
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
@@ -1466,38 +1469,6 @@ namespace AliasServerDb.Migrations
b.ToTable("UserClaims", (string)null);
});
- modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
- {
- b.Property<string>("LoginProvider")
- .HasColumnType("text");
-
- b.Property<string>("ProviderKey")
- .HasColumnType("text");
-
- b.Property<string>("ProviderDisplayName")
- .HasColumnType("text");
-
- b.Property<string>("UserId")
- .HasColumnType("text");
-
- b.HasKey("LoginProvider", "ProviderKey");
-
- b.ToTable("UserLogins", (string)null);
- });
-
- modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
- {
- b.Property<string>("UserId")
- .HasColumnType("text");
-
- b.Property<string>("RoleId")
- .HasColumnType("text");
-
- b.HasKey("UserId", "RoleId");
-
- b.ToTable("UserRoles", (string)null);
- });
-
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
@@ -1539,17 +1510,6 @@ namespace AliasServerDb.Migrations
b.Navigation("User");
});
- modelBuilder.Entity("AliasServerDb.Email", b =>
- {
- b.HasOne("AliasServerDb.VaultManifestDeliveryKey", "EncryptionKey")
- .WithMany("Emails")
- .HasForeignKey("EncryptionKeyId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("EncryptionKey");
- });
-
modelBuilder.Entity("AliasServerDb.EmailAttachment", b =>
{
b.HasOne("AliasServerDb.Email", "Email")
@@ -1561,16 +1521,56 @@ namespace AliasServerDb.Migrations
b.Navigation("Email");
});
- modelBuilder.Entity("AliasServerDb.EmailClaim", b =>
+ 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.SetNull);
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("EmailClaim");
b.Navigation("VaultManifest");
});
+ modelBuilder.Entity("AliasServerDb.EmailDecryptionKey", b =>
+ {
+ b.HasOne("AliasServerDb.Email", "Email")
+ .WithMany("DecryptionKeys")
+ .HasForeignKey("EmailId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasServerDb.VaultManifestDeliveryKey", "VaultManifestDeliveryKey")
+ .WithMany("DecryptionKeys")
+ .HasForeignKey("VaultManifestDeliveryKeyId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired()
+ .HasConstraintName("FK_EmailDecryptionKeys_VaultManifestDeliveryKeys_DeliveryKeyId");
+
+ b.Navigation("Email");
+
+ b.Navigation("VaultManifestDeliveryKey");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailPart", b =>
+ {
+ b.HasOne("AliasServerDb.Email", "Email")
+ .WithMany("Parts")
+ .HasForeignKey("EmailId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Email");
+ });
+
modelBuilder.Entity("AliasServerDb.GroupMember", b =>
{
b.HasOne("AliasServerDb.Group", "Group")
@@ -1760,6 +1760,15 @@ namespace AliasServerDb.Migrations
modelBuilder.Entity("AliasServerDb.Email", b =>
{
b.Navigation("Attachments");
+
+ b.Navigation("DecryptionKeys");
+
+ b.Navigation("Parts");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailClaim", b =>
+ {
+ b.Navigation("Links");
});
modelBuilder.Entity("AliasServerDb.Group", b =>
@@ -1769,7 +1778,7 @@ namespace AliasServerDb.Migrations
modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>
{
- b.Navigation("Emails");
+ b.Navigation("DecryptionKeys");
});
#pragma warning restore 612, 618
}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.cs b/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.cs
index b407bd83b..74329cea3 100644
--- a/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.cs
+++ b/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.cs
@@ -1,42 +1,41 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace AliasServerDb.Migrations
{
/// <summary>
- /// Moves vault storage to the manifest model and makes groups the ownership path for everything a user owns.
- ///
- /// Existing rows are carried over in place:
- /// - every user gains a Personal group that takes over their vault, aliases, quotas and rate limit overrides,
- /// - the append-only "Vaults" revision log becomes one "VaultManifests" head row per user plus a
- /// "VaultManifestsHistory" tail, keyed by a newly generated manifest id,
- /// - per-user email encryption keys become per-manifest delivery keys,
- /// - every stored public key records the algorithm it belongs to.
- ///
- /// The tables that only the manifest-v1 write path uses (buckets, blobs, grant, access and unlock keys) start empty. Every
- /// ciphertext they hold carries the version of the key it was written with, so a future key rotation can tell the
- /// generations apart.
+ /// Moves vault and email storage onto group-owned manifests.
/// </summary>
public partial class ManifestStorageAndGroupOwnership : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
+ DropForeignKeysToUsers(migrationBuilder);
+ CreateUserMigrationMap(migrationBuilder);
IntroduceGroups(migrationBuilder);
ConvertVaultsToManifests(migrationBuilder);
- ScopeEmailClaimsToManifests(migrationBuilder);
+ LinkEmailClaimsToManifests(migrationBuilder);
ScopeDeliveryKeysToManifests(migrationBuilder);
- AddAlgorithmToPublicKeys(migrationBuilder);
ScopeRateLimitsToGroups(migrationBuilder);
+ AddAlgorithmToMobileLoginRequests(migrationBuilder);
+ MoveMessageSourceToBytes(migrationBuilder);
+ AddDetachedMessageParts(migrationBuilder);
AddManifestV1Tables(migrationBuilder);
SkipToastCompressionOnCiphertextColumns(migrationBuilder);
+ AddForeignKeys(migrationBuilder);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
+ RemoveAnonymizedSenderCounts(migrationBuilder);
+ DropDetachedMessageParts(migrationBuilder);
+ RestoreMessageSourceText(migrationBuilder);
+ RestoreSingleManifestLinks(migrationBuilder);
DropManifestV1Tables(migrationBuilder);
RestoreRateLimitsToUsers(migrationBuilder);
RemoveAlgorithmFromPublicKeys(migrationBuilder);
@@ -46,10 +45,29 @@ namespace AliasServerDb.Migrations
RemoveGroups(migrationBuilder);
}
- /// <summary>
- /// Adds the group tables and gives every existing user a Personal group holding their email quotas.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
+ private static void DropForeignKeysToUsers(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(name: "FK_AliasVaultUserRefreshTokens_AliasVaultUsers_UserId", table: "AliasVaultUserRefreshTokens");
+ migrationBuilder.DropForeignKey(name: "FK_MobileLoginRequests_AliasVaultUsers_UserId", table: "MobileLoginRequests");
+ migrationBuilder.DropForeignKey(name: "FK_RateLimits_AliasVaultUsers_UserId", table: "RateLimits");
+ migrationBuilder.DropForeignKey(name: "FK_UserEmailClaims_AliasVaultUsers_UserId", table: "UserEmailClaims");
+ migrationBuilder.DropForeignKey(name: "FK_UserEncryptionKeys_AliasVaultUsers_UserId", table: "UserEncryptionKeys");
+ migrationBuilder.DropForeignKey(name: "FK_Vaults_AliasVaultUsers_UserId", table: "Vaults");
+ }
+
+ private static void CreateUserMigrationMap(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.Sql("""
+ CREATE TEMP TABLE "UserMigrationMap" ON COMMIT DROP AS
+ SELECT u."Id" AS "UserId", gen_random_uuid() AS "GroupId",
+ CASE WHEN EXISTS (SELECT 1 FROM "Vaults" v WHERE v."UserId" = u."Id") THEN gen_random_uuid() END AS "ManifestId"
+ FROM "AliasVaultUsers" u;
+
+ ALTER TABLE "UserMigrationMap" ADD PRIMARY KEY ("UserId");
+ ANALYZE "UserMigrationMap";
+ """);
+ }
+
private static void IntroduceGroups(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
@@ -64,6 +82,7 @@ namespace AliasServerDb.Migrations
MaxEmails = table.Column<int>(type: "integer", nullable: false),
MaxEmailAgeDays = table.Column<int>(type: "integer", nullable: false),
EmailsReceived = table.Column<int>(type: "integer", nullable: false),
+ AnonymizedEmailAliasSenderCounts = table.Column<int[]>(type: "integer[]", nullable: false, defaultValueSql: "array_fill(0, ARRAY[64])"),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
@@ -86,99 +105,85 @@ namespace AliasServerDb.Migrations
constraints: table =>
{
table.PrimaryKey("PK_GroupMembers", x => x.Id);
- table.ForeignKey(
- name: "FK_GroupMembers_AliasVaultUsers_UserId",
- column: x => x.UserId,
- principalTable: "AliasVaultUsers",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
- table.ForeignKey(
- name: "FK_GroupMembers_Groups_GroupId",
- column: x => x.GroupId,
- principalTable: "Groups",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
});
- migrationBuilder.CreateIndex(name: "IX_GroupMembers_GroupId_UserId", table: "GroupMembers", columns: new[] { "GroupId", "UserId" }, unique: true);
- migrationBuilder.CreateIndex(name: "IX_GroupMembers_UserId", table: "GroupMembers", column: "UserId");
-
- migrationBuilder.AddColumn<Guid>(name: "PersonalGroupId", table: "AliasVaultUsers", type: "uuid", nullable: true);
-
- // Every user owns exactly one Personal group (type 0) and is its owner (role 0). The abuse counters and
- // email limits are charged to the group that owns the content from here on, so they move across with it.
+ // Personal group is type 0, owner is role 0.
migrationBuilder.Sql("""
- UPDATE "AliasVaultUsers" SET "PersonalGroupId" = gen_random_uuid() WHERE "PersonalGroupId" IS NULL;
-
INSERT INTO "Groups" ("Id", "Name", "Type", "ShadowBlocked", "ShadowBlockedAt", "MaxEmails", "MaxEmailAgeDays", "EmailsReceived", "CreatedAt", "UpdatedAt")
- SELECT u."PersonalGroupId", COALESCE(u."UserName", 'Personal'), 0, u."ShadowBlocked", u."ShadowBlockedAt", u."MaxEmails", u."MaxEmailAgeDays", u."EmailsReceived", now(), now()
- FROM "AliasVaultUsers" u;
+ SELECT m."GroupId", COALESCE(u."UserName", 'Personal'), 0, u."ShadowBlocked", u."ShadowBlockedAt", u."MaxEmails", u."MaxEmailAgeDays", u."EmailsReceived", now(), now()
+ FROM "AliasVaultUsers" u
+ JOIN "UserMigrationMap" m ON m."UserId" = u."Id";
INSERT INTO "GroupMembers" ("Id", "GroupId", "UserId", "Role", "CreatedAt", "UpdatedAt")
- SELECT gen_random_uuid(), u."PersonalGroupId", u."Id", 0, now(), now()
- FROM "AliasVaultUsers" u;
- """);
+ SELECT gen_random_uuid(), m."GroupId", m."UserId", 0, now(), now()
+ FROM "UserMigrationMap" m;
+
+ 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 u."Id", u."UserName", u."NormalizedUserName", u."Email", u."NormalizedEmail", u."EmailConfirmed", u."SrpIdentity", m."GroupId", u."PasswordHash", u."SecurityStamp", u."ConcurrencyStamp", u."Blocked", u."BlockedAt", u."LastActivityDate", u."PasswordChangedAt", u."CreatedAt", u."UpdatedAt", u."PhoneNumber", u."PhoneNumberConfirmed", u."TwoFactorEnabled", u."LockoutEnd", u."LockoutEnabled", u."AccessFailedCount"
+ FROM "AliasVaultUsers" u
+ JOIN "UserMigrationMap" m ON m."UserId" = u."Id";
- migrationBuilder.AlterColumn<Guid>(
- name: "PersonalGroupId",
- table: "AliasVaultUsers",
- type: "uuid",
- nullable: false,
- oldClrType: typeof(Guid),
- oldType: "uuid",
- oldNullable: true);
+ DROP TABLE "AliasVaultUsers";
+ ALTER TABLE "AliasVaultUsers_reordered" RENAME TO "AliasVaultUsers";
+ ALTER TABLE "AliasVaultUsers" ADD CONSTRAINT "PK_AliasVaultUsers" PRIMARY KEY ("Id");
+ """);
migrationBuilder.CreateIndex(name: "UX_AliasVaultUsers_PersonalGroupId", table: "AliasVaultUsers", column: "PersonalGroupId", unique: true);
-
- migrationBuilder.AddForeignKey(
- name: "FK_AliasVaultUsers_Groups_PersonalGroupId",
- table: "AliasVaultUsers",
- column: "PersonalGroupId",
- principalTable: "Groups",
- principalColumn: "Id",
- onDelete: ReferentialAction.Restrict);
-
- migrationBuilder.DropColumn(name: "ShadowBlocked", table: "AliasVaultUsers");
- migrationBuilder.DropColumn(name: "ShadowBlockedAt", table: "AliasVaultUsers");
- migrationBuilder.DropColumn(name: "MaxEmails", table: "AliasVaultUsers");
- migrationBuilder.DropColumn(name: "MaxEmailAgeDays", table: "AliasVaultUsers");
- migrationBuilder.DropColumn(name: "EmailsReceived", table: "AliasVaultUsers");
+ migrationBuilder.CreateIndex(name: "IX_GroupMembers_GroupId_UserId", table: "GroupMembers", columns: new[] { "GroupId", "UserId" }, unique: true);
+ migrationBuilder.CreateIndex(name: "IX_GroupMembers_UserId", table: "GroupMembers", column: "UserId");
}
- /// <summary>
- /// Turns the per-revision "Vaults" log into a group-owned manifest plus its revision history.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
private static void ConvertVaultsToManifests(MigrationBuilder migrationBuilder)
{
- migrationBuilder.DropForeignKey(name: "FK_Vaults_AliasVaultUsers_UserId", table: "Vaults");
- migrationBuilder.DropIndex(name: "IX_Vaults_UserId", table: "Vaults");
- migrationBuilder.RenameTable(name: "Vaults", newName: "VaultManifests");
- migrationBuilder.Sql("""ALTER TABLE "VaultManifests" RENAME CONSTRAINT "PK_Vaults" TO "PK_VaultManifests";""");
-
- migrationBuilder.AddColumn<Guid>(name: "ManifestId", table: "VaultManifests", type: "uuid", nullable: true);
- migrationBuilder.AddColumn<Guid>(name: "OwnerGroupId", table: "VaultManifests", type: "uuid", nullable: true);
- migrationBuilder.AddColumn<string>(name: "StorageFormat", table: "VaultManifests", type: "character varying(20)", maxLength: 20, nullable: true);
- migrationBuilder.AddColumn<byte[]>(name: "ManifestBlob", table: "VaultManifests", type: "bytea", nullable: true);
- migrationBuilder.AddColumn<string>(name: "ManifestCiphertextHash", table: "VaultManifests", type: "character varying(64)", maxLength: 64, nullable: true);
- migrationBuilder.AddColumn<int>(name: "KeyVersion", table: "VaultManifests", type: "integer", nullable: false, defaultValue: 0);
- migrationBuilder.AddColumn<string>(name: "UpdatedByUserId", table: "VaultManifests", type: "character varying(255)", maxLength: 255, nullable: true);
-
- // A manifest-v1 revision carries no vault blob and no SRP credentials, so the columns that only the legacy
- // sqlite-blob format fills become nullable. NULL is the sole "not applicable" marker; the empty string is not.
- MakeLegacyRevisionColumnsNullable(migrationBuilder, "VaultManifests");
-
- // Every revision of a user's vault belongs to one manifest, owned by that user's personal group.
migrationBuilder.Sql("""
- UPDATE "VaultManifests" v
- SET "ManifestId" = ids.gid
- FROM (SELECT "UserId", gen_random_uuid() AS gid FROM "VaultManifests" GROUP BY "UserId") ids
- WHERE v."UserId" = ids."UserId";
-
- UPDATE "VaultManifests" v
- SET "OwnerGroupId" = u."PersonalGroupId", "StorageFormat" = 'sqlite-blob'
- FROM "AliasVaultUsers" u
- WHERE u."Id" = v."UserId";
+ CREATE TABLE "VaultManifests" (
+ "VaultBlob" text,
+ "Version" character varying(255),
+ "RevisionNumber" bigint NOT NULL,
+ "FileSize" integer NOT NULL,
+ "Salt" character varying(100),
+ "Verifier" character varying(1000),
+ "CredentialsCount" integer NOT NULL,
+ "EmailClaimsCount" integer NOT NULL,
+ "EncryptionType" text,
+ "EncryptionSettings" text,
+ "CreatedAt" timestamp with time zone NOT NULL,
+ "UpdatedAt" timestamp with time zone NOT NULL,
+ "Client" character varying(255),
+ "ManifestId" uuid NOT NULL,
+ "OwnerGroupId" uuid NOT NULL,
+ "StorageFormat" character varying(20) NOT NULL,
+ "ManifestBlob" bytea,
+ "ManifestCiphertextHash" character varying(64),
+ "KeyVersion" integer DEFAULT 0 NOT NULL,
+ "UpdatedByUserId" character varying(255)
+ );
""");
migrationBuilder.CreateTable(
@@ -204,253 +209,233 @@ namespace AliasServerDb.Migrations
Verifier = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
EncryptionType = table.Column<string>(type: "text", nullable: true),
EncryptionSettings = table.Column<string>(type: "text", nullable: true)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_VaultManifestsHistory", x => new { x.ManifestId, x.RevisionNumber });
});
- // The newest revision stays behind as the manifest head; everything older becomes history.
+ // Newest revision is the head; older ones go to history.
migrationBuilder.Sql("""
- INSERT INTO "VaultManifestsHistory" ("ManifestId", "RevisionNumber", "VaultBlob", "StorageFormat", "ManifestBlob", "ManifestCiphertextHash", "Version", "FileSize", "Salt", "Verifier", "CredentialsCount", "EmailClaimsCount", "EncryptionType", "EncryptionSettings", "Client", "CreatedAt", "UpdatedAt")
- SELECT "ManifestId", "RevisionNumber", "VaultBlob", "StorageFormat", "ManifestBlob", "ManifestCiphertextHash", "Version", "FileSize", "Salt", "Verifier", "CredentialsCount", "EmailClaimsCount", "EncryptionType", "EncryptionSettings", "Client", "CreatedAt", "UpdatedAt"
+ CREATE TEMP TABLE "VaultRevisionRanks" ON COMMIT DROP AS
+ SELECT "Id", "UserId", "RevisionNumber", ROW_NUMBER() OVER (PARTITION BY "UserId" ORDER BY "RevisionNumber" DESC, "CreatedAt" DESC, "Id" DESC) AS "Rank"
+ FROM "Vaults";
+
+ INSERT INTO "VaultManifests" ("VaultBlob", "Version", "RevisionNumber", "FileSize", "Salt", "Verifier", "CredentialsCount", "EmailClaimsCount", "EncryptionType", "EncryptionSettings", "CreatedAt", "UpdatedAt", "Client", "ManifestId", "OwnerGroupId", "StorageFormat")
+ SELECT v."VaultBlob", v."Version", v."RevisionNumber", v."FileSize", v."Salt", v."Verifier", v."CredentialsCount", v."EmailClaimsCount", v."EncryptionType", v."EncryptionSettings", v."CreatedAt", v."UpdatedAt", v."Client", m."ManifestId", m."GroupId", 'sqlite-blob'
+ FROM "VaultRevisionRanks" r
+ JOIN "Vaults" v ON v."Id" = r."Id"
+ JOIN "UserMigrationMap" m ON m."UserId" = r."UserId"
+ WHERE r."Rank" = 1;
+
+ INSERT INTO "VaultManifestsHistory" ("ManifestId", "RevisionNumber", "StorageFormat", "FileSize", "CredentialsCount", "EmailClaimsCount", "Client", "CreatedAt", "UpdatedAt", "VaultBlob", "Version", "Salt", "Verifier", "EncryptionType", "EncryptionSettings")
+ SELECT m."ManifestId", v."RevisionNumber", 'sqlite-blob', v."FileSize", v."CredentialsCount", v."EmailClaimsCount", v."Client", v."CreatedAt", v."UpdatedAt", v."VaultBlob", v."Version", v."Salt", v."Verifier", v."EncryptionType", v."EncryptionSettings"
FROM (
- SELECT v.*, ROW_NUMBER() OVER (PARTITION BY "ManifestId" ORDER BY "RevisionNumber" DESC, "CreatedAt" DESC, "Id" DESC) AS rn
- FROM "VaultManifests" v
- ) ranked
- WHERE ranked.rn > 1
- ON CONFLICT ("ManifestId", "RevisionNumber") DO NOTHING;
-
- DELETE FROM "VaultManifests" v
- USING (
- SELECT "Id", ROW_NUMBER() OVER (PARTITION BY "ManifestId" ORDER BY "RevisionNumber" DESC, "CreatedAt" DESC, "Id" DESC) AS rn
- FROM "VaultManifests"
- ) ranked
- WHERE v."Id" = ranked."Id" AND ranked.rn > 1;
+ SELECT DISTINCT ON ("UserId", "RevisionNumber") "Id", "UserId"
+ FROM "VaultRevisionRanks"
+ WHERE "Rank" > 1
+ ORDER BY "UserId", "RevisionNumber", "Rank"
+ ) r
+ JOIN "Vaults" v ON v."Id" = r."Id"
+ JOIN "UserMigrationMap" m ON m."UserId" = r."UserId";
+
+ DROP TABLE "Vaults";
""");
- // Swap the per-revision key for the manifest key now that there is exactly one row per manifest.
- migrationBuilder.DropPrimaryKey(name: "PK_VaultManifests", table: "VaultManifests");
- migrationBuilder.DropColumn(name: "Id", table: "VaultManifests");
- migrationBuilder.DropColumn(name: "UserId", table: "VaultManifests");
-
- migrationBuilder.AlterColumn<Guid>(
- name: "ManifestId",
- table: "VaultManifests",
- type: "uuid",
- nullable: false,
- oldClrType: typeof(Guid),
- oldType: "uuid",
- oldNullable: true);
-
- migrationBuilder.AlterColumn<Guid>(
- name: "OwnerGroupId",
- table: "VaultManifests",
- type: "uuid",
- nullable: false,
- oldClrType: typeof(Guid),
- oldType: "uuid",
- oldNullable: true);
-
- migrationBuilder.AlterColumn<string>(
- name: "StorageFormat",
- table: "VaultManifests",
- type: "character varying(20)",
- maxLength: 20,
- nullable: false,
- oldClrType: typeof(string),
- oldType: "character varying(20)",
- oldMaxLength: 20,
- oldNullable: true);
-
migrationBuilder.AddPrimaryKey(name: "PK_VaultManifests", table: "VaultManifests", column: "ManifestId");
+ migrationBuilder.AddPrimaryKey(name: "PK_VaultManifestsHistory", table: "VaultManifestsHistory", columns: new[] { "ManifestId", "RevisionNumber" });
migrationBuilder.CreateIndex(name: "IX_VaultManifests_OwnerGroupId", table: "VaultManifests", column: "OwnerGroupId");
migrationBuilder.CreateIndex(name: "IX_VaultManifests_UpdatedByUserId", table: "VaultManifests", column: "UpdatedByUserId");
migrationBuilder.CreateIndex(name: "IX_VaultManifestsHistory_UpdatedByUserId", table: "VaultManifestsHistory", column: "UpdatedByUserId");
-
- migrationBuilder.AddForeignKey(
- name: "FK_VaultManifests_Groups_OwnerGroupId",
- table: "VaultManifests",
- column: "OwnerGroupId",
- principalTable: "Groups",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
-
- migrationBuilder.AddForeignKey(
- name: "FK_VaultManifestsHistory_VaultManifests_ManifestId",
- table: "VaultManifestsHistory",
- column: "ManifestId",
- principalTable: "VaultManifests",
- principalColumn: "ManifestId",
- onDelete: ReferentialAction.Cascade);
-
- migrationBuilder.AddForeignKey(
- name: "FK_VaultManifests_AliasVaultUsers_UpdatedByUserId",
- table: "VaultManifests",
- column: "UpdatedByUserId",
- principalTable: "AliasVaultUsers",
- principalColumn: "Id",
- onDelete: ReferentialAction.SetNull);
-
- migrationBuilder.AddForeignKey(
- name: "FK_VaultManifestsHistory_AliasVaultUsers_UpdatedByUserId",
- table: "VaultManifestsHistory",
- column: "UpdatedByUserId",
- principalTable: "AliasVaultUsers",
- principalColumn: "Id",
- onDelete: ReferentialAction.SetNull);
}
- /// <summary>
- /// Repoints email aliases from their user to the manifest that holds the alias, which is what mail delivery
- /// resolves the recipient's encryption key through.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
- private static void ScopeEmailClaimsToManifests(MigrationBuilder migrationBuilder)
+ private static void LinkEmailClaimsToManifests(MigrationBuilder migrationBuilder)
{
- migrationBuilder.DropForeignKey(name: "FK_UserEmailClaims_AliasVaultUsers_UserId", table: "UserEmailClaims");
- migrationBuilder.DropIndex(name: "IX_UserEmailClaims_UserId_CreatedAt", table: "UserEmailClaims");
- migrationBuilder.DropIndex(name: "IX_UserEmailClaims_UserId_Disabled", table: "UserEmailClaims");
- migrationBuilder.RenameTable(name: "UserEmailClaims", newName: "EmailClaims");
- migrationBuilder.Sql("""ALTER TABLE "EmailClaims" RENAME CONSTRAINT "PK_UserEmailClaims" TO "PK_EmailClaims";""");
- migrationBuilder.RenameIndex(name: "IX_UserEmailClaims_Address", table: "EmailClaims", newName: "IX_EmailClaims_Address");
+ migrationBuilder.CreateTable(
+ name: "EmailClaims",
+ columns: table => new
+ {
+ Id = table.Column<Guid>(type: "uuid", nullable: false),
+ Address = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
+ AddressLocal = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
+ AddressDomain = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
+ AnonymizedSenderCounted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
+ CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
+ UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
+ });
- migrationBuilder.AddColumn<Guid>(name: "VaultManifestId", table: "EmailClaims", type: "uuid", nullable: true);
+ migrationBuilder.CreateTable(
+ name: "EmailClaimLinks",
+ columns: table => new
+ {
+ EmailClaimId = table.Column<Guid>(type: "uuid", nullable: false),
+ VaultManifestId = table.Column<Guid>(type: "uuid", nullable: false),
+ State = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false)
+ });
- // A claim of a user who never uploaded a vault has no manifest to hang off and stays unassigned.
migrationBuilder.Sql("""
- UPDATE "EmailClaims" c
- SET "VaultManifestId" = m."ManifestId"
- FROM "AliasVaultUsers" u
- JOIN "VaultManifests" m ON m."OwnerGroupId" = u."PersonalGroupId"
- WHERE u."Id" = c."UserId";
+ INSERT INTO "EmailClaims" ("Id", "Address", "AddressLocal", "AddressDomain", "CreatedAt", "UpdatedAt")
+ SELECT "Id", "Address", "AddressLocal", "AddressDomain", "CreatedAt", "UpdatedAt"
+ FROM "UserEmailClaims";
+
+ INSERT INTO "EmailClaimLinks" ("EmailClaimId", "VaultManifestId", "State")
+ SELECT c."Id", m."ManifestId", CASE WHEN c."Disabled" THEN 'Removed' ELSE 'Active' END
+ FROM "UserEmailClaims" c
+ JOIN "UserMigrationMap" m ON m."UserId" = c."UserId"
+ WHERE m."ManifestId" IS NOT NULL;
""");
- migrationBuilder.DropColumn(name: "UserId", table: "EmailClaims");
-
- migrationBuilder.CreateIndex(name: "IX_EmailClaims_VaultManifestId_CreatedAt", table: "EmailClaims", columns: new[] { "VaultManifestId", "CreatedAt" });
- migrationBuilder.CreateIndex(name: "IX_EmailClaims_VaultManifestId_Disabled", table: "EmailClaims", columns: new[] { "VaultManifestId", "Disabled" });
+ migrationBuilder.DropTable(name: "UserEmailClaims");
- migrationBuilder.AddForeignKey(
- name: "FK_EmailClaims_VaultManifests_VaultManifestId",
- table: "EmailClaims",
- column: "VaultManifestId",
- principalTable: "VaultManifests",
- principalColumn: "ManifestId",
- onDelete: ReferentialAction.SetNull);
+ migrationBuilder.AddPrimaryKey(name: "PK_EmailClaims", table: "EmailClaims", column: "Id");
+ migrationBuilder.AddPrimaryKey(name: "PK_EmailClaimLinks", table: "EmailClaimLinks", columns: new[] { "EmailClaimId", "VaultManifestId" });
+ migrationBuilder.CreateIndex(name: "IX_EmailClaims_Address", table: "EmailClaims", column: "Address", unique: true);
+ migrationBuilder.CreateIndex(name: "IX_EmailClaimLinks_VaultManifestId_EmailClaimId", table: "EmailClaimLinks", columns: new[] { "VaultManifestId", "EmailClaimId" });
+ migrationBuilder.Sql("""CREATE INDEX "IX_EmailClaimLinks_EmailClaimId_Live" ON "EmailClaimLinks" ("EmailClaimId") WHERE "State" <> 'Removed';""");
}
- /// <summary>
- /// Turns the per-user email encryption keys into per-manifest delivery keys.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
private static void ScopeDeliveryKeysToManifests(MigrationBuilder migrationBuilder)
{
- migrationBuilder.DropForeignKey(name: "FK_UserEncryptionKeys_AliasVaultUsers_UserId", table: "UserEncryptionKeys");
- migrationBuilder.DropIndex(name: "IX_UserEncryptionKeys_UserId", table: "UserEncryptionKeys");
- migrationBuilder.RenameTable(name: "UserEncryptionKeys", newName: "VaultManifestDeliveryKeys");
+ // No vault means no manifest to attach the key to.
migrationBuilder.Sql("""
- ALTER TABLE "VaultManifestDeliveryKeys" RENAME CONSTRAINT "PK_UserEncryptionKeys" TO "PK_VaultManifestDeliveryKeys";
- ALTER TABLE "Emails" RENAME CONSTRAINT "FK_Emails_UserEncryptionKeys_UserEncryptionKeyId" TO "FK_Emails_VaultManifestDeliveryKeys_EncryptionKeyId";
+ DELETE FROM "UserEncryptionKeys" k
+ WHERE NOT EXISTS (SELECT 1 FROM "UserMigrationMap" m WHERE m."UserId" = k."UserId" AND m."ManifestId" IS NOT NULL);
""");
- migrationBuilder.RenameColumn(name: "UserEncryptionKeyId", table: "Emails", newName: "EncryptionKeyId");
- migrationBuilder.RenameIndex(name: "IX_Emails_UserEncryptionKeyId", table: "Emails", newName: "IX_Emails_EncryptionKeyId");
-
- migrationBuilder.AddColumn<Guid>(name: "VaultManifestId", table: "VaultManifestDeliveryKeys", type: "uuid", nullable: true);
- migrationBuilder.Sql("""
- UPDATE "VaultManifestDeliveryKeys" k
- SET "VaultManifestId" = m."ManifestId"
- FROM "AliasVaultUsers" u
- JOIN "VaultManifests" m ON m."OwnerGroupId" = u."PersonalGroupId"
- WHERE u."Id" = k."UserId";
- """);
+ migrationBuilder.CreateTable(
+ name: "VaultManifestDeliveryKeys",
+ columns: table => new
+ {
+ Id = table.Column<Guid>(type: "uuid", nullable: false),
+ VaultManifestId = table.Column<Guid>(type: "uuid", nullable: false),
+ Algorithm = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),
+ PublicKey = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: false),
+ IsPrimary = table.Column<bool>(type: "boolean", nullable: false),
+ CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
+ UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
+ });
- // A key whose owner has no vault has no manifest to belong to. Its private half only ever existed inside
- // that vault, so mail encrypted to it is already unreadable; the cascade takes those emails with it.
- migrationBuilder.Sql("""DELETE FROM "VaultManifestDeliveryKeys" WHERE "VaultManifestId" IS NULL;""");
+ migrationBuilder.CreateTable(
+ name: "EmailDecryptionKeys",
+ columns: table => new
+ {
+ EmailId = table.Column<int>(type: "integer", nullable: false),
+ VaultManifestDeliveryKeyId = table.Column<Guid>(type: "uuid", nullable: false),
+ EncryptedSymmetricKey = table.Column<string>(type: "text", nullable: false)
+ });
- // The unique index below allows one primary key per manifest; keep the most recently updated one.
+ // Existing keys are rsa-oaep-sha256; one primary per user.
migrationBuilder.Sql("""
- UPDATE "VaultManifestDeliveryKeys" k
- SET "IsPrimary" = FALSE
- WHERE k."IsPrimary"
- AND k."Id" NOT IN (
- SELECT DISTINCT ON ("VaultManifestId") "Id"
- FROM "VaultManifestDeliveryKeys"
- WHERE "IsPrimary"
- ORDER BY "VaultManifestId", "UpdatedAt" DESC, "Id");
+ INSERT INTO "VaultManifestDeliveryKeys" ("Id", "VaultManifestId", "Algorithm", "PublicKey", "IsPrimary", "CreatedAt", "UpdatedAt")
+ SELECT k."Id", m."ManifestId", 'rsa-oaep-sha256', k."PublicKey",
+ k."IsPrimary" AND ROW_NUMBER() OVER (PARTITION BY k."UserId", k."IsPrimary" ORDER BY k."UpdatedAt" DESC, k."Id") = 1,
+ k."CreatedAt", k."UpdatedAt"
+ FROM "UserEncryptionKeys" k
+ JOIN "UserMigrationMap" m ON m."UserId" = k."UserId";
+
+ INSERT INTO "EmailDecryptionKeys" ("EmailId", "VaultManifestDeliveryKeyId", "EncryptedSymmetricKey")
+ SELECT "Id", "UserEncryptionKeyId", "EncryptedSymmetricKey" FROM "Emails";
""");
- migrationBuilder.DropColumn(name: "UserId", table: "VaultManifestDeliveryKeys");
-
- migrationBuilder.AlterColumn<Guid>(
- name: "VaultManifestId",
- table: "VaultManifestDeliveryKeys",
- type: "uuid",
- nullable: false,
- oldClrType: typeof(Guid),
- oldType: "uuid",
- oldNullable: true);
+ migrationBuilder.DropForeignKey(name: "FK_Emails_UserEncryptionKeys_UserEncryptionKeyId", table: "Emails");
+ migrationBuilder.DropIndex(name: "IX_Emails_UserEncryptionKeyId", table: "Emails");
+ migrationBuilder.DropColumn(name: "EncryptedSymmetricKey", table: "Emails");
+ migrationBuilder.DropColumn(name: "UserEncryptionKeyId", table: "Emails");
+ migrationBuilder.DropTable(name: "UserEncryptionKeys");
+ migrationBuilder.AddPrimaryKey(name: "PK_VaultManifestDeliveryKeys", table: "VaultManifestDeliveryKeys", column: "Id");
+ migrationBuilder.AddPrimaryKey(name: "PK_EmailDecryptionKeys", table: "EmailDecryptionKeys", columns: new[] { "EmailId", "VaultManifestDeliveryKeyId" });
migrationBuilder.CreateIndex(name: "IX_VaultManifestDeliveryKeys_VaultManifestId_IsPrimary", table: "VaultManifestDeliveryKeys", columns: new[] { "VaultManifestId", "IsPrimary" });
migrationBuilder.CreateIndex(name: "UX_VaultManifestDeliveryKeys_Manifest_Primary", table: "VaultManifestDeliveryKeys", column: "VaultManifestId", unique: true, filter: "\"IsPrimary\"");
+ migrationBuilder.CreateIndex(name: "IX_EmailDecryptionKeys_VaultManifestDeliveryKeyId_EmailId", table: "EmailDecryptionKeys", columns: new[] { "VaultManifestDeliveryKeyId", "EmailId" });
+ }
- migrationBuilder.AddForeignKey(
- name: "FK_VaultManifestDeliveryKeys_VaultManifests_VaultManifestId",
- table: "VaultManifestDeliveryKeys",
- column: "VaultManifestId",
- principalTable: "VaultManifests",
- principalColumn: "ManifestId",
- onDelete: ReferentialAction.Cascade);
+ private static void ScopeRateLimitsToGroups(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 r."Id", m."GroupId", r."LimitType", r."Tier", r."WindowSeconds", r."MaxCount", r."AppliesToAccountAgeMaxDays", r."Enabled", r."Notes", r."EffectiveFrom", r."EffectiveUntil", r."CreatedBy", r."CreatedAt", r."UpdatedAt"
+ FROM "RateLimits" r
+ LEFT JOIN "UserMigrationMap" m ON m."UserId" = r."UserId";
+
+ DROP TABLE "RateLimits";
+ ALTER TABLE "RateLimits_reordered" RENAME TO "RateLimits";
+ ALTER TABLE "RateLimits" ADD CONSTRAINT "PK_RateLimits" PRIMARY KEY ("Id");
+ """);
+
+ migrationBuilder.CreateIndex(name: "IX_RateLimits_GroupId", table: "RateLimits", column: "GroupId");
+ migrationBuilder.CreateIndex(name: "IX_RateLimits_LimitType_Enabled", table: "RateLimits", columns: new[] { "LimitType", "Enabled" });
+ migrationBuilder.CreateIndex(name: "IX_RateLimits_Tier", table: "RateLimits", column: "Tier");
}
- /// <summary>
- /// Records the algorithm on the public keys that predate the column. All of them are RSA-OAEP keys.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
- private static void AddAlgorithmToPublicKeys(MigrationBuilder migrationBuilder)
+ private static void AddAlgorithmToMobileLoginRequests(MigrationBuilder migrationBuilder)
{
- migrationBuilder.AddColumn<string>(name: "Algorithm", table: "VaultManifestDeliveryKeys", type: "character varying(30)", maxLength: 30, nullable: false, defaultValue: "rsa-oaep-sha256");
migrationBuilder.AddColumn<string>(name: "Algorithm", table: "MobileLoginRequests", type: "character varying(30)", maxLength: 30, nullable: false, defaultValue: "rsa-oaep-sha256");
- migrationBuilder.AlterColumn<string>(name: "Algorithm", table: "VaultManifestDeliveryKeys", type: "character varying(30)", maxLength: 30, nullable: false, oldClrType: typeof(string), oldType: "character varying(30)", oldMaxLength: 30, oldDefaultValue: "rsa-oaep-sha256");
migrationBuilder.AlterColumn<string>(name: "Algorithm", table: "MobileLoginRequests", type: "character varying(30)", maxLength: 30, nullable: false, oldClrType: typeof(string), oldType: "character varying(30)", oldMaxLength: 30, oldDefaultValue: "rsa-oaep-sha256");
}
- /// <summary>
- /// Charges rate limit overrides to the group that owns the content instead of to the user.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
- private static void ScopeRateLimitsToGroups(MigrationBuilder migrationBuilder)
+ private static void MoveMessageSourceToBytes(MigrationBuilder migrationBuilder)
{
- migrationBuilder.AddColumn<Guid>(name: "GroupId", table: "RateLimits", type: "uuid", nullable: true);
+ migrationBuilder.AlterColumn<string>(name: "MessageSource", table: "Emails", type: "text", nullable: true, oldClrType: typeof(string), oldType: "text");
+ migrationBuilder.AddColumn<int>(name: "AttachmentCount", table: "Emails", type: "integer", nullable: false, defaultValue: 0);
migrationBuilder.Sql("""
- UPDATE "RateLimits" r
- SET "GroupId" = u."PersonalGroupId"
- FROM "AliasVaultUsers" u
- WHERE r."UserId" = u."Id";
+ UPDATE "Emails" SET "AttachmentCount" = counts."AttachmentCount"
+ FROM (SELECT "EmailId", COUNT(*) AS "AttachmentCount" FROM "EmailAttachments" GROUP BY "EmailId") AS counts
+ WHERE "Emails"."Id" = counts."EmailId";
""");
- migrationBuilder.DropForeignKey(name: "FK_RateLimits_AliasVaultUsers_UserId", table: "RateLimits");
- migrationBuilder.DropIndex(name: "IX_RateLimits_UserId", table: "RateLimits");
- migrationBuilder.DropColumn(name: "UserId", table: "RateLimits");
- migrationBuilder.CreateIndex(name: "IX_RateLimits_GroupId", table: "RateLimits", column: "GroupId");
+ migrationBuilder.AddColumn<byte[]>(name: "MessageSourceBytes", table: "Emails", type: "bytea", nullable: true);
- migrationBuilder.AddForeignKey(
- name: "FK_RateLimits_Groups_GroupId",
- table: "RateLimits",
- column: "GroupId",
- principalTable: "Groups",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
+ // Ciphertext: skip TOAST compression.
+ migrationBuilder.Sql("""
+ ALTER TABLE "Emails" ALTER COLUMN "MessageSourceBytes" SET STORAGE EXTERNAL;
+ ALTER TABLE "EmailAttachments" ALTER COLUMN "Bytes" SET STORAGE EXTERNAL;
+ """);
+ }
+
+ private static void AddDetachedMessageParts(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "EmailParts",
+ columns: table => new
+ {
+ Id = table.Column<int>(type: "integer", nullable: false)
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ EmailId = table.Column<int>(type: "integer", nullable: false),
+ PartIndex = table.Column<int>(type: "integer", nullable: false),
+ Bytes = table.Column<byte[]>(type: "bytea", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_EmailParts", x => x.Id);
+ table.ForeignKey(
+ name: "FK_EmailParts_Emails_EmailId",
+ column: x => x.EmailId,
+ principalTable: "Emails",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateIndex(name: "IX_EmailParts_EmailId_PartIndex", table: "EmailParts", columns: new[] { "EmailId", "PartIndex" }, unique: true);
+
+ // Ciphertext: skip TOAST compression.
+ migrationBuilder.Sql("""ALTER TABLE "EmailParts" ALTER COLUMN "Bytes" SET STORAGE EXTERNAL;""");
}
- /// <summary>
- /// Creates the tables that only the manifest-v1 write path uses. They start empty: a client fills them on its
- /// first manifest-v1 push.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
private static void AddManifestV1Tables(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
@@ -669,12 +654,6 @@ namespace AliasServerDb.Migrations
migrationBuilder.CreateIndex(name: "UX_VaultManifestAccessKeys_UserId_Type_Manifest_Version", table: "VaultManifestAccessKeys", columns: new[] { "UserId", "Type", "VaultManifestId", "KeyVersion" }, unique: true);
}
- /// <summary>
- /// Every manifest-v1 payload column holds AES ciphertext of an already-gzipped payload, which is
- /// incompressible, so TOAST would burn a compression attempt per write and always discard the result.
- /// EXTERNAL keeps the out-of-line storage but skips that attempt, matching the Emails.MessageSourceBytes column.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
private static void SkipToastCompressionOnCiphertextColumns(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("""
@@ -686,10 +665,88 @@ namespace AliasServerDb.Migrations
""");
}
- /// <summary>
- /// Drops the manifest-v1 only tables again.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
+ private static void AddForeignKeys(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AddForeignKey(name: "FK_AliasVaultUserRefreshTokens_AliasVaultUsers_UserId", table: "AliasVaultUserRefreshTokens", column: "UserId", principalTable: "AliasVaultUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade);
+ migrationBuilder.AddForeignKey(name: "FK_MobileLoginRequests_AliasVaultUsers_UserId", table: "MobileLoginRequests", column: "UserId", principalTable: "AliasVaultUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade);
+ migrationBuilder.AddForeignKey(name: "FK_AliasVaultUsers_Groups_PersonalGroupId", table: "AliasVaultUsers", column: "PersonalGroupId", principalTable: "Groups", principalColumn: "Id", onDelete: ReferentialAction.Restrict);
+ migrationBuilder.AddForeignKey(name: "FK_GroupMembers_AliasVaultUsers_UserId", table: "GroupMembers", column: "UserId", principalTable: "AliasVaultUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade);
+ migrationBuilder.AddForeignKey(name: "FK_GroupMembers_Groups_GroupId", table: "GroupMembers", column: "GroupId", principalTable: "Groups", principalColumn: "Id", onDelete: ReferentialAction.Cascade);
+ migrationBuilder.AddForeignKey(name: "FK_VaultManifests_Groups_OwnerGroupId", table: "VaultManifests", column: "OwnerGroupId", principalTable: "Groups", principalColumn: "Id", onDelete: ReferentialAction.Cascade);
+ migrationBuilder.AddForeignKey(name: "FK_VaultManifests_AliasVaultUsers_UpdatedByUserId", table: "VaultManifests", column: "UpdatedByUserId", principalTable: "AliasVaultUsers", principalColumn: "Id", onDelete: ReferentialAction.SetNull);
+ migrationBuilder.AddForeignKey(name: "FK_VaultManifestsHistory_VaultManifests_ManifestId", table: "VaultManifestsHistory", column: "ManifestId", principalTable: "VaultManifests", principalColumn: "ManifestId", onDelete: ReferentialAction.Cascade);
+ migrationBuilder.AddForeignKey(name: "FK_VaultManifestsHistory_AliasVaultUsers_UpdatedByUserId", table: "VaultManifestsHistory", column: "UpdatedByUserId", principalTable: "AliasVaultUsers", principalColumn: "Id", onDelete: ReferentialAction.SetNull);
+ migrationBuilder.AddForeignKey(name: "FK_EmailClaimLinks_EmailClaims_EmailClaimId", table: "EmailClaimLinks", column: "EmailClaimId", principalTable: "EmailClaims", principalColumn: "Id", onDelete: ReferentialAction.Cascade);
+ migrationBuilder.AddForeignKey(name: "FK_EmailClaimLinks_VaultManifests_VaultManifestId", table: "EmailClaimLinks", column: "VaultManifestId", principalTable: "VaultManifests", principalColumn: "ManifestId", onDelete: ReferentialAction.Cascade);
+ migrationBuilder.AddForeignKey(name: "FK_VaultManifestDeliveryKeys_VaultManifests_VaultManifestId", table: "VaultManifestDeliveryKeys", column: "VaultManifestId", principalTable: "VaultManifests", principalColumn: "ManifestId", onDelete: ReferentialAction.Cascade);
+ migrationBuilder.AddForeignKey(name: "FK_EmailDecryptionKeys_Emails_EmailId", table: "EmailDecryptionKeys", column: "EmailId", principalTable: "Emails", principalColumn: "Id", onDelete: ReferentialAction.Cascade);
+ migrationBuilder.AddForeignKey(name: "FK_EmailDecryptionKeys_VaultManifestDeliveryKeys_DeliveryKeyId", table: "EmailDecryptionKeys", column: "VaultManifestDeliveryKeyId", principalTable: "VaultManifestDeliveryKeys", principalColumn: "Id", onDelete: ReferentialAction.Cascade);
+ migrationBuilder.AddForeignKey(name: "FK_RateLimits_Groups_GroupId", table: "RateLimits", column: "GroupId", principalTable: "Groups", principalColumn: "Id", onDelete: ReferentialAction.Cascade);
+ }
+
+ private static void RemoveAnonymizedSenderCounts(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropColumn(name: "AnonymizedEmailAliasSenderCounts", table: "Groups");
+ migrationBuilder.DropColumn(name: "AnonymizedSenderCounted", table: "EmailClaims");
+ }
+
+ private static void DropDetachedMessageParts(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(name: "EmailParts");
+ }
+
+ private static void RestoreMessageSourceText(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.Sql(@"ALTER TABLE ""EmailAttachments"" ALTER COLUMN ""Bytes"" SET STORAGE EXTENDED;");
+ migrationBuilder.DropColumn(name: "AttachmentCount", table: "Emails");
+ migrationBuilder.DropColumn(name: "MessageSourceBytes", table: "Emails");
+ migrationBuilder.AlterColumn<string>(name: "MessageSource", table: "Emails", type: "text", nullable: false, defaultValue: "", oldClrType: typeof(string), oldType: "text", oldNullable: true);
+ }
+
+ private static void RestoreSingleManifestLinks(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.Sql("""DROP INDEX IF EXISTS "IX_EmailClaimLinks_EmailClaimId_Live";""");
+
+ migrationBuilder.AddColumn<bool>(name: "Disabled", table: "EmailClaims", type: "boolean", nullable: false, defaultValue: false);
+
+ migrationBuilder.Sql("""
+ UPDATE "EmailClaims" c
+ SET "Disabled" = NOT EXISTS (SELECT 1 FROM "EmailClaimLinks" l WHERE l."EmailClaimId" = c."Id" AND l."State" <> 'Removed');
+ """);
+
+ migrationBuilder.AddColumn<string>(name: "EncryptedSymmetricKey", table: "Emails", type: "text", nullable: true);
+ migrationBuilder.AddColumn<Guid>(name: "EncryptionKeyId", table: "Emails", type: "uuid", maxLength: 255, nullable: true);
+ migrationBuilder.AddColumn<Guid>(name: "VaultManifestId", table: "EmailClaims", type: "uuid", nullable: true);
+
+ // One key per row. Emails left with none are deleted.
+ migrationBuilder.Sql("""
+ UPDATE "Emails" e
+ SET "EncryptionKeyId" = d."VaultManifestDeliveryKeyId", "EncryptedSymmetricKey" = d."EncryptedSymmetricKey"
+ FROM (SELECT DISTINCT ON ("EmailId") "EmailId", "VaultManifestDeliveryKeyId", "EncryptedSymmetricKey" FROM "EmailDecryptionKeys" ORDER BY "EmailId", "VaultManifestDeliveryKeyId") d
+ WHERE d."EmailId" = e."Id";
+
+ DELETE FROM "Emails" WHERE "EncryptionKeyId" IS NULL;
+
+ UPDATE "EmailClaims" c
+ SET "VaultManifestId" = l."VaultManifestId"
+ FROM (SELECT DISTINCT ON ("EmailClaimId") "EmailClaimId", "VaultManifestId" FROM "EmailClaimLinks" ORDER BY "EmailClaimId", "VaultManifestId") l
+ WHERE l."EmailClaimId" = c."Id";
+ """);
+
+ migrationBuilder.AlterColumn<string>(name: "EncryptedSymmetricKey", table: "Emails", type: "text", nullable: false, oldClrType: typeof(string), oldType: "text", oldNullable: true);
+ migrationBuilder.AlterColumn<Guid>(name: "EncryptionKeyId", table: "Emails", type: "uuid", maxLength: 255, nullable: false, oldClrType: typeof(Guid), oldType: "uuid", oldMaxLength: 255, oldNullable: true);
+
+ migrationBuilder.DropTable(name: "EmailClaimLinks");
+ migrationBuilder.DropTable(name: "EmailDecryptionKeys");
+
+ migrationBuilder.CreateIndex(name: "IX_Emails_EncryptionKeyId", table: "Emails", column: "EncryptionKeyId");
+ migrationBuilder.CreateIndex(name: "IX_EmailClaims_VaultManifestId_CreatedAt", table: "EmailClaims", columns: new[] { "VaultManifestId", "CreatedAt" });
+ migrationBuilder.CreateIndex(name: "IX_EmailClaims_VaultManifestId_Disabled", table: "EmailClaims", columns: new[] { "VaultManifestId", "Disabled" });
+
+ migrationBuilder.AddForeignKey(name: "FK_EmailClaims_VaultManifests_VaultManifestId", table: "EmailClaims", column: "VaultManifestId", principalTable: "VaultManifests", principalColumn: "ManifestId", onDelete: ReferentialAction.SetNull);
+ migrationBuilder.AddForeignKey(name: "FK_Emails_VaultManifestDeliveryKeys_EncryptionKeyId", table: "Emails", column: "EncryptionKeyId", principalTable: "VaultManifestDeliveryKeys", principalColumn: "Id", onDelete: ReferentialAction.Cascade);
+ }
+
private static void DropManifestV1Tables(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(name: "VaultDataBucketsHistory");
@@ -702,15 +759,11 @@ namespace AliasServerDb.Migrations
migrationBuilder.DropTable(name: "UserGrantKeys");
}
- /// <summary>
- /// Charges rate limit overrides back to the user.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
private static void RestoreRateLimitsToUsers(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(name: "UserId", table: "RateLimits", type: "character varying(255)", maxLength: 255, nullable: true);
- // Only a personal group maps back to a user. A rule scoped to a shared group has no user equivalent.
+ // Shared-group rules have no user to map back to.
migrationBuilder.Sql("""
UPDATE "RateLimits" r
SET "UserId" = u."Id"
@@ -734,20 +787,12 @@ namespace AliasServerDb.Migrations
onDelete: ReferentialAction.Cascade);
}
- /// <summary>
- /// Drops the algorithm from the public keys that predate the column.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
private static void RemoveAlgorithmFromPublicKeys(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(name: "Algorithm", table: "MobileLoginRequests");
migrationBuilder.DropColumn(name: "Algorithm", table: "VaultManifestDeliveryKeys");
}
- /// <summary>
- /// Turns the per-manifest delivery keys back into per-user email encryption keys.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
private static void RestoreDeliveryKeysToUsers(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_VaultManifestDeliveryKeys_VaultManifests_VaultManifestId", table: "VaultManifestDeliveryKeys");
@@ -756,7 +801,7 @@ namespace AliasServerDb.Migrations
migrationBuilder.AddColumn<string>(name: "UserId", table: "VaultManifestDeliveryKeys", type: "character varying(255)", maxLength: 255, nullable: true);
- // A key of a shared manifest has no single owning user to go back to.
+ // Shared-manifest keys have no single user.
migrationBuilder.Sql("""
UPDATE "VaultManifestDeliveryKeys" k
SET "UserId" = u."Id"
@@ -799,10 +844,6 @@ namespace AliasServerDb.Migrations
onDelete: ReferentialAction.Cascade);
}
- /// <summary>
- /// Repoints email aliases from their manifest back to the owning user.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
private static void RestoreEmailClaimsToUsers(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_EmailClaims_VaultManifests_VaultManifestId", table: "EmailClaims");
@@ -837,10 +878,6 @@ namespace AliasServerDb.Migrations
onDelete: ReferentialAction.SetNull);
}
- /// <summary>
- /// Folds the manifest head and its history back into the per-revision "Vaults" log.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
private static void RestoreManifestsToVaults(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_VaultManifestsHistory_AliasVaultUsers_UpdatedByUserId", table: "VaultManifestsHistory");
@@ -850,7 +887,7 @@ namespace AliasServerDb.Migrations
migrationBuilder.DropIndex(name: "IX_VaultManifests_UpdatedByUserId", table: "VaultManifests");
migrationBuilder.DropIndex(name: "IX_VaultManifests_OwnerGroupId", table: "VaultManifests");
- // A shared manifest has no owning user, so there is no "Vaults" row it can become.
+ // Shared manifests have no owning user.
migrationBuilder.Sql("""
DELETE FROM "VaultManifests" m
WHERE NOT EXISTS (SELECT 1 FROM "AliasVaultUsers" u WHERE u."PersonalGroupId" = m."OwnerGroupId");
@@ -864,7 +901,6 @@ namespace AliasServerDb.Migrations
WHERE u."PersonalGroupId" = m."OwnerGroupId";
""");
- // Restore the per-revision key, then fold the history rows back in as ordinary revisions.
migrationBuilder.DropPrimaryKey(name: "PK_VaultManifests", table: "VaultManifests");
migrationBuilder.Sql("""ALTER TABLE "VaultManifests" ADD COLUMN "Id" uuid NOT NULL DEFAULT gen_random_uuid();""");
migrationBuilder.AddPrimaryKey(name: "PK_VaultManifests", table: "VaultManifests", column: "Id");
@@ -887,7 +923,7 @@ namespace AliasServerDb.Migrations
migrationBuilder.DropColumn(name: "ManifestCiphertextHash", table: "VaultManifests");
migrationBuilder.DropColumn(name: "UpdatedByUserId", table: "VaultManifests");
- // The pre-manifest schema has no "not applicable" marker: an unset column reads as the empty string.
+ // Unset legacy columns become empty strings.
migrationBuilder.Sql("""
UPDATE "VaultManifests" SET
"VaultBlob" = COALESCE("VaultBlob", ''),
@@ -925,10 +961,6 @@ namespace AliasServerDb.Migrations
onDelete: ReferentialAction.Cascade);
}
- /// <summary>
- /// Moves the email quotas back onto the user record and drops the group tables.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
private static void RemoveGroups(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(name: "ShadowBlocked", table: "AliasVaultUsers", type: "boolean", nullable: false, defaultValue: false);
@@ -956,26 +988,6 @@ namespace AliasServerDb.Migrations
migrationBuilder.DropTable(name: "Groups");
}
- /// <summary>
- /// Makes the columns that only the legacy sqlite-blob format fills nullable.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
- /// <param name="table">The revision table to alter.</param>
- private static void MakeLegacyRevisionColumnsNullable(MigrationBuilder migrationBuilder, string table)
- {
- migrationBuilder.AlterColumn<string>(name: "VaultBlob", table: table, type: "text", nullable: true, oldClrType: typeof(string), oldType: "text");
- migrationBuilder.AlterColumn<string>(name: "Version", table: table, type: "character varying(255)", maxLength: 255, nullable: true, oldClrType: typeof(string), oldType: "character varying(255)", oldMaxLength: 255);
- migrationBuilder.AlterColumn<string>(name: "Salt", table: table, type: "character varying(100)", maxLength: 100, nullable: true, oldClrType: typeof(string), oldType: "character varying(100)", oldMaxLength: 100);
- migrationBuilder.AlterColumn<string>(name: "Verifier", table: table, type: "character varying(1000)", maxLength: 1000, nullable: true, oldClrType: typeof(string), oldType: "character varying(1000)", oldMaxLength: 1000);
- migrationBuilder.AlterColumn<string>(name: "EncryptionType", table: table, type: "text", nullable: true, oldClrType: typeof(string), oldType: "text");
- migrationBuilder.AlterColumn<string>(name: "EncryptionSettings", table: table, type: "text", nullable: true, oldClrType: typeof(string), oldType: "text");
- }
-
- /// <summary>
- /// Makes the columns that only the legacy sqlite-blob format fills required again.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
- /// <param name="table">The revision table to alter.</param>
private static void MakeLegacyRevisionColumnsRequired(MigrationBuilder migrationBuilder, string table)
{
migrationBuilder.AlterColumn<string>(name: "VaultBlob", table: table, type: "text", nullable: false, defaultValue: string.Empty, oldClrType: typeof(string), oldType: "text", oldNullable: true);
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260810154523_EmailMultiManifestAndStorageV2.Designer.cs b/apps/server/Databases/AliasServerDb/Migrations/20260810154523_EmailMultiManifestAndStorageV2.Designer.cs
deleted file mode 100644
index 9a13b2f0a..000000000
--- a/apps/server/Databases/AliasServerDb/Migrations/20260810154523_EmailMultiManifestAndStorageV2.Designer.cs
+++ /dev/null
@@ -1,1786 +0,0 @@
-// <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("20260810154523_EmailMultiManifestAndStorageV2")]
- partial class EmailMultiManifestAndStorageV2
- {
- /// <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(255)
- .HasColumnType("character varying(255)");
-
- 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<bool>("AnonymizedSenderCounted")
- .HasColumnType("boolean");
-
- b.Property<DateTime>("CreatedAt")
- .HasColumnType("timestamp with time zone");
-
- 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.Property<string>("State")
- .IsRequired()
- .HasMaxLength(20)
- .HasColumnType("character varying(20)");
-
- b.HasKey("EmailClaimId", "VaultManifestId");
-
- b.HasIndex("VaultManifestId", "EmailClaimId");
-
- b.HasIndex("EmailClaimId")
- .HasDatabaseName("IX_EmailClaimLinks_EmailClaimId_Live")
- .HasFilter("\"State\" <> 'Removed'");
-
- b.ToTable("EmailClaimLinks");
- });
-
- modelBuilder.Entity("AliasServerDb.EmailDecryptionKey", b =>
- {
- b.Property<int>("EmailId")
- .HasColumnType("integer");
-
- b.Property<Guid>("VaultManifestDeliveryKeyId")
- .HasColumnType("uuid");
-
- b.Property<string>("EncryptedSymmetricKey")
- .IsRequired()
- .HasColumnType("text");
-
- b.HasKey("EmailId", "VaultManifestDeliveryKeyId");
-
- b.HasIndex("VaultManifestDeliveryKeyId", "EmailId");
-
- b.ToTable("EmailDecryptionKeys");
- });
-
- modelBuilder.Entity("AliasServerDb.EmailPart", b =>
- {
- b.Property<int>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("integer");
-
- NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
-
- b.Property<byte[]>("Bytes")
- .IsRequired()
- .HasColumnType("bytea");
-
- b.Property<int>("EmailId")
- .HasColumnType("integer");
-
- b.Property<int>("PartIndex")
- .HasColumnType("integer");
-
- b.HasKey("Id");
-
- b.HasIndex("EmailId", "PartIndex")
- .IsUnique();
-
- b.ToTable("EmailParts");
- });
-
- modelBuilder.Entity("AliasServerDb.Group", b =>
- {
- b.Property<Guid>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("uuid");
-
- b.PrimitiveCollection<int[]>("AnonymizedEmailAliasSenderCounts")
- .IsRequired()
- .ValueGeneratedOnAdd()
- .HasColumnType("integer[]")
- .HasDefaultValueSql("array_fill(0, ARRAY[64])");
-
- 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<string>("Algorithm")
- .IsRequired()
- .HasMaxLength(30)
- .HasColumnType("character varying(30)");
-
- 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<string>("Algorithm")
- .IsRequired()
- .HasMaxLength(30)
- .HasColumnType("character varying(30)");
-
- 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.UserUnlockKeysHistory", 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>("ArchivedAt")
- .HasColumnType("timestamp with time zone");
-
- b.Property<string>("ArchivedByClient")
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- 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<string>("Metadata")
- .HasColumnType("jsonb");
-
- b.Property<string>("Type")
- .IsRequired()
- .HasMaxLength(30)
- .HasColumnType("character varying(30)");
-
- b.Property<Guid>("UnlockKeyId")
- .HasColumnType("uuid");
-
- 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("ArchivedAt")
- .HasDatabaseName("IX_UserUnlockKeysHistory_ArchivedAt");
-
- b.HasIndex("UserId", "Type", "ArchivedAt")
- .HasDatabaseName("IX_UserUnlockKeysHistory_UserId_Type_ArchivedAt");
-
- b.ToTable("UserUnlockKeysHistory", (string)null);
- });
-
- modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>
- {
- b.Property<Guid>("ManifestId")
- .HasColumnType("uuid");
-
- b.Property<string>("Hash")
- .HasMaxLength(64)
- .HasColumnType("character varying(64)");
-
- b.Property<string>("Category")
- .IsRequired()
- .HasMaxLength(20)
- .HasColumnType("character varying(20)");
-
- b.Property<DateTime>("CreatedAt")
- .HasColumnType("timestamp with time zone");
-
- b.Property<string>("EncryptedBlobKey")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.Property<byte[]>("EncryptedData")
- .IsRequired()
- .HasColumnType("bytea");
-
- b.Property<int>("KeyVersion")
- .HasColumnType("integer");
-
- b.Property<int>("SizeBytes")
- .HasColumnType("integer");
-
- b.HasKey("ManifestId", "Hash");
-
- 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<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>("UpdatedByUserId")
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- 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.HasIndex("UpdatedByUserId");
-
- 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<string>("Algorithm")
- .IsRequired()
- .HasMaxLength(30)
- .HasColumnType("character varying(30)");
-
- 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>("UpdatedByUserId")
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- 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.HasIndex("UpdatedByUserId");
-
- 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<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.EmailDecryptionKey", b =>
- {
- b.HasOne("AliasServerDb.Email", "Email")
- .WithMany("DecryptionKeys")
- .HasForeignKey("EmailId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.HasOne("AliasServerDb.VaultManifestDeliveryKey", "VaultManifestDeliveryKey")
- .WithMany("DecryptionKeys")
- .HasForeignKey("VaultManifestDeliveryKeyId")
- .HasConstraintName("FK_EmailDecryptionKeys_VaultManifestDeliveryKeys_DeliveryKeyId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Email");
-
- b.Navigation("VaultManifestDeliveryKey");
- });
-
- modelBuilder.Entity("AliasServerDb.EmailPart", b =>
- {
- b.HasOne("AliasServerDb.Email", "Email")
- .WithMany("Parts")
- .HasForeignKey("EmailId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Email");
- });
-
- 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.UserUnlockKeysHistory", b =>
- {
- b.HasOne("AliasServerDb.AliasVaultUser", "User")
- .WithMany()
- .HasForeignKey("UserId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("User");
- });
-
- modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>
- {
- b.HasOne("AliasServerDb.VaultManifest", "Manifest")
- .WithMany()
- .HasForeignKey("ManifestId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Manifest");
- });
-
- 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.HasOne("AliasServerDb.AliasVaultUser", "UpdatedByUser")
- .WithMany()
- .HasForeignKey("UpdatedByUserId")
- .OnDelete(DeleteBehavior.SetNull);
-
- b.Navigation("OwnerGroup");
-
- b.Navigation("UpdatedByUser");
- });
-
- 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.HasOne("AliasServerDb.AliasVaultUser", "UpdatedByUser")
- .WithMany()
- .HasForeignKey("UpdatedByUserId")
- .OnDelete(DeleteBehavior.SetNull);
-
- b.Navigation("Manifest");
-
- b.Navigation("UpdatedByUser");
- });
-
- modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>
- {
- b.Navigation("VaultManifestAccessKeys");
- });
-
- modelBuilder.Entity("AliasServerDb.Email", b =>
- {
- b.Navigation("Attachments");
-
- b.Navigation("Parts");
-
- b.Navigation("DecryptionKeys");
- });
-
- modelBuilder.Entity("AliasServerDb.EmailClaim", b =>
- {
- b.Navigation("Links");
- });
-
- modelBuilder.Entity("AliasServerDb.Group", b =>
- {
- b.Navigation("Members");
- });
-
- modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>
- {
- b.Navigation("DecryptionKeys");
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260810154523_EmailMultiManifestAndStorageV2.cs b/apps/server/Databases/AliasServerDb/Migrations/20260810154523_EmailMultiManifestAndStorageV2.cs
deleted file mode 100644
index 5425227aa..000000000
--- a/apps/server/Databases/AliasServerDb/Migrations/20260810154523_EmailMultiManifestAndStorageV2.cs
+++ /dev/null
@@ -1,395 +0,0 @@
-using System;
-using Microsoft.EntityFrameworkCore.Migrations;
-using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
-
-#nullable disable
-
-namespace AliasServerDb.Migrations
-{
- /// <summary>
- /// Moves email storage to the multi-manifest model:
- /// - an alias and a received email are both linked to the manifests that hold them instead of carrying a single
- /// manifest reference, so one address can be claimed by several manifests at once,
- /// - the raw message moves to a binary column, is split into separately fetchable parts, and the attachment count
- /// becomes a column of its own,
- /// - a group counts the first-time senders of its aliases in an anonymized bucket array.
- /// </summary>
- public partial class EmailMultiManifestAndStorageV2 : Migration
- {
- /// <inheritdoc />
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- LinkClaimsAndEmailsToManifests(migrationBuilder);
- MoveMessageSourceToBytes(migrationBuilder);
- AddDetachedMessageParts(migrationBuilder);
- AddAnonymizedSenderCounts(migrationBuilder);
- }
-
- /// <inheritdoc />
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- RemoveAnonymizedSenderCounts(migrationBuilder);
- DropDetachedMessageParts(migrationBuilder);
- RestoreMessageSourceText(migrationBuilder);
- RestoreSingleManifestLinks(migrationBuilder);
- }
-
- /// <summary>
- /// Replaces the single manifest reference on an alias and on a received email with a link table each.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
- private static void LinkClaimsAndEmailsToManifests(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.CreateTable(
- name: "EmailClaimLinks",
- columns: table => new
- {
- EmailClaimId = table.Column<Guid>(type: "uuid", nullable: false),
- VaultManifestId = table.Column<Guid>(type: "uuid", nullable: false),
- State = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_EmailClaimLinks", x => new { x.EmailClaimId, x.VaultManifestId });
- });
-
- migrationBuilder.CreateTable(
- name: "EmailDecryptionKeys",
- columns: table => new
- {
- EmailId = table.Column<int>(type: "integer", nullable: false),
- VaultManifestDeliveryKeyId = table.Column<Guid>(type: "uuid", nullable: false),
- EncryptedSymmetricKey = table.Column<string>(type: "text", nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_EmailDecryptionKeys", x => new { x.EmailId, x.VaultManifestDeliveryKeyId });
- });
-
- migrationBuilder.Sql("""
- INSERT INTO "EmailDecryptionKeys" ("EmailId", "VaultManifestDeliveryKeyId", "EncryptedSymmetricKey")
- SELECT "Id", "EncryptionKeyId", "EncryptedSymmetricKey" FROM "Emails";
-
- INSERT INTO "EmailClaimLinks" ("EmailClaimId", "VaultManifestId", "State")
- SELECT "Id", "VaultManifestId", CASE WHEN "Disabled" THEN 'Removed' ELSE 'Active' END FROM "EmailClaims" WHERE "VaultManifestId" IS NOT NULL;
- """);
-
- migrationBuilder.CreateIndex(
- name: "IX_EmailClaimLinks_VaultManifestId_EmailClaimId",
- table: "EmailClaimLinks",
- columns: new[] { "VaultManifestId", "EmailClaimId" });
-
- migrationBuilder.CreateIndex(
- name: "IX_EmailDecryptionKeys_VaultManifestDeliveryKeyId_EmailId",
- table: "EmailDecryptionKeys",
- columns: new[] { "VaultManifestDeliveryKeyId", "EmailId" });
-
- migrationBuilder.AddForeignKey(
- name: "FK_EmailClaimLinks_EmailClaims_EmailClaimId",
- table: "EmailClaimLinks",
- column: "EmailClaimId",
- principalTable: "EmailClaims",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
-
- migrationBuilder.AddForeignKey(
- name: "FK_EmailClaimLinks_VaultManifests_VaultManifestId",
- table: "EmailClaimLinks",
- column: "VaultManifestId",
- principalTable: "VaultManifests",
- principalColumn: "ManifestId",
- onDelete: ReferentialAction.Cascade);
-
- migrationBuilder.AddForeignKey(
- name: "FK_EmailDecryptionKeys_Emails_EmailId",
- table: "EmailDecryptionKeys",
- column: "EmailId",
- principalTable: "Emails",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
-
- migrationBuilder.AddForeignKey(
- name: "FK_EmailDecryptionKeys_VaultManifestDeliveryKeys_DeliveryKeyId",
- table: "EmailDecryptionKeys",
- column: "VaultManifestDeliveryKeyId",
- principalTable: "VaultManifestDeliveryKeys",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
-
- migrationBuilder.DropForeignKey(name: "FK_EmailClaims_VaultManifests_VaultManifestId", table: "EmailClaims");
- migrationBuilder.DropForeignKey(name: "FK_Emails_VaultManifestDeliveryKeys_EncryptionKeyId", table: "Emails");
- migrationBuilder.DropIndex(name: "IX_Emails_EncryptionKeyId", table: "Emails");
- migrationBuilder.DropIndex(name: "IX_EmailClaims_VaultManifestId_CreatedAt", table: "EmailClaims");
- migrationBuilder.DropIndex(name: "IX_EmailClaims_VaultManifestId_Disabled", table: "EmailClaims");
- migrationBuilder.DropColumn(name: "EncryptedSymmetricKey", table: "Emails");
- migrationBuilder.DropColumn(name: "EncryptionKeyId", table: "Emails");
- migrationBuilder.DropColumn(name: "VaultManifestId", table: "EmailClaims");
- migrationBuilder.DropColumn(name: "Disabled", table: "EmailClaims");
- migrationBuilder.Sql("""CREATE INDEX "IX_EmailClaimLinks_EmailClaimId_Live" ON "EmailClaimLinks" ("EmailClaimId") WHERE "State" <> 'Removed';""");
- }
-
- /// <summary>
- /// Moves the raw message to a binary column and gives the attachment count a column of its own.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
- private static void MoveMessageSourceToBytes(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.AlterColumn<string>(
- name: "MessageSource",
- table: "Emails",
- type: "text",
- nullable: true,
- oldClrType: typeof(string),
- oldType: "text");
-
- migrationBuilder.AddColumn<int>(
- name: "AttachmentCount",
- table: "Emails",
- type: "integer",
- nullable: false,
- defaultValue: 0);
-
- // Backfill the count for emails that predate this column from their attachment records, so the column is
- // authoritative for every row in the table.
- migrationBuilder.Sql("""
- UPDATE "Emails" SET "AttachmentCount" = counts."AttachmentCount"
- FROM (SELECT "EmailId", COUNT(*) AS "AttachmentCount" FROM "EmailAttachments" GROUP BY "EmailId") AS counts
- WHERE "Emails"."Id" = counts."EmailId";
- """);
-
- migrationBuilder.AddColumn<byte[]>(
- name: "MessageSourceBytes",
- table: "Emails",
- type: "bytea",
- nullable: true);
-
- // Both columns hold AES ciphertext which is incompressible, so skip TOAST compression.
- migrationBuilder.Sql("""
- ALTER TABLE "Emails" ALTER COLUMN "MessageSourceBytes" SET STORAGE EXTERNAL;
- ALTER TABLE "EmailAttachments" ALTER COLUMN "Bytes" SET STORAGE EXTERNAL;
- """);
- }
-
- /// <summary>
- /// Adds the table that holds the message body in separately fetchable parts.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
- private static void AddDetachedMessageParts(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.CreateTable(
- name: "EmailParts",
- columns: table => new
- {
- Id = table.Column<int>(type: "integer", nullable: false)
- .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
- EmailId = table.Column<int>(type: "integer", nullable: false),
- PartIndex = table.Column<int>(type: "integer", nullable: false),
- Bytes = table.Column<byte[]>(type: "bytea", nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_EmailParts", x => x.Id);
- table.ForeignKey(
- name: "FK_EmailParts_Emails_EmailId",
- column: x => x.EmailId,
- principalTable: "Emails",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
- });
-
- migrationBuilder.CreateIndex(
- name: "IX_EmailParts_EmailId_PartIndex",
- table: "EmailParts",
- columns: new[] { "EmailId", "PartIndex" },
- unique: true);
-
- // The part bodies are AES ciphertext which is incompressible, so skip TOAST compression.
- migrationBuilder.Sql(@"ALTER TABLE ""EmailParts"" ALTER COLUMN ""Bytes"" SET STORAGE EXTERNAL;");
- }
-
- /// <summary>
- /// Adds the anonymized first-time sender buckets and the per-alias flag that feeds them.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
- private static void AddAnonymizedSenderCounts(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.AddColumn<int[]>(
- name: "AnonymizedEmailAliasSenderCounts",
- table: "Groups",
- type: "integer[]",
- nullable: false,
- defaultValueSql: "array_fill(0, ARRAY[64])");
-
- migrationBuilder.AddColumn<bool>(
- name: "AnonymizedSenderCounted",
- table: "EmailClaims",
- type: "boolean",
- nullable: false,
- defaultValue: false);
- }
-
- /// <summary>
- /// Drops the anonymized first-time sender buckets again.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
- private static void RemoveAnonymizedSenderCounts(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropColumn(
- name: "AnonymizedEmailAliasSenderCounts",
- table: "Groups");
-
- migrationBuilder.DropColumn(
- name: "AnonymizedSenderCounted",
- table: "EmailClaims");
- }
-
- /// <summary>
- /// Drops the detached message parts.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
- private static void DropDetachedMessageParts(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropTable(
- name: "EmailParts");
- }
-
- /// <summary>
- /// Moves the raw message back to the text column and drops the attachment counter.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
- private static void RestoreMessageSourceText(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.Sql(@"ALTER TABLE ""EmailAttachments"" ALTER COLUMN ""Bytes"" SET STORAGE EXTENDED;");
-
- migrationBuilder.DropColumn(
- name: "AttachmentCount",
- table: "Emails");
-
- migrationBuilder.DropColumn(
- name: "MessageSourceBytes",
- table: "Emails");
-
- migrationBuilder.AlterColumn<string>(
- name: "MessageSource",
- table: "Emails",
- type: "text",
- nullable: false,
- defaultValue: "",
- oldClrType: typeof(string),
- oldType: "text",
- oldNullable: true);
- }
-
- /// <summary>
- /// Collapses the link tables back into the single manifest reference an alias and an email used to carry.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
- private static void RestoreSingleManifestLinks(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.Sql("""DROP INDEX IF EXISTS "IX_EmailClaimLinks_EmailClaimId_Live";""");
-
- migrationBuilder.AddColumn<bool>(
- name: "Disabled",
- table: "EmailClaims",
- type: "boolean",
- nullable: false,
- defaultValue: false);
-
- // Rebuild the roll-up from the links before they are dropped with the table below.
- migrationBuilder.Sql("""
- UPDATE "EmailClaims" c
- SET "Disabled" = NOT EXISTS (SELECT 1 FROM "EmailClaimLinks" l WHERE l."EmailClaimId" = c."Id" AND l."State" <> 'Removed');
- """);
-
- migrationBuilder.AddColumn<string>(
- name: "EncryptedSymmetricKey",
- table: "Emails",
- type: "text",
- nullable: true);
-
- migrationBuilder.AddColumn<Guid>(
- name: "EncryptionKeyId",
- table: "Emails",
- type: "uuid",
- maxLength: 255,
- nullable: true);
-
- migrationBuilder.AddColumn<Guid>(
- name: "VaultManifestId",
- table: "EmailClaims",
- type: "uuid",
- nullable: true);
-
- // Collapse back to one decryption key/link per row (the lowest key/manifest id when there are several - the
- // extra decryption keys are unrepresentable in the singular model and are dropped with the table). An email
- // whose decryption keys are all gone is undecryptable and cannot be represented either; it is deleted.
- migrationBuilder.Sql("""
- UPDATE "Emails" e
- SET "EncryptionKeyId" = d."VaultManifestDeliveryKeyId", "EncryptedSymmetricKey" = d."EncryptedSymmetricKey"
- FROM (SELECT DISTINCT ON ("EmailId") "EmailId", "VaultManifestDeliveryKeyId", "EncryptedSymmetricKey" FROM "EmailDecryptionKeys" ORDER BY "EmailId", "VaultManifestDeliveryKeyId") d
- WHERE d."EmailId" = e."Id";
-
- DELETE FROM "Emails" WHERE "EncryptionKeyId" IS NULL;
-
- UPDATE "EmailClaims" c
- SET "VaultManifestId" = l."VaultManifestId"
- FROM (SELECT DISTINCT ON ("EmailClaimId") "EmailClaimId", "VaultManifestId" FROM "EmailClaimLinks" ORDER BY "EmailClaimId", "VaultManifestId") l
- WHERE l."EmailClaimId" = c."Id";
- """);
-
- migrationBuilder.AlterColumn<string>(
- name: "EncryptedSymmetricKey",
- table: "Emails",
- type: "text",
- nullable: false,
- oldClrType: typeof(string),
- oldType: "text",
- oldNullable: true);
-
- migrationBuilder.AlterColumn<Guid>(
- name: "EncryptionKeyId",
- table: "Emails",
- type: "uuid",
- maxLength: 255,
- nullable: false,
- oldClrType: typeof(Guid),
- oldType: "uuid",
- oldMaxLength: 255,
- oldNullable: true);
-
- migrationBuilder.DropTable(name: "EmailClaimLinks");
- migrationBuilder.DropTable(name: "EmailDecryptionKeys");
-
- migrationBuilder.CreateIndex(
- name: "IX_Emails_EncryptionKeyId",
- table: "Emails",
- column: "EncryptionKeyId");
-
- migrationBuilder.CreateIndex(
- name: "IX_EmailClaims_VaultManifestId_CreatedAt",
- table: "EmailClaims",
- columns: new[] { "VaultManifestId", "CreatedAt" });
-
- migrationBuilder.CreateIndex(
- name: "IX_EmailClaims_VaultManifestId_Disabled",
- table: "EmailClaims",
- columns: new[] { "VaultManifestId", "Disabled" });
-
- migrationBuilder.AddForeignKey(
- name: "FK_EmailClaims_VaultManifests_VaultManifestId",
- table: "EmailClaims",
- column: "VaultManifestId",
- principalTable: "VaultManifests",
- principalColumn: "ManifestId",
- onDelete: ReferentialAction.SetNull);
-
- migrationBuilder.AddForeignKey(
- name: "FK_Emails_VaultManifestDeliveryKeys_EncryptionKeyId",
- table: "Emails",
- column: "EncryptionKeyId",
- principalTable: "VaultManifestDeliveryKeys",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
- }
- }
-}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260817222545_ReorderTableColumns.Designer.cs b/apps/server/Databases/AliasServerDb/Migrations/20260817222545_ReorderTableColumns.Designer.cs
deleted file mode 100644
index 2d3ab5487..000000000
--- a/apps/server/Databases/AliasServerDb/Migrations/20260817222545_ReorderTableColumns.Designer.cs
+++ /dev/null
@@ -1,1786 +0,0 @@
-// <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("20260817222545_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(255)
- .HasColumnType("character varying(255)");
-
- 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<bool>("AnonymizedSenderCounted")
- .HasColumnType("boolean");
-
- b.Property<DateTime>("CreatedAt")
- .HasColumnType("timestamp with time zone");
-
- 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.Property<string>("State")
- .IsRequired()
- .HasMaxLength(20)
- .HasColumnType("character varying(20)");
-
- b.HasKey("EmailClaimId", "VaultManifestId");
-
- b.HasIndex("EmailClaimId")
- .HasDatabaseName("IX_EmailClaimLinks_EmailClaimId_Live")
- .HasFilter("\"State\" <> 'Removed'");
-
- b.HasIndex("VaultManifestId", "EmailClaimId");
-
- b.ToTable("EmailClaimLinks");
- });
-
- modelBuilder.Entity("AliasServerDb.EmailDecryptionKey", b =>
- {
- b.Property<int>("EmailId")
- .HasColumnType("integer");
-
- b.Property<Guid>("VaultManifestDeliveryKeyId")
- .HasColumnType("uuid");
-
- b.Property<string>("EncryptedSymmetricKey")
- .IsRequired()
- .HasColumnType("text");
-
- b.HasKey("EmailId", "VaultManifestDeliveryKeyId");
-
- b.HasIndex("VaultManifestDeliveryKeyId", "EmailId");
-
- b.ToTable("EmailDecryptionKeys");
- });
-
- modelBuilder.Entity("AliasServerDb.EmailPart", b =>
- {
- b.Property<int>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("integer");
-
- NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
-
- b.Property<byte[]>("Bytes")
- .IsRequired()
- .HasColumnType("bytea");
-
- b.Property<int>("EmailId")
- .HasColumnType("integer");
-
- b.Property<int>("PartIndex")
- .HasColumnType("integer");
-
- b.HasKey("Id");
-
- b.HasIndex("EmailId", "PartIndex")
- .IsUnique();
-
- b.ToTable("EmailParts");
- });
-
- modelBuilder.Entity("AliasServerDb.Group", b =>
- {
- b.Property<Guid>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("uuid");
-
- b.PrimitiveCollection<int[]>("AnonymizedEmailAliasSenderCounts")
- .IsRequired()
- .ValueGeneratedOnAdd()
- .HasColumnType("integer[]")
- .HasDefaultValueSql("array_fill(0, ARRAY[64])");
-
- 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<string>("Algorithm")
- .IsRequired()
- .HasMaxLength(30)
- .HasColumnType("character varying(30)");
-
- 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<string>("Algorithm")
- .IsRequired()
- .HasMaxLength(30)
- .HasColumnType("character varying(30)");
-
- 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.UserUnlockKeysHistory", 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>("ArchivedAt")
- .HasColumnType("timestamp with time zone");
-
- b.Property<string>("ArchivedByClient")
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- 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<string>("Metadata")
- .HasColumnType("jsonb");
-
- b.Property<string>("Type")
- .IsRequired()
- .HasMaxLength(30)
- .HasColumnType("character varying(30)");
-
- b.Property<Guid>("UnlockKeyId")
- .HasColumnType("uuid");
-
- 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("ArchivedAt")
- .HasDatabaseName("IX_UserUnlockKeysHistory_ArchivedAt");
-
- b.HasIndex("UserId", "Type", "ArchivedAt")
- .HasDatabaseName("IX_UserUnlockKeysHistory_UserId_Type_ArchivedAt");
-
- b.ToTable("UserUnlockKeysHistory", (string)null);
- });
-
- modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>
- {
- b.Property<Guid>("ManifestId")
- .HasColumnType("uuid");
-
- b.Property<string>("Hash")
- .HasMaxLength(64)
- .HasColumnType("character varying(64)");
-
- b.Property<string>("Category")
- .IsRequired()
- .HasMaxLength(20)
- .HasColumnType("character varying(20)");
-
- b.Property<DateTime>("CreatedAt")
- .HasColumnType("timestamp with time zone");
-
- b.Property<string>("EncryptedBlobKey")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.Property<byte[]>("EncryptedData")
- .IsRequired()
- .HasColumnType("bytea");
-
- b.Property<int>("KeyVersion")
- .HasColumnType("integer");
-
- b.Property<int>("SizeBytes")
- .HasColumnType("integer");
-
- b.HasKey("ManifestId", "Hash");
-
- 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<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>("UpdatedByUserId")
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- 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.HasIndex("UpdatedByUserId");
-
- 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<string>("Algorithm")
- .IsRequired()
- .HasMaxLength(30)
- .HasColumnType("character varying(30)");
-
- 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>("UpdatedByUserId")
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- 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.HasIndex("UpdatedByUserId");
-
- 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<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.EmailDecryptionKey", b =>
- {
- b.HasOne("AliasServerDb.Email", "Email")
- .WithMany("DecryptionKeys")
- .HasForeignKey("EmailId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.HasOne("AliasServerDb.VaultManifestDeliveryKey", "VaultManifestDeliveryKey")
- .WithMany("DecryptionKeys")
- .HasForeignKey("VaultManifestDeliveryKeyId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired()
- .HasConstraintName("FK_EmailDecryptionKeys_VaultManifestDeliveryKeys_DeliveryKeyId");
-
- b.Navigation("Email");
-
- b.Navigation("VaultManifestDeliveryKey");
- });
-
- modelBuilder.Entity("AliasServerDb.EmailPart", b =>
- {
- b.HasOne("AliasServerDb.Email", "Email")
- .WithMany("Parts")
- .HasForeignKey("EmailId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Email");
- });
-
- 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.UserUnlockKeysHistory", b =>
- {
- b.HasOne("AliasServerDb.AliasVaultUser", "User")
- .WithMany()
- .HasForeignKey("UserId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("User");
- });
-
- modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>
- {
- b.HasOne("AliasServerDb.VaultManifest", "Manifest")
- .WithMany()
- .HasForeignKey("ManifestId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Manifest");
- });
-
- 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.HasOne("AliasServerDb.AliasVaultUser", "UpdatedByUser")
- .WithMany()
- .HasForeignKey("UpdatedByUserId")
- .OnDelete(DeleteBehavior.SetNull);
-
- b.Navigation("OwnerGroup");
-
- b.Navigation("UpdatedByUser");
- });
-
- 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.HasOne("AliasServerDb.AliasVaultUser", "UpdatedByUser")
- .WithMany()
- .HasForeignKey("UpdatedByUserId")
- .OnDelete(DeleteBehavior.SetNull);
-
- b.Navigation("Manifest");
-
- b.Navigation("UpdatedByUser");
- });
-
- modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>
- {
- b.Navigation("VaultManifestAccessKeys");
- });
-
- modelBuilder.Entity("AliasServerDb.Email", b =>
- {
- b.Navigation("Attachments");
-
- b.Navigation("DecryptionKeys");
-
- b.Navigation("Parts");
- });
-
- modelBuilder.Entity("AliasServerDb.EmailClaim", b =>
- {
- b.Navigation("Links");
- });
-
- modelBuilder.Entity("AliasServerDb.Group", b =>
- {
- b.Navigation("Members");
- });
-
- modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>
- {
- b.Navigation("DecryptionKeys");
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260817222545_ReorderTableColumns.cs b/apps/server/Databases/AliasServerDb/Migrations/20260817222545_ReorderTableColumns.cs
deleted file mode 100644
index 0b21d6ae5..000000000
--- a/apps/server/Databases/AliasServerDb/Migrations/20260817222545_ReorderTableColumns.cs
+++ /dev/null
@@ -1,271 +0,0 @@
-using Microsoft.EntityFrameworkCore.Migrations;
-
-#nullable disable
-
-namespace AliasServerDb.Migrations
-{
- /// <summary>
- /// Reorders the physical columns of the tables that predate the manifest storage model, whose columns were added
- /// and dropped in the order the schema happened to grow. The tables the earlier migrations create are already
- /// created in their final order, so they are left alone here.
- /// </summary>
- public partial class ReorderTableColumns : Migration
- {
- /// <inheritdoc />
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- DropForeignKeys(migrationBuilder);
-
- RebuildAliasVaultUsers(migrationBuilder);
- RebuildGroups(migrationBuilder);
- RebuildEmailClaims(migrationBuilder);
- RebuildRateLimits(migrationBuilder);
- RebuildVaultManifestDeliveryKeys(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 "EmailClaimLinks" DROP CONSTRAINT "FK_EmailClaimLinks_EmailClaims_EmailClaimId";
- ALTER TABLE "EmailDecryptionKeys" DROP CONSTRAINT "FK_EmailDecryptionKeys_VaultManifestDeliveryKeys_DeliveryKeyId";
- ALTER TABLE "GroupMembers" DROP CONSTRAINT "FK_GroupMembers_AliasVaultUsers_UserId";
- ALTER TABLE "GroupMembers" DROP CONSTRAINT "FK_GroupMembers_Groups_GroupId";
- 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 "UserUnlockKeysHistory" DROP CONSTRAINT "FK_UserUnlockKeysHistory_AliasVaultUsers_UserId";
- ALTER TABLE "VaultManifestAccessKeys" DROP CONSTRAINT "FK_VaultManifestAccessKeys_AliasVaultUsers_UserId";
- ALTER TABLE "VaultManifestDeliveryKeys" DROP CONSTRAINT "FK_VaultManifestDeliveryKeys_VaultManifests_VaultManifestId";
- ALTER TABLE "VaultManifests" DROP CONSTRAINT "FK_VaultManifests_AliasVaultUsers_UpdatedByUserId";
- ALTER TABLE "VaultManifests" DROP CONSTRAINT "FK_VaultManifests_Groups_OwnerGroupId";
- ALTER TABLE "VaultManifestsHistory" DROP CONSTRAINT "FK_VaultManifestsHistory_AliasVaultUsers_UpdatedByUserId";
- """);
- }
-
- /// <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>
- /// Moves the anonymized first-time sender buckets up next to the other per-group email counters they belong
- /// with, instead of leaving them behind the audit timestamps where they were appended.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
- private static void RebuildGroups(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.Sql("""
- CREATE TABLE "Groups_reordered" (
- "Id" uuid NOT NULL,
- "Name" character varying(255) NOT NULL,
- "Type" integer NOT NULL,
- "ShadowBlocked" boolean NOT NULL,
- "ShadowBlockedAt" timestamp with time zone,
- "MaxEmails" integer NOT NULL,
- "MaxEmailAgeDays" integer NOT NULL,
- "EmailsReceived" integer NOT NULL,
- "AnonymizedEmailAliasSenderCounts" integer[] DEFAULT array_fill(0, ARRAY[64]) NOT NULL,
- "CreatedAt" timestamp with time zone NOT NULL,
- "UpdatedAt" timestamp with time zone NOT NULL
- );
-
- INSERT INTO "Groups_reordered" ("Id", "Name", "Type", "ShadowBlocked", "ShadowBlockedAt", "MaxEmails", "MaxEmailAgeDays", "EmailsReceived", "AnonymizedEmailAliasSenderCounts", "CreatedAt", "UpdatedAt")
- SELECT "Id", "Name", "Type", "ShadowBlocked", "ShadowBlockedAt", "MaxEmails", "MaxEmailAgeDays", "EmailsReceived", "AnonymizedEmailAliasSenderCounts", "CreatedAt", "UpdatedAt"
- FROM "Groups";
-
- DROP TABLE "Groups";
- ALTER TABLE "Groups_reordered" RENAME TO "Groups";
-
- ALTER TABLE "Groups" ADD CONSTRAINT "PK_Groups" PRIMARY KEY ("Id");
- """);
- }
-
- /// <summary>
- /// Moves the anonymized sender flag up next to the address it describes, and compacts the dead column slots
- /// this table carries from the user-owned claim model it was migrated away from.
- /// </summary>
- /// <param name="migrationBuilder">Migration builder.</param>
- private static void RebuildEmailClaims(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.Sql("""
- CREATE TABLE "EmailClaims_reordered" (
- "Id" uuid NOT NULL,
- "Address" character varying(255) NOT NULL,
- "AddressLocal" character varying(255) NOT NULL,
- "AddressDomain" character varying(255) NOT NULL,
- "AnonymizedSenderCounted" boolean DEFAULT false NOT NULL,
- "CreatedAt" timestamp with time zone NOT NULL,
- "UpdatedAt" timestamp with time zone NOT NULL
- );
-
- INSERT INTO "EmailClaims_reordered" ("Id", "Address", "AddressLocal", "AddressDomain", "AnonymizedSenderCounted", "CreatedAt", "UpdatedAt")
- SELECT "Id", "Address", "AddressLocal", "AddressDomain", "AnonymizedSenderCounted", "CreatedAt", "UpdatedAt"
- FROM "EmailClaims";
-
- DROP TABLE "EmailClaims";
- ALTER TABLE "EmailClaims_reordered" RENAME TO "EmailClaims";
-
- ALTER TABLE "EmailClaims" ADD CONSTRAINT "PK_EmailClaims" PRIMARY KEY ("Id");
- CREATE UNIQUE INDEX "IX_EmailClaims_Address" ON "EmailClaims" ("Address");
- """);
- }
-
- /// <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>
- /// Moves the manifest a delivery key belongs to and its algorithm up next to the primary key instead of
- /// leaving them 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,
- "Algorithm" character varying(30) 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", "Algorithm", "PublicKey", "IsPrimary", "CreatedAt", "UpdatedAt")
- SELECT "Id", "VaultManifestId", "Algorithm", "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>
- /// 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 "EmailClaimLinks" ADD CONSTRAINT "FK_EmailClaimLinks_EmailClaims_EmailClaimId" FOREIGN KEY ("EmailClaimId") REFERENCES "EmailClaims"("Id") ON DELETE CASCADE;
- ALTER TABLE "EmailDecryptionKeys" ADD CONSTRAINT "FK_EmailDecryptionKeys_VaultManifestDeliveryKeys_DeliveryKeyId" FOREIGN KEY ("VaultManifestDeliveryKeyId") 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 "GroupMembers" ADD CONSTRAINT "FK_GroupMembers_Groups_GroupId" FOREIGN KEY ("GroupId") REFERENCES "Groups"("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 "UserUnlockKeysHistory" ADD CONSTRAINT "FK_UserUnlockKeysHistory_AliasVaultUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AliasVaultUsers"("Id") ON DELETE CASCADE;
- ALTER TABLE "VaultManifestAccessKeys" ADD CONSTRAINT "FK_VaultManifestAccessKeys_AliasVaultUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AliasVaultUsers"("Id") ON DELETE CASCADE;
- 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_AliasVaultUsers_UpdatedByUserId" FOREIGN KEY ("UpdatedByUserId") REFERENCES "AliasVaultUsers"("Id") ON DELETE SET NULL;
- 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_AliasVaultUsers_UpdatedByUserId" FOREIGN KEY ("UpdatedByUserId") REFERENCES "AliasVaultUsers"("Id") ON DELETE SET NULL;
- """);
- }
- }
-}