Skip to content

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

Add group structure (#2159)

Leendert de Borst25d99254714e
diff --git a/apps/server/Databases/AliasServerDb/Group.cs b/apps/server/Databases/AliasServerDb/Group.cs
new file mode 100644
index 000000000..71774e7ce
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/Group.cs
@@ -0,0 +1,49 @@
+//-----------------------------------------------------------------------
+// <copyright file="Group.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasServerDb;
+
+using System.ComponentModel.DataAnnotations;
+
+/// <summary>
+/// Groups own all vault content and email aliases. A group can contain one or members who
+/// are allowed to access the group's vault content, enabling optional sharing and collaboration.
+/// </summary>
+public class Group
+{
+ /// <summary>
+ /// Gets or sets the primary key.
+ /// </summary>
+ [Key]
+ public Guid Id { get; set; }
+
+ /// <summary>
+ /// Gets or sets the display name of the group.
+ /// </summary>
+ [StringLength(255)]
+ public string Name { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the type of group. Personal groups are created automatically per user in a one-to-one relationship by design.
+ /// </summary>
+ public GroupType Type { get; set; } = GroupType.Personal;
+
+ /// <summary>
+ /// Gets or sets the members of the group.
+ /// </summary>
+ public virtual ICollection<GroupMember> Members { get; set; } = [];
+
+ /// <summary>
+ /// Gets or sets created timestamp.
+ /// </summary>
+ public DateTime CreatedAt { get; set; }
+
+ /// <summary>
+ /// Gets or sets updated timestamp.
+ /// </summary>
+ public DateTime UpdatedAt { get; set; }
+}
diff --git a/apps/server/Databases/AliasServerDb/GroupMember.cs b/apps/server/Databases/AliasServerDb/GroupMember.cs
new file mode 100644
index 000000000..25d49b85e
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/GroupMember.cs
@@ -0,0 +1,63 @@
+//-----------------------------------------------------------------------
+// <copyright file="GroupMember.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasServerDb;
+
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using Microsoft.EntityFrameworkCore;
+
+/// <summary>
+/// A user's membership of a <see cref="Group"/>.
+/// </summary>
+[Index(nameof(GroupId), nameof(UserId), IsUnique = true)]
+public class GroupMember
+{
+ /// <summary>
+ /// Gets or sets the primary key.
+ /// </summary>
+ [Key]
+ public Guid Id { get; set; }
+
+ /// <summary>
+ /// Gets or sets the group this membership belongs to.
+ /// </summary>
+ public Guid GroupId { get; set; }
+
+ /// <summary>
+ /// Gets or sets the navigation property to the group.
+ /// </summary>
+ [ForeignKey("GroupId")]
+ public virtual Group Group { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the member.
+ /// </summary>
+ [StringLength(255)]
+ public string UserId { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the navigation property to the member.
+ /// </summary>
+ [ForeignKey("UserId")]
+ public virtual AliasVaultUser User { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets what this member may do in the group.
+ /// </summary>
+ public GroupRole Role { get; set; } = GroupRole.Member;
+
+ /// <summary>
+ /// Gets or sets created timestamp.
+ /// </summary>
+ public DateTime CreatedAt { get; set; }
+
+ /// <summary>
+ /// Gets or sets updated timestamp.
+ /// </summary>
+ public DateTime UpdatedAt { get; set; }
+}
diff --git a/apps/server/Databases/AliasServerDb/GroupRole.cs b/apps/server/Databases/AliasServerDb/GroupRole.cs
new file mode 100644
index 000000000..6e9b60059
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/GroupRole.cs
@@ -0,0 +1,29 @@
+//-----------------------------------------------------------------------
+// <copyright file="GroupRole.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasServerDb;
+
+/// <summary>
+/// Group roles.
+/// </summary>
+public enum GroupRole
+{
+ /// <summary>
+ /// Can use shared folders they hold a grant on.
+ /// </summary>
+ Member = 0,
+
+ /// <summary>
+ /// Can invite and remove members and administer the group's shared folders.
+ /// </summary>
+ Admin = 1,
+
+ /// <summary>
+ /// The group's owner: everything an admin can do, plus managing the group's plan and deleting the group itself.
+ /// </summary>
+ Owner = 2,
+}
diff --git a/apps/server/Databases/AliasServerDb/GroupType.cs b/apps/server/Databases/AliasServerDb/GroupType.cs
new file mode 100644
index 000000000..ccb752132
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/GroupType.cs
@@ -0,0 +1,24 @@
+//-----------------------------------------------------------------------
+// <copyright file="GroupType.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasServerDb;
+
+/// <summary>
+/// Group types.
+/// </summary>
+public enum GroupType
+{
+ /// <summary>
+ /// The implicit group created for every user, owner of the user's own content. Has exactly one member by design.
+ /// </summary>
+ Personal = 0,
+
+ /// <summary>
+ /// A group users join by invitation to be able to participate in shared vaults. Represents "family" in UI.
+ /// </summary>
+ Shared = 1,
+}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260728102956_AddGroupsAndSharedOwnership.Designer.cs b/apps/server/Databases/AliasServerDb/Migrations/20260728102956_AddGroupsAndSharedOwnership.Designer.cs
new file mode 100644
index 000000000..af48cd4cc
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/Migrations/20260728102956_AddGroupsAndSharedOwnership.Designer.cs
@@ -0,0 +1,1591 @@
+// <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("20260728102956_AddGroupsAndSharedOwnership")]
+ partial class AddGroupsAndSharedOwnership
+ {
+ /// <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.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")
+ .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.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")
+ .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<int>("EmailsReceived")
+ .HasColumnType("integer");
+
+ 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<int>("MaxEmailAgeDays")
+ .HasColumnType("integer");
+
+ b.Property<int>("MaxEmails")
+ .HasColumnType("integer");
+
+ 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<bool>("ShadowBlocked")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime?>("ShadowBlockedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("SrpIdentity")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<bool>("TwoFactorEnabled")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserName")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.HasIndex("PersonalGroupId")
+ .IsUnique()
+ .HasDatabaseName("UX_AliasVaultUsers_PersonalGroupId");
+
+ b.ToTable("AliasVaultUsers");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUserRefreshToken", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("DeviceIdentifier")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<DateTime>("ExpireDate")
+ .HasMaxLength(255)
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("IpAddress")
+ .HasMaxLength(45)
+ .HasColumnType("character varying(45)");
+
+ b.Property<string>("PreviousTokenValue")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Value")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("AliasVaultUserRefreshTokens");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AuthLog", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("AdditionalInfo")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Browser")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("Client")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("Country")
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("DeviceType")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<int>("EventType")
+ .HasColumnType("integer");
+
+ b.Property<int?>("FailureReason")
+ .HasColumnType("integer");
+
+ b.Property<string>("IpAddress")
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<bool>("IsSuccess")
+ .HasColumnType("boolean");
+
+ b.Property<bool>("IsSuspiciousActivity")
+ .HasColumnType("boolean");
+
+ b.Property<string>("OperatingSystem")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("RequestPath")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<DateTime>("Timestamp")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Username")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex(new[] { "EventType" }, "IX_EventType");
+
+ b.HasIndex(new[] { "IpAddress" }, "IX_IpAddress");
+
+ b.HasIndex(new[] { "Timestamp" }, "IX_Timestamp");
+
+ b.HasIndex(new[] { "Username", "IsSuccess", "Timestamp" }, "IX_Username_IsSuccess_Timestamp")
+ .IsDescending(false, false, true);
+
+ b.HasIndex(new[] { "Username", "Timestamp" }, "IX_Username_Timestamp")
+ .IsDescending(false, true);
+
+ b.ToTable("AuthLogs");
+ });
+
+ modelBuilder.Entity("AliasServerDb.BlockedIpRange", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<bool>("BlockLogin")
+ .HasColumnType("boolean");
+
+ b.Property<bool>("BlockRegistration")
+ .HasColumnType("boolean");
+
+ b.Property<bool>("BlockShadow")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("CreatedBy")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<bool>("Enabled")
+ .HasColumnType("boolean");
+
+ b.Property<string>("IpRange")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("Reason")
+ .HasMaxLength(500)
+ .HasColumnType("character varying(500)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.HasIndex(new[] { "Enabled" }, "IX_BlockedIpRange_Enabled");
+
+ b.HasIndex(new[] { "IpRange" }, "IX_BlockedIpRange_IpRange")
+ .IsUnique();
+
+ b.ToTable("BlockedIpRanges");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Email", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<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");
+
+ 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")
+ .IsRequired()
+ .HasColumnType("text");
+
+ 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("EncryptionKeyId");
+
+ b.HasIndex("PushNotificationSent");
+
+ b.HasIndex("Visible");
+
+ b.HasIndex("To", "DateSystem");
+
+ b.ToTable("Emails");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailAttachment", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<byte[]>("Bytes")
+ .IsRequired()
+ .HasColumnType("bytea");
+
+ b.Property<DateTime>("Date")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("EmailId")
+ .HasColumnType("integer");
+
+ b.Property<string>("Filename")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<int>("Filesize")
+ .HasColumnType("integer");
+
+ b.Property<string>("MimeType")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.HasIndex("EmailId");
+
+ b.ToTable("EmailAttachments");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailClaim", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Address")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("AddressDomain")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("AddressLocal")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("Disabled")
+ .HasColumnType("boolean");
+
+ b.Property<Guid?>("EncryptionKeyId")
+ .HasColumnType("uuid");
+
+ b.Property<Guid?>("OwnerGroupId")
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid?>("VaultManifestId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Address")
+ .IsUnique();
+
+ b.HasIndex("EncryptionKeyId");
+
+ b.HasIndex("VaultManifestId");
+
+ b.HasIndex("OwnerGroupId", "CreatedAt");
+
+ b.HasIndex("OwnerGroupId", "Disabled");
+
+ b.ToTable("EmailClaims");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EncryptionKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("IsPrimary")
+ .HasColumnType("boolean");
+
+ b.Property<string>("PublicKey")
+ .IsRequired()
+ .HasMaxLength(2000)
+ .HasColumnType("character varying(2000)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<Guid?>("VaultManifestId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("VaultManifestId");
+
+ b.HasIndex("UserId", "VaultManifestId", "IsPrimary");
+
+ b.ToTable("EncryptionKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Group", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Name")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<int>("Type")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.ToTable("Groups");
+ });
+
+ modelBuilder.Entity("AliasServerDb.GroupMember", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid>("GroupId")
+ .HasColumnType("uuid");
+
+ b.Property<int>("Role")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.HasIndex("GroupId", "UserId")
+ .IsUnique();
+
+ b.ToTable("GroupMembers");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Log", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("Application")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("Exception")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("Level")
+ .IsRequired()
+ .HasMaxLength(128)
+ .HasColumnType("character varying(128)");
+
+ b.Property<string>("LogEvent")
+ .IsRequired()
+ .HasColumnType("text")
+ .HasColumnName("LogEvent");
+
+ b.Property<string>("Message")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("MessageTemplate")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("Properties")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("SourceContext")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("TimeStamp")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Application");
+
+ b.HasIndex("TimeStamp");
+
+ b.ToTable("Logs", (string)null);
+ });
+
+ modelBuilder.Entity("AliasServerDb.MobileLoginRequest", b =>
+ {
+ b.Property<string>("Id")
+ .HasColumnType("text");
+
+ b.Property<DateTime?>("ClearedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("ClientIpAddress")
+ .HasColumnType("text");
+
+ b.Property<string>("ClientPublicKey")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedDecryptionKey")
+ .HasColumnType("text");
+
+ b.Property<DateTime?>("FulfilledAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("MobileIpAddress")
+ .HasColumnType("text");
+
+ b.Property<DateTime?>("RetrievedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.HasIndex(new[] { "ClientIpAddress" }, "IX_ClientIpAddress");
+
+ b.HasIndex(new[] { "CreatedAt" }, "IX_CreatedAt");
+
+ b.HasIndex(new[] { "MobileIpAddress" }, "IX_MobileIpAddress");
+
+ b.HasIndex(new[] { "RetrievedAt", "ClearedAt", "FulfilledAt" }, "IX_RetrievedAt_ClearedAt_FulfilledAt");
+
+ b.HasIndex(new[] { "UserId" }, "IX_UserId");
+
+ b.ToTable("MobileLoginRequests");
+ });
+
+ modelBuilder.Entity("AliasServerDb.RateLimit", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<int?>("AppliesToAccountAgeMaxDays")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("CreatedBy")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime?>("EffectiveFrom")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<DateTime?>("EffectiveUntil")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("Enabled")
+ .HasColumnType("boolean");
+
+ b.Property<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<string>("UserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<int>("WindowSeconds")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Tier");
+
+ b.HasIndex("UserId");
+
+ 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.VaultBlobObject", b =>
+ {
+ b.Property<string>("Hash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<string>("OwnerUserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Category")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<byte[]>("EncryptedData")
+ .IsRequired()
+ .HasColumnType("bytea");
+
+ b.Property<DateTime>("LastReferencedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("SizeBytes")
+ .HasColumnType("integer");
+
+ b.HasKey("Hash", "OwnerUserId");
+
+ b.HasIndex("OwnerUserId", "Category");
+
+ b.ToTable("VaultBlobObjects");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultBlobReference", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<string>("BlobHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.HasKey("ManifestId", "RevisionNumber", "BlobHash");
+
+ b.ToTable("VaultBlobReferences");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucket", b =>
+ {
+ b.Property<string>("OwnerUserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ 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<string>("EncryptedData")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("OwnerUserId", "Category");
+
+ b.ToTable("VaultDataBuckets");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucketsHistory", b =>
+ {
+ b.Property<string>("OwnerUserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ 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<string>("EncryptedData")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("OwnerUserId", "Category", "RevisionNumber");
+
+ b.ToTable("VaultDataBucketsHistory");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptionSettings")
+ .HasColumnType("text");
+
+ b.Property<string>("EncryptionType")
+ .HasColumnType("text");
+
+ b.Property<string>("KeyType")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<DateTime?>("LastUsedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Metadata")
+ .HasColumnType("jsonb");
+
+ b.Property<Guid?>("RecipientPublicKeyId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("Salt")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<Guid?>("VaultManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("Verifier")
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<string>("WrapScheme")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<string>("WrappedVek")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.HasIndex("VaultManifestId")
+ .HasDatabaseName("IX_VaultKeys_VaultManifestId");
+
+ b.HasIndex("UserId", "KeyType", "VaultManifestId")
+ .IsUnique()
+ .HasDatabaseName("UX_VaultKeys_UserId_KeyType_Manifest");
+
+ b.ToTable("VaultKeys");
+ });
+
+ 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")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("EncryptionType")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<int>("FileSize")
+ .HasColumnType("integer");
+
+ b.Property<bool>("IsRoot")
+ .HasColumnType("boolean");
+
+ b.Property<string>("ManifestBlob")
+ .HasColumnType("text");
+
+ b.Property<string>("ManifestCiphertextHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<string>("Name")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<Guid>("OwnerGroupId")
+ .HasColumnType("uuid");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<string>("Salt")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("StorageFormat")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("VaultBlob")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("Verifier")
+ .IsRequired()
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<string>("Version")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("ManifestId");
+
+ b.HasIndex("OwnerGroupId")
+ .IsUnique()
+ .HasDatabaseName("UX_VaultManifests_OwnerGroupId_Root")
+ .HasFilter("\"IsRoot\"");
+
+ b.ToTable("VaultManifests");
+ });
+
+ 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")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("EncryptionType")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<int>("FileSize")
+ .HasColumnType("integer");
+
+ b.Property<string>("ManifestBlob")
+ .HasColumnType("text");
+
+ b.Property<string>("ManifestCiphertextHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<string>("Salt")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("StorageFormat")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("VaultBlob")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("Verifier")
+ .IsRequired()
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<string>("Version")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("ManifestId", "RevisionNumber");
+
+ b.ToTable("VaultManifestsHistory", (string)null);
+ });
+
+ modelBuilder.Entity("AliasVault.WorkerStatus.Database.WorkerServiceStatus", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("CurrentStatus")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("DesiredStatus")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<DateTime>("Heartbeat")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("ServiceName")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.ToTable("WorkerServiceStatuses");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.DataProtectionKey", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("FriendlyName")
+ .HasColumnType("text");
+
+ b.Property<string>("Xml")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("DataProtectionKeys");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.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")
+ .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.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")
+ .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.Email", b =>
+ {
+ b.HasOne("AliasServerDb.EncryptionKey", "EncryptionKey")
+ .WithMany("Emails")
+ .HasForeignKey("EncryptionKeyId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("EncryptionKey");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailAttachment", b =>
+ {
+ b.HasOne("AliasServerDb.Email", "Email")
+ .WithMany("Attachments")
+ .HasForeignKey("EmailId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Email");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailClaim", b =>
+ {
+ b.HasOne("AliasServerDb.EncryptionKey", "EncryptionKey")
+ .WithMany()
+ .HasForeignKey("EncryptionKeyId")
+ .OnDelete(DeleteBehavior.Restrict);
+
+ b.HasOne("AliasServerDb.Group", "OwnerGroup")
+ .WithMany()
+ .HasForeignKey("OwnerGroupId")
+ .OnDelete(DeleteBehavior.SetNull);
+
+ b.HasOne("AliasServerDb.VaultManifest", "VaultManifest")
+ .WithMany()
+ .HasForeignKey("VaultManifestId")
+ .OnDelete(DeleteBehavior.SetNull);
+
+ b.Navigation("EncryptionKey");
+
+ b.Navigation("OwnerGroup");
+
+ b.Navigation("VaultManifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EncryptionKey", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany("EncryptionKeys")
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.HasOne("AliasServerDb.VaultManifest", "VaultManifest")
+ .WithMany()
+ .HasForeignKey("VaultManifestId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.Navigation("User");
+
+ b.Navigation("VaultManifest");
+ });
+
+ 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.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("OwnerUserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultBlobReference", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "Manifest")
+ .WithMany()
+ .HasForeignKey("ManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Manifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucket", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("OwnerUserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucketsHistory", b =>
+ {
+ b.HasOne("AliasServerDb.VaultDataBucket", "Bucket")
+ .WithMany()
+ .HasForeignKey("OwnerUserId", "Category")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Bucket");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultKey", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany("VaultKeys")
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifest", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "OwnerGroup")
+ .WithMany()
+ .HasForeignKey("OwnerGroupId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("OwnerGroup");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestsHistory", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "Manifest")
+ .WithMany()
+ .HasForeignKey("ManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Manifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>
+ {
+ b.Navigation("EncryptionKeys");
+
+ b.Navigation("VaultKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Email", b =>
+ {
+ b.Navigation("Attachments");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EncryptionKey", b =>
+ {
+ b.Navigation("Emails");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Group", b =>
+ {
+ b.Navigation("Members");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260728102956_AddGroupsAndSharedOwnership.cs b/apps/server/Databases/AliasServerDb/Migrations/20260728102956_AddGroupsAndSharedOwnership.cs
new file mode 100644
index 000000000..d4e474586
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/Migrations/20260728102956_AddGroupsAndSharedOwnership.cs
@@ -0,0 +1,455 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace AliasServerDb.Migrations
+{
+ /// <summary>
+ /// Add groups as the ownership path for vault content and email aliases.
+ /// </summary>
+ public partial class AddGroupsAndSharedOwnership : Migration
+ {
+ /// <inheritdoc />
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ // Drop old foreign keys
+ migrationBuilder.DropForeignKey(name: "FK_Emails_UserEncryptionKeys_UserEncryptionKeyId", table: "Emails");
+ migrationBuilder.DropForeignKey(name: "FK_VaultManifests_AliasVaultUsers_OwnerUserId", table: "VaultManifests");
+ migrationBuilder.DropForeignKey(name: "FK_UserEmailClaims_AliasVaultUsers_UserId", table: "UserEmailClaims");
+ migrationBuilder.DropForeignKey(name: "FK_UserEmailClaims_UserEncryptionKeys_EncryptionKeyId", table: "UserEmailClaims");
+ migrationBuilder.DropForeignKey(name: "FK_UserEncryptionKeys_AliasVaultUsers_UserId", table: "UserEncryptionKeys");
+ migrationBuilder.DropForeignKey(name: "FK_UserEncryptionKeys_VaultManifests_VaultManifestId", table: "UserEncryptionKeys");
+
+ // Drop old indexes
+ migrationBuilder.DropIndex(name: "IX_VaultManifestsHistory_OwnerUserId", table: "VaultManifestsHistory");
+ migrationBuilder.DropIndex(name: "UX_VaultManifests_OwnerUserId_Root", table: "VaultManifests");
+ migrationBuilder.DropIndex(name: "IX_UserEmailClaims_UserId_CreatedAt", table: "UserEmailClaims");
+ migrationBuilder.DropIndex(name: "IX_UserEmailClaims_UserId_Disabled", table: "UserEmailClaims");
+
+ // Rename tables
+ migrationBuilder.RenameTable(name: "UserEmailClaims", newName: "EmailClaims");
+ migrationBuilder.RenameTable(name: "UserEncryptionKeys", newName: "EncryptionKeys");
+ migrationBuilder.Sql("""
+ ALTER TABLE "EmailClaims" RENAME CONSTRAINT "PK_UserEmailClaims" TO "PK_EmailClaims";
+ ALTER TABLE "EncryptionKeys" RENAME CONSTRAINT "PK_UserEncryptionKeys" TO "PK_EncryptionKeys";
+ """);
+ migrationBuilder.RenameIndex(name: "IX_UserEmailClaims_Address", table: "EmailClaims", newName: "IX_EmailClaims_Address");
+ migrationBuilder.RenameIndex(name: "IX_UserEmailClaims_EncryptionKeyId", table: "EmailClaims", newName: "IX_EmailClaims_EncryptionKeyId");
+ migrationBuilder.RenameIndex(name: "IX_UserEncryptionKeys_UserId_VaultManifestId_IsPrimary", table: "EncryptionKeys", newName: "IX_EncryptionKeys_UserId_VaultManifestId_IsPrimary");
+ migrationBuilder.RenameIndex(name: "IX_UserEncryptionKeys_VaultManifestId", table: "EncryptionKeys", newName: "IX_EncryptionKeys_VaultManifestId");
+ migrationBuilder.RenameColumn(name: "UserEncryptionKeyId", table: "Emails", newName: "EncryptionKeyId");
+ migrationBuilder.RenameIndex(name: "IX_Emails_UserEncryptionKeyId", table: "Emails", newName: "IX_Emails_EncryptionKeyId");
+
+ // Add new ownership columns
+ migrationBuilder.AddColumn<Guid>(
+ name: "OwnerGroupId",
+ table: "VaultManifests",
+ type: "uuid",
+ nullable: true);
+
+ migrationBuilder.AddColumn<Guid>(
+ name: "OwnerGroupId",
+ table: "EmailClaims",
+ type: "uuid",
+ nullable: true);
+
+ migrationBuilder.AddColumn<Guid>(
+ name: "VaultManifestId",
+ table: "EmailClaims",
+ type: "uuid",
+ nullable: true);
+
+ // Add new personal group column
+ migrationBuilder.AddColumn<Guid>(
+ name: "PersonalGroupId",
+ table: "AliasVaultUsers",
+ type: "uuid",
+ nullable: true);
+
+ // Alter encryption keys table to remove user id column
+ migrationBuilder.AlterColumn<string>(
+ name: "UserId",
+ table: "EncryptionKeys",
+ type: "character varying(255)",
+ maxLength: 255,
+ nullable: true,
+ oldClrType: typeof(string),
+ oldType: "character varying(255)",
+ oldMaxLength: 255);
+
+ // Create groups table
+ migrationBuilder.CreateTable(
+ name: "Groups",
+ columns: table => new
+ {
+ Id = table.Column<Guid>(type: "uuid", nullable: false),
+ Name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
+ Type = table.Column<int>(type: "integer", nullable: false),
+ CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
+ UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Groups", x => x.Id);
+ });
+
+ // Create group members table
+ migrationBuilder.CreateTable(
+ name: "GroupMembers",
+ columns: table => new
+ {
+ Id = table.Column<Guid>(type: "uuid", nullable: false),
+ GroupId = table.Column<Guid>(type: "uuid", nullable: false),
+ UserId = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
+ Role = table.Column<int>(type: "integer", nullable: false),
+ CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
+ UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
+ },
+ 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);
+ });
+
+ // Backfill: every existing user gets their Personal group, every manifest and every email claim becomes owned
+ // by its user's personal group, folder-scoped delivery keys lose their per-user owner.
+ migrationBuilder.Sql("""
+ UPDATE "AliasVaultUsers"
+ SET "PersonalGroupId" = gen_random_uuid()
+ WHERE "PersonalGroupId" IS NULL;
+
+ INSERT INTO "Groups" ("Id", "Name", "Type", "CreatedAt", "UpdatedAt")
+ SELECT u."PersonalGroupId", u."UserName", 0, now(), now()
+ FROM "AliasVaultUsers" u
+ WHERE NOT EXISTS (SELECT 1 FROM "Groups" g WHERE g."Id" = u."PersonalGroupId");
+
+ INSERT INTO "GroupMembers" ("Id", "GroupId", "UserId", "Role", "CreatedAt", "UpdatedAt")
+ SELECT gen_random_uuid(), u."PersonalGroupId", u."Id", 2, now(), now()
+ FROM "AliasVaultUsers" u
+ WHERE NOT EXISTS (SELECT 1 FROM "GroupMembers" m WHERE m."GroupId" = u."PersonalGroupId" AND m."UserId" = u."Id");
+
+ UPDATE "VaultManifests" m
+ SET "OwnerGroupId" = u."PersonalGroupId"
+ FROM "AliasVaultUsers" u
+ WHERE u."Id" = m."OwnerUserId" AND m."OwnerGroupId" IS NULL;
+
+ UPDATE "EmailClaims" c
+ SET "OwnerGroupId" = u."PersonalGroupId"
+ FROM "AliasVaultUsers" u
+ WHERE u."Id" = c."UserId" AND c."OwnerGroupId" IS NULL;
+
+ UPDATE "EncryptionKeys"
+ SET "UserId" = NULL
+ WHERE "VaultManifestId" IS NOT NULL;
+ """);
+
+ migrationBuilder.AlterColumn<Guid>(
+ name: "OwnerGroupId",
+ table: "VaultManifests",
+ type: "uuid",
+ nullable: false,
+ oldClrType: typeof(Guid),
+ oldType: "uuid",
+ oldNullable: true);
+
+ // Every user has a personal group by design from here on.
+ migrationBuilder.AlterColumn<Guid>(
+ name: "PersonalGroupId",
+ table: "AliasVaultUsers",
+ type: "uuid",
+ nullable: false,
+ oldClrType: typeof(Guid),
+ oldType: "uuid",
+ oldNullable: true);
+
+ // Drop old per-user ownership columns
+ migrationBuilder.DropColumn(name: "OwnerUserId", table: "VaultManifestsHistory");
+ migrationBuilder.DropColumn(name: "OwnerUserId", table: "VaultManifests");
+ migrationBuilder.DropColumn(name: "UserId", table: "EmailClaims");
+
+ // Create new indexes and foreign keys
+ migrationBuilder.CreateIndex(
+ name: "UX_VaultManifests_OwnerGroupId_Root",
+ table: "VaultManifests",
+ column: "OwnerGroupId",
+ unique: true,
+ filter: "\"IsRoot\"");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_EmailClaims_OwnerGroupId_CreatedAt",
+ table: "EmailClaims",
+ columns: new[] { "OwnerGroupId", "CreatedAt" });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_EmailClaims_OwnerGroupId_Disabled",
+ table: "EmailClaims",
+ columns: new[] { "OwnerGroupId", "Disabled" });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_EmailClaims_VaultManifestId",
+ table: "EmailClaims",
+ column: "VaultManifestId");
+
+ 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.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.AddForeignKey(
+ name: "FK_Emails_EncryptionKeys_EncryptionKeyId",
+ table: "Emails",
+ column: "EncryptionKeyId",
+ principalTable: "EncryptionKeys",
+ 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_EmailClaims_EncryptionKeys_EncryptionKeyId",
+ table: "EmailClaims",
+ column: "EncryptionKeyId",
+ principalTable: "EncryptionKeys",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Restrict);
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_EmailClaims_Groups_OwnerGroupId",
+ table: "EmailClaims",
+ column: "OwnerGroupId",
+ principalTable: "Groups",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.SetNull);
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_EmailClaims_VaultManifests_VaultManifestId",
+ table: "EmailClaims",
+ column: "VaultManifestId",
+ principalTable: "VaultManifests",
+ principalColumn: "ManifestId",
+ onDelete: ReferentialAction.SetNull);
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_EncryptionKeys_AliasVaultUsers_UserId",
+ table: "EncryptionKeys",
+ column: "UserId",
+ principalTable: "AliasVaultUsers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_EncryptionKeys_VaultManifests_VaultManifestId",
+ table: "EncryptionKeys",
+ column: "VaultManifestId",
+ principalTable: "VaultManifests",
+ principalColumn: "ManifestId",
+ onDelete: ReferentialAction.Cascade);
+ }
+
+ /// <inheritdoc />
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AddColumn<string>(
+ name: "OwnerUserId",
+ table: "VaultManifests",
+ type: "character varying(255)",
+ maxLength: 255,
+ nullable: false,
+ defaultValue: "");
+
+ migrationBuilder.AddColumn<string>(
+ name: "OwnerUserId",
+ table: "VaultManifestsHistory",
+ type: "character varying(255)",
+ maxLength: 255,
+ nullable: false,
+ defaultValue: "");
+
+ migrationBuilder.AddColumn<string>(
+ name: "UserId",
+ table: "EmailClaims",
+ type: "character varying(255)",
+ maxLength: 255,
+ nullable: true);
+
+ migrationBuilder.Sql("""
+ UPDATE "VaultManifests" m
+ SET "OwnerUserId" = u."Id"
+ FROM "AliasVaultUsers" u
+ WHERE u."PersonalGroupId" = m."OwnerGroupId";
+
+ UPDATE "VaultManifestsHistory" h
+ SET "OwnerUserId" = m."OwnerUserId"
+ FROM "VaultManifests" m
+ WHERE m."ManifestId" = h."ManifestId";
+
+ UPDATE "EmailClaims" c
+ SET "UserId" = u."Id"
+ FROM "AliasVaultUsers" u
+ WHERE u."PersonalGroupId" = c."OwnerGroupId";
+
+ UPDATE "EncryptionKeys" k
+ SET "UserId" = u."Id"
+ FROM "VaultManifests" m
+ JOIN "AliasVaultUsers" u ON u."PersonalGroupId" = m."OwnerGroupId"
+ WHERE m."ManifestId" = k."VaultManifestId" AND k."UserId" IS NULL;
+ """);
+
+ migrationBuilder.DropForeignKey(name: "FK_AliasVaultUsers_Groups_PersonalGroupId", table: "AliasVaultUsers");
+ migrationBuilder.DropIndex(name: "UX_AliasVaultUsers_PersonalGroupId", table: "AliasVaultUsers");
+ migrationBuilder.DropColumn(name: "PersonalGroupId", table: "AliasVaultUsers");
+ migrationBuilder.DropForeignKey(name: "FK_Emails_EncryptionKeys_EncryptionKeyId", table: "Emails");
+ migrationBuilder.DropForeignKey(name: "FK_VaultManifests_Groups_OwnerGroupId", table: "VaultManifests");
+ migrationBuilder.DropForeignKey(name: "FK_EmailClaims_EncryptionKeys_EncryptionKeyId", table: "EmailClaims");
+ migrationBuilder.DropForeignKey(name: "FK_EmailClaims_Groups_OwnerGroupId", table: "EmailClaims");
+ migrationBuilder.DropForeignKey(name: "FK_EmailClaims_VaultManifests_VaultManifestId", table: "EmailClaims");
+ migrationBuilder.DropForeignKey(name: "FK_EncryptionKeys_AliasVaultUsers_UserId", table: "EncryptionKeys");
+ migrationBuilder.DropForeignKey(name: "FK_EncryptionKeys_VaultManifests_VaultManifestId", table: "EncryptionKeys");
+
+ migrationBuilder.DropTable(name: "GroupMembers");
+ migrationBuilder.DropTable(name: "Groups");
+
+ migrationBuilder.DropIndex(name: "UX_VaultManifests_OwnerGroupId_Root", table: "VaultManifests");
+ migrationBuilder.DropIndex(name: "IX_EmailClaims_OwnerGroupId_CreatedAt", table: "EmailClaims");
+ migrationBuilder.DropIndex(name: "IX_EmailClaims_OwnerGroupId_Disabled", table: "EmailClaims");
+ migrationBuilder.DropIndex(name: "IX_EmailClaims_VaultManifestId", table: "EmailClaims");
+
+ migrationBuilder.DropColumn(name: "OwnerGroupId", table: "VaultManifests");
+ migrationBuilder.DropColumn(name: "OwnerGroupId", table: "EmailClaims");
+ migrationBuilder.DropColumn(name: "VaultManifestId", table: "EmailClaims");
+
+ migrationBuilder.AlterColumn<string>(
+ name: "UserId",
+ table: "EncryptionKeys",
+ type: "character varying(255)",
+ maxLength: 255,
+ nullable: false,
+ defaultValue: "",
+ oldClrType: typeof(string),
+ oldType: "character varying(255)",
+ oldMaxLength: 255,
+ oldNullable: true);
+
+ migrationBuilder.RenameColumn(name: "EncryptionKeyId", table: "Emails", newName: "UserEncryptionKeyId");
+ migrationBuilder.RenameIndex(name: "IX_Emails_EncryptionKeyId", table: "Emails", newName: "IX_Emails_UserEncryptionKeyId");
+ migrationBuilder.RenameIndex(name: "IX_EmailClaims_Address", table: "EmailClaims", newName: "IX_UserEmailClaims_Address");
+ migrationBuilder.RenameIndex(name: "IX_EmailClaims_EncryptionKeyId", table: "EmailClaims", newName: "IX_UserEmailClaims_EncryptionKeyId");
+ migrationBuilder.RenameIndex(name: "IX_EncryptionKeys_UserId_VaultManifestId_IsPrimary", table: "EncryptionKeys", newName: "IX_UserEncryptionKeys_UserId_VaultManifestId_IsPrimary");
+ migrationBuilder.RenameIndex(name: "IX_EncryptionKeys_VaultManifestId", table: "EncryptionKeys", newName: "IX_UserEncryptionKeys_VaultManifestId");
+ migrationBuilder.Sql("""
+ ALTER TABLE "EmailClaims" RENAME CONSTRAINT "PK_EmailClaims" TO "PK_UserEmailClaims";
+ ALTER TABLE "EncryptionKeys" RENAME CONSTRAINT "PK_EncryptionKeys" TO "PK_UserEncryptionKeys";
+ """);
+ migrationBuilder.RenameTable(name: "EmailClaims", newName: "UserEmailClaims");
+ migrationBuilder.RenameTable(name: "EncryptionKeys", newName: "UserEncryptionKeys");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_VaultManifestsHistory_OwnerUserId",
+ table: "VaultManifestsHistory",
+ column: "OwnerUserId");
+
+ migrationBuilder.CreateIndex(
+ name: "UX_VaultManifests_OwnerUserId_Root",
+ table: "VaultManifests",
+ column: "OwnerUserId",
+ unique: true,
+ filter: "\"IsRoot\"");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_UserEmailClaims_UserId_CreatedAt",
+ table: "UserEmailClaims",
+ columns: new[] { "UserId", "CreatedAt" });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_UserEmailClaims_UserId_Disabled",
+ table: "UserEmailClaims",
+ columns: new[] { "UserId", "Disabled" });
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Emails_UserEncryptionKeys_UserEncryptionKeyId",
+ table: "Emails",
+ column: "UserEncryptionKeyId",
+ principalTable: "UserEncryptionKeys",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_VaultManifests_AliasVaultUsers_OwnerUserId",
+ table: "VaultManifests",
+ column: "OwnerUserId",
+ principalTable: "AliasVaultUsers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_UserEmailClaims_AliasVaultUsers_UserId",
+ table: "UserEmailClaims",
+ column: "UserId",
+ principalTable: "AliasVaultUsers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.SetNull);
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_UserEmailClaims_UserEncryptionKeys_EncryptionKeyId",
+ table: "UserEmailClaims",
+ column: "EncryptionKeyId",
+ principalTable: "UserEncryptionKeys",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Restrict);
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_UserEncryptionKeys_AliasVaultUsers_UserId",
+ table: "UserEncryptionKeys",
+ column: "UserId",
+ principalTable: "AliasVaultUsers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_UserEncryptionKeys_VaultManifests_VaultManifestId",
+ table: "UserEncryptionKeys",
+ column: "VaultManifestId",
+ principalTable: "VaultManifests",
+ principalColumn: "ManifestId",
+ onDelete: ReferentialAction.Cascade);
+ }
+ }
+}