From 0bafd510a0091960dbfe5ad08d3d524153117536 Mon Sep 17 00:00:00 2001 From: vnugent Date: Thu, 13 Apr 2023 11:37:30 -0400 Subject: Database creation tools --- .../src/Model/Route.cs | 4 +- .../src/Model/RoutingContext.cs | 53 +++++++++++++++++++++- 2 files changed, 54 insertions(+), 3 deletions(-) (limited to 'plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model') 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 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(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); + } } } -- cgit