Add initial hcs database schema creation

This commit is contained in:
2025-10-22 16:42:00 +09:00
parent 77626a8e52
commit 37cf856685
38 changed files with 302 additions and 336 deletions

View File

@ -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]

View File

@ -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

View File

@ -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;

View 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; }
}
}

View 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
}
}
}

View File

@ -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");
}
}
}

View 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
}
}
}

View 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; } = [];
}
}

View 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; }
}
}

View File

@ -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)
{

View File

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Identity;
namespace Hcs.WebApp.Data
namespace Hcs.WebApp.Data.Identity
{
public class AppRole : IdentityRole
{

View File

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Identity;
namespace Hcs.WebApp.Data
namespace Hcs.WebApp.Data.Identity
{
public class AppUser : IdentityUser
{

View File

@ -1,4 +1,4 @@
namespace Hcs.WebApp.Data
namespace Hcs.WebApp.Data.Identity
{
public class AppUserWithRole
{

View File

@ -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")]

View File

@ -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

View File

@ -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")]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,4 +1,4 @@
using Hcs.WebApp.Data;
using Hcs.WebApp.Data.Identity;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;

View File

@ -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"
}
}

View File

@ -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"
}
}