feat(email): add tenant draft persistence
Add owner-filtered, job-cascading private draft storage with reversible SQLite and MariaDB migration paths. No API or UI exposes draft content yet.
This commit is contained in:
@@ -62,6 +62,7 @@ namespace JobTrackerApi.Data
|
||||
public DbSet<UserOperation> UserOperations => Set<UserOperation>();
|
||||
public DbSet<UserNotification> UserNotifications => Set<UserNotification>();
|
||||
public DbSet<EmailSendAttempt> EmailSendAttempts => Set<EmailSendAttempt>();
|
||||
public DbSet<EmailDraft> EmailDrafts => Set<EmailDraft>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
@@ -280,6 +281,21 @@ namespace JobTrackerApi.Data
|
||||
.HasForeignKey(x => x.JobApplicationId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<EmailDraft>()
|
||||
.HasQueryFilter(x => CurrentUserId != null && x.OwnerUserId == CurrentUserId);
|
||||
modelBuilder.Entity<EmailDraft>().Property(x => x.OwnerUserId).HasMaxLength(255);
|
||||
modelBuilder.Entity<EmailDraft>().Property(x => x.Provider).HasMaxLength(32);
|
||||
modelBuilder.Entity<EmailDraft>().Property(x => x.To).HasMaxLength(320);
|
||||
modelBuilder.Entity<EmailDraft>().Property(x => x.Subject).HasMaxLength(998);
|
||||
modelBuilder.Entity<EmailDraft>().Property(x => x.ThreadId).HasMaxLength(512);
|
||||
modelBuilder.Entity<EmailDraft>()
|
||||
.HasIndex(x => new { x.OwnerUserId, x.JobApplicationId, x.UpdatedAtUtc });
|
||||
modelBuilder.Entity<EmailDraft>()
|
||||
.HasOne(x => x.JobApplication)
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.JobApplicationId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<TailoredCvDraft>()
|
||||
.HasQueryFilter(x => CurrentUserId != null && x.OwnerUserId == CurrentUserId);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace JobTrackerApi.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddEmailDrafts : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
if (ActiveProvider.Contains("MySql", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
migrationBuilder.Sql("""
|
||||
CREATE TABLE `EmailDrafts` (
|
||||
`Id` char(36) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
|
||||
`OwnerUserId` varchar(255) NOT NULL,
|
||||
`JobApplicationId` int NOT NULL,
|
||||
`Provider` varchar(32) NOT NULL,
|
||||
`To` varchar(320) NOT NULL,
|
||||
`Subject` varchar(998) NOT NULL,
|
||||
`BodyText` longtext NOT NULL,
|
||||
`ThreadId` varchar(512) NULL,
|
||||
`Revision` bigint NOT NULL,
|
||||
`CreatedAtUtc` datetime(6) NOT NULL,
|
||||
`UpdatedAtUtc` datetime(6) NOT NULL,
|
||||
CONSTRAINT `PK_EmailDrafts` PRIMARY KEY (`Id`),
|
||||
CONSTRAINT `FK_EmailDrafts_JobApplications_JobApplicationId`
|
||||
FOREIGN KEY (`JobApplicationId`) REFERENCES `JobApplications` (`Id`) ON DELETE CASCADE
|
||||
) CHARACTER SET=utf8mb4;
|
||||
""");
|
||||
}
|
||||
else
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "EmailDrafts",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
OwnerUserId = table.Column<string>(type: "TEXT", maxLength: 255, nullable: false),
|
||||
JobApplicationId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Provider = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
|
||||
To = table.Column<string>(type: "TEXT", maxLength: 320, nullable: false),
|
||||
Subject = table.Column<string>(type: "TEXT", maxLength: 998, nullable: false),
|
||||
BodyText = table.Column<string>(type: "TEXT", nullable: false),
|
||||
ThreadId = table.Column<string>(type: "TEXT", maxLength: 512, nullable: true),
|
||||
Revision = table.Column<long>(type: "INTEGER", nullable: false),
|
||||
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
UpdatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_EmailDrafts", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_EmailDrafts_JobApplications_JobApplicationId",
|
||||
column: x => x.JobApplicationId,
|
||||
principalTable: "JobApplications",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
}
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_EmailDrafts_JobApplicationId",
|
||||
table: "EmailDrafts",
|
||||
column: "JobApplicationId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_EmailDrafts_OwnerUserId_JobApplicationId_UpdatedAtUtc",
|
||||
table: "EmailDrafts",
|
||||
columns: new[] { "OwnerUserId", "JobApplicationId", "UpdatedAtUtc" });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "EmailDrafts");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1098,6 +1098,61 @@ namespace JobTrackerApi.Migrations
|
||||
b.ToTable("CvVariantVersions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JobTrackerApi.Models.EmailDraft", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("BodyText")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAtUtc")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("JobApplicationId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("OwnerUserId")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Provider")
|
||||
.IsRequired()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<long>("Revision")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Subject")
|
||||
.IsRequired()
|
||||
.HasMaxLength(998)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("ThreadId")
|
||||
.HasMaxLength(512)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("To")
|
||||
.IsRequired()
|
||||
.HasMaxLength(320)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("UpdatedAtUtc")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("JobApplicationId");
|
||||
|
||||
b.HasIndex("OwnerUserId", "JobApplicationId", "UpdatedAtUtc");
|
||||
|
||||
b.ToTable("EmailDrafts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JobTrackerApi.Models.EmailSendAttempt", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -2446,6 +2501,17 @@ namespace JobTrackerApi.Migrations
|
||||
b.Navigation("CvVariant");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JobTrackerApi.Models.EmailDraft", b =>
|
||||
{
|
||||
b.HasOne("JobTrackerApi.Models.JobApplication", "JobApplication")
|
||||
.WithMany()
|
||||
.HasForeignKey("JobApplicationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("JobApplication");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JobTrackerApi.Models.EmailSendAttempt", b =>
|
||||
{
|
||||
b.HasOne("JobTrackerApi.Models.JobApplication", "JobApplication")
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace JobTrackerApi.Models;
|
||||
|
||||
public sealed class EmailDraft
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string OwnerUserId { get; set; } = string.Empty;
|
||||
public int JobApplicationId { get; set; }
|
||||
public JobApplication JobApplication { get; set; } = null!;
|
||||
public string Provider { get; set; } = string.Empty;
|
||||
public string To { get; set; } = string.Empty;
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
public string BodyText { get; set; } = string.Empty;
|
||||
public string? ThreadId { get; set; }
|
||||
public long Revision { get; set; } = 1;
|
||||
public DateTime CreatedAtUtc { get; set; }
|
||||
public DateTime UpdatedAtUtc { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user