Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
// <auto-generated/>
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace AliasServerDb.Migrations
{
/// <inheritdoc />
public partial class InitialMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AdminRoles",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: true),
NormalizedName = table.Column<string>(type: "text", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AdminRoles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AdminUsers",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
LastPasswordChanged = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
UserName = table.Column<string>(type: "text", nullable: true),
NormalizedUserName = table.Column<string>(type: "text", nullable: true),
Email = table.Column<string>(type: "text", nullable: true),
NormalizedEmail = table.Column<string>(type: "text", nullable: true),
EmailConfirmed = table.Column<bool>(type: "boolean", nullable: false),
PasswordHash = table.Column<string>(type: "text", nullable: true),
SecurityStamp = table.Column<string>(type: "text", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true),
PhoneNumber = table.Column<string>(type: "text", nullable: true),
PhoneNumberConfirmed = table.Column<bool>(type: "boolean", nullable: false),
TwoFactorEnabled = table.Column<bool>(type: "boolean", nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
LockoutEnabled = table.Column<bool>(type: "boolean", nullable: false),
AccessFailedCount = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AdminUsers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AliasVaultRoles",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: true),
NormalizedName = table.Column<string>(type: "text", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AliasVaultRoles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AliasVaultUsers",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
PasswordChangedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Blocked = table.Column<bool>(type: "boolean", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UserName = table.Column<string>(type: "text", nullable: true),
NormalizedUserName = table.Column<string>(type: "text", nullable: true),
Email = table.Column<string>(type: "text", nullable: true),
NormalizedEmail = table.Column<string>(type: "text", nullable: true),
EmailConfirmed = table.Column<bool>(type: "boolean", nullable: false),
PasswordHash = table.Column<string>(type: "text", nullable: true),
SecurityStamp = table.Column<string>(type: "text", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true),
PhoneNumber = table.Column<string>(type: "text", nullable: true),
PhoneNumberConfirmed = table.Column<bool>(type: "boolean", nullable: false),
TwoFactorEnabled = table.Column<bool>(type: "boolean", nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
LockoutEnabled = table.Column<bool>(type: "boolean", nullable: false),
AccessFailedCount = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AliasVaultUsers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AuthLogs",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Timestamp = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Username = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
EventType = table.Column<int>(type: "integer", nullable: false),
IsSuccess = table.Column<bool>(type: "boolean", nullable: false),
FailureReason = table.Column<int>(type: "integer", nullable: true),
IpAddress = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
UserAgent = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
DeviceType = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
OperatingSystem = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
Browser = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
Country = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
AdditionalInfo = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
RequestPath = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
IsSuspiciousActivity = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AuthLogs", x => x.Id);
});
migrationBuilder.CreateTable(
name: "DataProtectionKeys",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FriendlyName = table.Column<string>(type: "text", nullable: true),
Xml = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DataProtectionKeys", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Logs",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Application = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
SourceContext = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
Message = table.Column<string>(type: "text", nullable: false),
MessageTemplate = table.Column<string>(type: "text", nullable: false),
Level = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
TimeStamp = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Exception = table.Column<string>(type: "text", nullable: false),
Properties = table.Column<string>(type: "text", nullable: false),
LogEvent = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Logs", x => x.Id);
});
migrationBuilder.CreateTable(
name: "RoleClaims",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
RoleId = table.Column<string>(type: "text", nullable: true),
ClaimType = table.Column<string>(type: "text", nullable: true),
ClaimValue = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_RoleClaims", x => x.Id);
});
migrationBuilder.CreateTable(
name: "ServerSettings",
columns: table => new
{
Key = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
Value = table.Column<string>(type: "text", nullable: true),
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_ServerSettings", x => x.Key);
});
migrationBuilder.CreateTable(
name: "TaskRunnerJobs",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
RunDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
StartTime = table.Column<TimeOnly>(type: "time without time zone", nullable: false),
EndTime = table.Column<TimeOnly>(type: "time without time zone", nullable: true),
Status = table.Column<int>(type: "integer", nullable: false),
ErrorMessage = table.Column<string>(type: "text", nullable: true),
IsOnDemand = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TaskRunnerJobs", x => x.Id);
});
migrationBuilder.CreateTable(
name: "UserClaims",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<string>(type: "text", nullable: true),
ClaimType = table.Column<string>(type: "text", nullable: true),
ClaimValue = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_UserClaims", x => x.Id);
});
migrationBuilder.CreateTable(
name: "UserLogins",
columns: table => new
{
LoginProvider = table.Column<string>(type: "text", nullable: false),
ProviderKey = table.Column<string>(type: "text", nullable: false),
ProviderDisplayName = table.Column<string>(type: "text", nullable: true),
UserId = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_UserLogins", x => new { x.LoginProvider, x.ProviderKey });
});
migrationBuilder.CreateTable(
name: "UserRoles",
columns: table => new
{
UserId = table.Column<string>(type: "text", nullable: false),
RoleId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserRoles", x => new { x.UserId, x.RoleId });
});
migrationBuilder.CreateTable(
name: "UserTokens",
columns: table => new
{
UserId = table.Column<string>(type: "text", nullable: false),
LoginProvider = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Value = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_UserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
});
migrationBuilder.CreateTable(
name: "WorkerServiceStatuses",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ServiceName = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
CurrentStatus = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
DesiredStatus = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
Heartbeat = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_WorkerServiceStatuses", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AliasVaultUserRefreshTokens",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
UserId = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
DeviceIdentifier = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
IpAddress = table.Column<string>(type: "character varying(45)", maxLength: 45, nullable: true),
Value = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
PreviousTokenValue = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
ExpireDate = table.Column<DateTime>(type: "timestamp with time zone", maxLength: 255, nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AliasVaultUserRefreshTokens", x => x.Id);
table.ForeignKey(
name: "FK_AliasVaultUserRefreshTokens_AliasVaultUsers_UserId",
column: x => x.UserId,
principalTable: "AliasVaultUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "UserEmailClaims",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
UserId = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
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),
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_UserEmailClaims", x => x.Id);
table.ForeignKey(
name: "FK_UserEmailClaims_AliasVaultUsers_UserId",
column: x => x.UserId,
principalTable: "AliasVaultUsers",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "UserEncryptionKeys",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
UserId = table.Column<string>(type: "character varying(255)", maxLength: 255, 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)
},
constraints: table =>
{
table.PrimaryKey("PK_UserEncryptionKeys", x => x.Id);
table.ForeignKey(
name: "FK_UserEncryptionKeys_AliasVaultUsers_UserId",
column: x => x.UserId,
principalTable: "AliasVaultUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Vaults",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
UserId = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
VaultBlob = table.Column<string>(type: "text", nullable: false),
Version = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
RevisionNumber = table.Column<long>(type: "bigint", nullable: false),
FileSize = table.Column<int>(type: "integer", nullable: false),
Salt = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
Verifier = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: false),
CredentialsCount = table.Column<int>(type: "integer", nullable: false),
EmailClaimsCount = table.Column<int>(type: "integer", nullable: false),
EncryptionType = table.Column<string>(type: "text", nullable: false),
EncryptionSettings = table.Column<string>(type: "text", 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_Vaults", x => x.Id);
table.ForeignKey(
name: "FK_Vaults_AliasVaultUsers_UserId",
column: x => x.UserId,
principalTable: "AliasVaultUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Emails",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserEncryptionKeyId = table.Column<Guid>(type: "uuid", maxLength: 255, nullable: false),
EncryptedSymmetricKey = table.Column<string>(type: "text", nullable: false),
Subject = table.Column<string>(type: "text", nullable: false),
From = table.Column<string>(type: "text", nullable: false),
FromLocal = table.Column<string>(type: "text", nullable: false),
FromDomain = table.Column<string>(type: "text", nullable: false),
To = table.Column<string>(type: "text", nullable: false),
ToLocal = table.Column<string>(type: "text", nullable: false),
ToDomain = table.Column<string>(type: "text", nullable: false),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
DateSystem = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
MessageHtml = table.Column<string>(type: "text", nullable: true),
MessagePlain = table.Column<string>(type: "text", nullable: true),
MessagePreview = table.Column<string>(type: "text", nullable: true),
MessageSource = table.Column<string>(type: "text", nullable: false),
Visible = table.Column<bool>(type: "boolean", nullable: false),
PushNotificationSent = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Emails", x => x.Id);
table.ForeignKey(
name: "FK_Emails_UserEncryptionKeys_UserEncryptionKeyId",
column: x => x.UserEncryptionKeyId,
principalTable: "UserEncryptionKeys",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "EmailAttachments",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Bytes = table.Column<byte[]>(type: "bytea", nullable: false),
Filename = table.Column<string>(type: "text", nullable: false),
MimeType = table.Column<string>(type: "text", nullable: false),
Filesize = table.Column<int>(type: "integer", nullable: false),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
EmailId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_EmailAttachments", x => x.Id);
table.ForeignKey(
name: "FK_EmailAttachments_Emails_EmailId",
column: x => x.EmailId,
principalTable: "Emails",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_AliasVaultUserRefreshTokens_UserId",
table: "AliasVaultUserRefreshTokens",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_EventType",
table: "AuthLogs",
column: "EventType");
migrationBuilder.CreateIndex(
name: "IX_IpAddress",
table: "AuthLogs",
column: "IpAddress");
migrationBuilder.CreateIndex(
name: "IX_Timestamp",
table: "AuthLogs",
column: "Timestamp");
migrationBuilder.CreateIndex(
name: "IX_Username_IsSuccess_Timestamp",
table: "AuthLogs",
columns: new[] { "Username", "IsSuccess", "Timestamp" },
descending: new[] { false, false, true });
migrationBuilder.CreateIndex(
name: "IX_Username_Timestamp",
table: "AuthLogs",
columns: new[] { "Username", "Timestamp" },
descending: new[] { false, true });
migrationBuilder.CreateIndex(
name: "IX_EmailAttachments_EmailId",
table: "EmailAttachments",
column: "EmailId");
migrationBuilder.CreateIndex(
name: "IX_Emails_Date",
table: "Emails",
column: "Date");
migrationBuilder.CreateIndex(
name: "IX_Emails_DateSystem",
table: "Emails",
column: "DateSystem");
migrationBuilder.CreateIndex(
name: "IX_Emails_PushNotificationSent",
table: "Emails",
column: "PushNotificationSent");
migrationBuilder.CreateIndex(
name: "IX_Emails_ToLocal",
table: "Emails",
column: "ToLocal");
migrationBuilder.CreateIndex(
name: "IX_Emails_UserEncryptionKeyId",
table: "Emails",
column: "UserEncryptionKeyId");
migrationBuilder.CreateIndex(
name: "IX_Emails_Visible",
table: "Emails",
column: "Visible");
migrationBuilder.CreateIndex(
name: "IX_Logs_Application",
table: "Logs",
column: "Application");
migrationBuilder.CreateIndex(
name: "IX_Logs_TimeStamp",
table: "Logs",
column: "TimeStamp");
migrationBuilder.CreateIndex(
name: "IX_UserEmailClaims_Address",
table: "UserEmailClaims",
column: "Address",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_UserEmailClaims_UserId",
table: "UserEmailClaims",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_UserEncryptionKeys_UserId",
table: "UserEncryptionKeys",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Vaults_UserId",
table: "Vaults",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AdminRoles");
migrationBuilder.DropTable(
name: "AdminUsers");
migrationBuilder.DropTable(
name: "AliasVaultRoles");
migrationBuilder.DropTable(
name: "AliasVaultUserRefreshTokens");
migrationBuilder.DropTable(
name: "AuthLogs");
migrationBuilder.DropTable(
name: "DataProtectionKeys");
migrationBuilder.DropTable(
name: "EmailAttachments");
migrationBuilder.DropTable(
name: "Logs");
migrationBuilder.DropTable(
name: "RoleClaims");
migrationBuilder.DropTable(
name: "ServerSettings");
migrationBuilder.DropTable(
name: "TaskRunnerJobs");
migrationBuilder.DropTable(
name: "UserClaims");
migrationBuilder.DropTable(
name: "UserEmailClaims");
migrationBuilder.DropTable(
name: "UserLogins");
migrationBuilder.DropTable(
name: "UserRoles");
migrationBuilder.DropTable(
name: "UserTokens");
migrationBuilder.DropTable(
name: "Vaults");
migrationBuilder.DropTable(
name: "WorkerServiceStatuses");
migrationBuilder.DropTable(
name: "Emails");
migrationBuilder.DropTable(
name: "UserEncryptionKeys");
migrationBuilder.DropTable(
name: "AliasVaultUsers");
}
}
}