Add initial hcs database schema creation
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
@page "/management/users"
|
||||
|
||||
@using System.IdentityModel.Claims
|
||||
@using Hcs.WebApp.Components.Dialogs
|
||||
@using Hcs.WebApp.Services
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using System.IdentityModel.Claims
|
||||
|
||||
@attribute [Authorize]
|
||||
|
||||
|
||||
@ -4,7 +4,8 @@
|
||||
@using Hcs.WebApp.Components
|
||||
@using Hcs.WebApp.Components.Layout
|
||||
@using Hcs.WebApp.Components.Shared
|
||||
@using Hcs.WebApp.Data
|
||||
@using Hcs.WebApp.Data.Hcs
|
||||
@using Hcs.WebApp.Data.Identity
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using Microsoft.AspNetCore.Components.Routing
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using Hcs.WebApp.Data;
|
||||
using Hcs.WebApp.Data.Identity;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
12
Hcs.WebApp/Data/Hcs/HcsDbContext.cs
Normal file
12
Hcs.WebApp/Data/Hcs/HcsDbContext.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Hcs.WebApp.Data.Hcs
|
||||
{
|
||||
public class HcsDbContext(DbContextOptions<HcsDbContext> options) : DbContext(options)
|
||||
{
|
||||
public DbSet<Registry> Registries { get; set; }
|
||||
|
||||
public DbSet<RegistryElement> Elements { get; set; }
|
||||
}
|
||||
}
|
||||
82
Hcs.WebApp/Data/Hcs/Migrations/20251022073558_CreateHcsSchema.Designer.cs
generated
Normal file
82
Hcs.WebApp/Data/Hcs/Migrations/20251022073558_CreateHcsSchema.Designer.cs
generated
Normal file
@ -0,0 +1,82 @@
|
||||
// <auto-generated />
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
namespace Hcs.WebApp.Data.Hcs.Migrations
|
||||
{
|
||||
[DbContext(typeof(HcsDbContext))]
|
||||
[Migration("20251022073558_CreateHcsSchema")]
|
||||
partial class CreateHcsSchema
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.9")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Hcs.WebApp.Data.Hcs.Registry", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<int>("Number")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Registries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Hcs.WebApp.Data.Hcs.RegistryElement", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Code")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("GUID")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("RegistryId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Xml")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RegistryId");
|
||||
|
||||
b.ToTable("Elements");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Hcs.WebApp.Data.Hcs.RegistryElement", b =>
|
||||
{
|
||||
b.HasOne("Hcs.WebApp.Data.Hcs.Registry", "Registry")
|
||||
.WithMany("Elements")
|
||||
.HasForeignKey("RegistryId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Registry");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Hcs.WebApp.Data.Hcs.Registry", b =>
|
||||
{
|
||||
b.Navigation("Elements");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
namespace Hcs.WebApp.Data.Hcs.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class CreateHcsSchema : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Registries",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
Number = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Registries", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Elements",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
RegistryId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
Code = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
GUID = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Xml = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Elements", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Elements_Registries_RegistryId",
|
||||
column: x => x.RegistryId,
|
||||
principalTable: "Registries",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Elements_RegistryId",
|
||||
table: "Elements",
|
||||
column: "RegistryId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Elements");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Registries");
|
||||
}
|
||||
}
|
||||
}
|
||||
79
Hcs.WebApp/Data/Hcs/Migrations/HcsDbContextModelSnapshot.cs
Normal file
79
Hcs.WebApp/Data/Hcs/Migrations/HcsDbContextModelSnapshot.cs
Normal file
@ -0,0 +1,79 @@
|
||||
// <auto-generated />
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
|
||||
#nullable disable
|
||||
namespace Hcs.WebApp.Data.Hcs.Migrations
|
||||
{
|
||||
[DbContext(typeof(HcsDbContext))]
|
||||
partial class HcsDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.9")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Hcs.WebApp.Data.Hcs.Registry", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<int>("Number")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Registries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Hcs.WebApp.Data.Hcs.RegistryElement", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Code")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("GUID")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("RegistryId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Xml")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RegistryId");
|
||||
|
||||
b.ToTable("Elements");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Hcs.WebApp.Data.Hcs.RegistryElement", b =>
|
||||
{
|
||||
b.HasOne("Hcs.WebApp.Data.Hcs.Registry", "Registry")
|
||||
.WithMany("Elements")
|
||||
.HasForeignKey("RegistryId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Registry");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Hcs.WebApp.Data.Hcs.Registry", b =>
|
||||
{
|
||||
b.Navigation("Elements");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Hcs.WebApp/Data/Hcs/Registry.cs
Normal file
11
Hcs.WebApp/Data/Hcs/Registry.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace Hcs.WebApp.Data.Hcs
|
||||
{
|
||||
public class Registry
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public int Number { get; set; }
|
||||
|
||||
public virtual ICollection<RegistryElement> Elements { get; set; } = [];
|
||||
}
|
||||
}
|
||||
17
Hcs.WebApp/Data/Hcs/RegistryElement.cs
Normal file
17
Hcs.WebApp/Data/Hcs/RegistryElement.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace Hcs.WebApp.Data.Hcs
|
||||
{
|
||||
public class RegistryElement
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public string RegistryId { get; set; }
|
||||
|
||||
public virtual Registry Registry { get; set; } = null!;
|
||||
|
||||
public string Code { get; set; }
|
||||
|
||||
public string GUID { get; set; }
|
||||
|
||||
public virtual string Xml { get; set; }
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
|
||||
namespace Hcs.WebApp.Data
|
||||
namespace Hcs.WebApp.Data.Identity
|
||||
{
|
||||
public class AppIdentityDbContext(DbContextOptions<AppIdentityDbContext> options) : IdentityDbContext<AppUser, AppRole, string>(options)
|
||||
{
|
||||
@ -1,6 +1,6 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace Hcs.WebApp.Data
|
||||
namespace Hcs.WebApp.Data.Identity
|
||||
{
|
||||
public class AppRole : IdentityRole
|
||||
{
|
||||
@ -1,6 +1,6 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace Hcs.WebApp.Data
|
||||
namespace Hcs.WebApp.Data.Identity
|
||||
{
|
||||
public class AppUser : IdentityUser
|
||||
{
|
||||
@ -1,4 +1,4 @@
|
||||
namespace Hcs.WebApp.Data
|
||||
namespace Hcs.WebApp.Data.Identity
|
||||
{
|
||||
public class AppUserWithRole
|
||||
{
|
||||
@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
namespace Hcs.WebApp.Data.Migrations
|
||||
namespace Hcs.WebApp.Data.Identity.Migrations
|
||||
{
|
||||
[DbContext(typeof(AppIdentityDbContext))]
|
||||
[Migration("00000000000000_CreateIdentitySchema")]
|
||||
@ -1,7 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
namespace Hcs.WebApp.Data.Migrations
|
||||
namespace Hcs.WebApp.Data.Identity.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class CreateIdentitySchema : Migration
|
||||
@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
namespace Hcs.WebApp.Data.Migrations
|
||||
namespace Hcs.WebApp.Data.Identity.Migrations
|
||||
{
|
||||
[DbContext(typeof(AppIdentityDbContext))]
|
||||
[Migration("20251019083804_AddRolePriority")]
|
||||
@ -1,7 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
namespace Hcs.WebApp.Data.Migrations
|
||||
namespace Hcs.WebApp.Data.Identity.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddRolePriority : Migration
|
||||
@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
|
||||
#nullable disable
|
||||
namespace Hcs.WebApp.Data.Migrations
|
||||
namespace Hcs.WebApp.Data.Identity.Migrations
|
||||
{
|
||||
[DbContext(typeof(AppIdentityDbContext))]
|
||||
public partial class AppIdentityDbContextModelSnapshot : ModelSnapshot
|
||||
@ -1,6 +1,7 @@
|
||||
using Hcs.WebApp.Components;
|
||||
using Hcs.WebApp.Components.Shared;
|
||||
using Hcs.WebApp.Data;
|
||||
using Hcs.WebApp.Data.Hcs;
|
||||
using Hcs.WebApp.Data.Identity;
|
||||
using Hcs.WebApp.Services;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
@ -22,8 +23,8 @@ builder.Services.AddHeaderPropagation(x => x.Headers.Add("Cookie"));
|
||||
builder.Services.AddAuthentication();
|
||||
builder.Services.AddAuthorization();
|
||||
|
||||
var connectionString = builder.Configuration.GetConnectionString("IdentityConnection") ?? throw new InvalidOperationException("<22><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 'IdentityConnection'");
|
||||
builder.Services.AddDbContextFactory<AppIdentityDbContext>(options => options.UseSqlServer(connectionString));
|
||||
var identityConnection = builder.Configuration.GetConnectionString("IdentityConnection") ?? throw new InvalidOperationException("<22><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 'IdentityConnection'");
|
||||
builder.Services.AddDbContextFactory<AppIdentityDbContext>(options => options.UseSqlServer(identityConnection));
|
||||
|
||||
builder.Services
|
||||
.AddIdentity<AppUser, AppRole>(options =>
|
||||
@ -38,6 +39,17 @@ builder.Services
|
||||
.AddEntityFrameworkStores<AppIdentityDbContext>()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
if (builder.Environment.IsDevelopment())
|
||||
{
|
||||
var hcsProdConnection = builder.Configuration.GetConnectionString("HcsSit2Connection") ?? throw new InvalidOperationException("<22><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 'HcsSit2Connection'");
|
||||
builder.Services.AddDbContextFactory<HcsDbContext>(options => options.UseSqlServer(hcsProdConnection));
|
||||
}
|
||||
else
|
||||
{
|
||||
var hcsProdConnection = builder.Configuration.GetConnectionString("HcsProdConnection") ?? throw new InvalidOperationException("<22><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 'HcsProdConnection'");
|
||||
builder.Services.AddDbContextFactory<HcsDbContext>(options => options.UseSqlServer(hcsProdConnection));
|
||||
}
|
||||
|
||||
#if USE_MOCK
|
||||
builder.Services.AddTransient<IClientProvider, MockClientProvider>();
|
||||
#else
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using Hcs.WebApp.Data;
|
||||
using Hcs.WebApp.Data.Identity;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
||||
@ -13,6 +13,8 @@
|
||||
"CertificateSerialNumber": "0636D2330032B3C38A4A26D765C787C248"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"AuthConnection": "Server=localhost\\SQLEXPRESS;Database=hcs_web_app_identity;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=Yes"
|
||||
"AuthConnection": "Server=localhost\\SQLEXPRESS;Database=hcs_web_app_identity;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=Yes",
|
||||
"HcsProdConnection": "Server=localhost\\SQLEXPRESS;Database=hcs_web_app_prod;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=Yes",
|
||||
"HcsSit2Connection": "Server=localhost\\SQLEXPRESS;Database=hcs_web_app_sit2;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=Yes"
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,6 +13,8 @@
|
||||
"CertificateSerialNumber": "0636D2330032B3C38A4A26D765C787C248"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"IdentityConnection": "Server=localhost\\SQLEXPRESS;Database=hcs_web_app_identity;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=Yes"
|
||||
"IdentityConnection": "Server=localhost\\SQLEXPRESS;Database=hcs_web_app_identity;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=Yes",
|
||||
"HcsProdConnection": "Server=localhost\\SQLEXPRESS;Database=hcs_web_app_prod;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=Yes",
|
||||
"HcsSit2Connection": "Server=localhost\\SQLEXPRESS;Database=hcs_web_app_sit2;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=Yes"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user