From 50f2cf42fdb4eafbfff6f5628cc46074bf2d1eaf Mon Sep 17 00:00:00 2001 From: vnugent Date: Sat, 30 Mar 2024 22:11:13 -0400 Subject: chore: Impletment SQL loading api updates --- lib/Emails.Transactional.Plugin/src/EmailDbCtx.cs | 84 ++++++---------------- .../src/EmailTransaction.cs | 2 + 2 files changed, 23 insertions(+), 63 deletions(-) diff --git a/lib/Emails.Transactional.Plugin/src/EmailDbCtx.cs b/lib/Emails.Transactional.Plugin/src/EmailDbCtx.cs index a88f35c..6f9b051 100644 --- a/lib/Emails.Transactional.Plugin/src/EmailDbCtx.cs +++ b/lib/Emails.Transactional.Plugin/src/EmailDbCtx.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: Emails.Transactional @@ -31,9 +31,7 @@ using VNLib.Plugins.Extensions.Loading.Sql; namespace Emails.Transactional { - - - internal class EmailDbCtx : DBContextBase, IDbTableDefinition + internal sealed class EmailDbCtx : DBContextBase, IDbTableDefinition { public DbSet EmailTransactions { get; set; } @@ -45,65 +43,25 @@ namespace Emails.Transactional public void OnDatabaseCreating(IDbContextBuilder builder, object? userState) { - //Define email tables - builder.DefineTable(nameof(EmailTransactions)) - - //Start with id, its a primary key - .WithColumn(e => e.Id) - .MaxLength(50) - .Next() - - .WithColumn(e => e.Created) - .AllowNull(false) - .Next() - - .WithColumn(e => e.LastModified) - .AllowNull(false) - .Next() - - .WithColumn(e => e.UserId) - .MaxLength(100) - .Next() - - //To is allowed to be null - .WithColumn(e => e.To) - .MaxLength(1000) - .Next() - - .WithColumn(e => e.From) - .MaxLength(100) - .Next() - - .WithColumn(e => e.FromName) - .MaxLength(100) - .Next() - - .WithColumn(e => e.Subject) - .MaxLength(500) - .Next() - - .WithColumn(e => e.Ccs) - .MaxLength(1000) - .Next() - - .WithColumn(e => e.Bccs) - .MaxLength(1000) - .Next() - - .WithColumn(e => e.ReplyTo) - .MaxLength(100) - .Next() - - .WithColumn(e => e.ReplyToName) - .MaxLength(100) - .Next() - - .WithColumn(e => e.TemplateId) - .MaxLength(100) - .Next() - - .WithColumn(e => e.Result) - .MaxLength(200); + //Define the transaction table + builder.DefineTable(nameof(EmailTransactions), table => + { + table.WithColumn(e => e.Id).AllowNull(false); + table.WithColumn(e => e.Created); + table.WithColumn(e => e.LastModified); + table.WithColumn(e => e.Version); + table.WithColumn(e => e.UserId).AllowNull(false); + table.WithColumn(e => e.To).MaxLength(1000); + table.WithColumn(e => e.From).MaxLength(100); + table.WithColumn(e => e.FromName).MaxLength(100); + table.WithColumn(e => e.Subject).MaxLength(500); + table.WithColumn(e => e.Ccs).MaxLength(1000); + table.WithColumn(e => e.Bccs).MaxLength(1000); + table.WithColumn(e => e.ReplyTo).MaxLength(100); + table.WithColumn(e => e.ReplyToName).MaxLength(100); + table.WithColumn(e => e.TemplateId).MaxLength(100); + table.WithColumn(e => e.Result).MaxLength(200); + }); } } } diff --git a/lib/Emails.Transactional.Plugin/src/EmailTransaction.cs b/lib/Emails.Transactional.Plugin/src/EmailTransaction.cs index 5ce2040..dbc0ad6 100644 --- a/lib/Emails.Transactional.Plugin/src/EmailTransaction.cs +++ b/lib/Emails.Transactional.Plugin/src/EmailTransaction.cs @@ -43,6 +43,7 @@ namespace Emails.Transactional { /// [Key] + [MaxLength(64)] [JsonPropertyName("id")] public override string Id { get; set; } /// @@ -56,6 +57,7 @@ namespace Emails.Transactional /// The sever side user-id that send the email /// [JsonIgnore] + [MaxLength(64)] public string? UserId { get; set; } //To address -- cgit