diff options
author | vnugent <public@vaughnnugent.com> | 2023-04-13 11:37:30 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-04-13 11:37:30 -0400 |
commit | 0bafd510a0091960dbfe5ad08d3d524153117536 (patch) | |
tree | 414a00aae7afc84f9b11d6bd7395248d5d24b668 /plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model | |
parent | 5d0660dea5e20d1bda06ea9b06b04bbac36b0db9 (diff) |
Database creation tools
Diffstat (limited to 'plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model')
-rw-r--r-- | plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs | 4 | ||||
-rw-r--r-- | plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/RoutingContext.cs | 53 |
2 files changed, 54 insertions, 3 deletions
diff --git a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs index 8c52725..c1531f7 100644 --- a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs +++ b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.Content.Routing @@ -23,6 +23,7 @@ */ using System; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Microsoft.EntityFrameworkCore; @@ -34,6 +35,7 @@ namespace VNLib.Plugins.Essentials.Content.Routing.Model [Index(nameof(Id), IsUnique = true)] internal class Route : DbModelBase { + [Key] public override string Id { get; set; } public override DateTime Created { get; set; } public override DateTime LastModified { get; set; } diff --git a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/RoutingContext.cs b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/RoutingContext.cs index 0cbd90f..4edb892 100644 --- a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/RoutingContext.cs +++ b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/RoutingContext.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.Content.Routing @@ -27,15 +27,64 @@ using System; using Microsoft.EntityFrameworkCore; using VNLib.Plugins.Extensions.Data; +using VNLib.Plugins.Extensions.Loading.Sql; namespace VNLib.Plugins.Essentials.Content.Routing.Model { - internal class RoutingContext : TransactionalDbContext + internal class RoutingContext : TransactionalDbContext, IDbTableDefinition { public DbSet<Route> Routes { get; set; } +#nullable disable + public RoutingContext(DbContextOptions options) :base(options) { } + + public RoutingContext() + {} + +#nullable enable + + public void OnDatabaseCreating(IDbContextBuilder builder, object? userState) + { + //Build the route table + + builder.DefineTable<Route>(nameof(Routes)) + .WithColumn(r => r.Id) + .MaxLength(50) + .Next() + + .WithColumn(r => r.Hostname) + .MaxLength(100) + .AllowNull(false) + .Next() + + .WithColumn(r => r.MatchPath) + .MaxLength(1000) + .AllowNull(false) + .Next() + + //Default to read-on + .WithColumn(r => r.Privilage) + .WithDefault(Accounts.AccountUtil.READ_MSK) + .AllowNull(false) + .Next() + + .WithColumn(r => r.Alternate) + .MaxLength(1000) + .Next() + + .WithColumn(r => (int)r.Routine) + .WithDefault(FpRoutine.Continue) + .Next() + + .WithColumn(r => r.Created) + .AllowNull(false) + .Next() + + .WithColumn(r => r.LastModified) + .AllowNull(false); + } } } |