aboutsummaryrefslogtreecommitdiff
path: root/lib/Emails.Transactional.Plugin/src/EmailDbCtx.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-04-13 11:40:22 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-04-13 11:40:22 -0400
commite5675b3ef2c688923e7c32e00fa55a5c3d4e233f (patch)
treef61bbca2d6e56fae0c560257b2b083da4f0cc339 /lib/Emails.Transactional.Plugin/src/EmailDbCtx.cs
parentb7dba1a8f68073cd1ef648ea369c6c3a8b33678f (diff)
Extension updates with database creation
Diffstat (limited to 'lib/Emails.Transactional.Plugin/src/EmailDbCtx.cs')
-rw-r--r--lib/Emails.Transactional.Plugin/src/EmailDbCtx.cs71
1 files changed, 69 insertions, 2 deletions
diff --git a/lib/Emails.Transactional.Plugin/src/EmailDbCtx.cs b/lib/Emails.Transactional.Plugin/src/EmailDbCtx.cs
index cd865d8..82bf696 100644
--- a/lib/Emails.Transactional.Plugin/src/EmailDbCtx.cs
+++ b/lib/Emails.Transactional.Plugin/src/EmailDbCtx.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2022 Vaughn Nugent
+* Copyright (c) 2023 Vaughn Nugent
*
* Library: VNLib
* Package: Transactional Emails
@@ -27,14 +27,81 @@ using System;
using Microsoft.EntityFrameworkCore;
using VNLib.Plugins.Extensions.Data;
+using VNLib.Plugins.Extensions.Loading.Sql;
namespace Emails.Transactional
{
- internal class EmailDbCtx : TransactionalDbContext
+ internal class EmailDbCtx : TransactionalDbContext, IDbTableDefinition
{
public DbSet<EmailTransaction> EmailTransactions { get; set; }
public EmailDbCtx(DbContextOptions options) : base(options)
{}
+
+ public EmailDbCtx()
+ { }
+
+ public void OnDatabaseCreating(IDbContextBuilder builder, object? userState)
+ {
+ //Define email tables
+ builder.DefineTable<EmailTransaction>(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);
+ }
}
}