- Add EF Core migrations for initial schema (clubs, members, work_items, shifts, shift_signups) - Implement RLS policies with SET LOCAL for tenant isolation - Add Finbuckle multi-tenant middleware with ClaimStrategy + HeaderStrategy fallback - Create TenantValidationMiddleware to enforce JWT claims match X-Tenant-Id header - Add tenant-aware DB interceptors (SaveChangesTenantInterceptor, TenantDbConnectionInterceptor) - Configure AppDbContext with tenant scoping and RLS support - Add test infrastructure: CustomWebApplicationFactory, TestAuthHandler, DatabaseFixture - Write TDD integration tests for multi-tenant isolation and RLS enforcement - Add health check null safety for connection string Tasks: 7 (PostgreSQL schema + migrations + RLS), 8 (Finbuckle multi-tenancy + validation), 12 (test infrastructure)
66 lines
1.8 KiB
C#
66 lines
1.8 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
using WorkClub.Domain.Entities;
|
|
|
|
namespace WorkClub.Infrastructure.Data.Configurations;
|
|
|
|
public class WorkItemConfiguration : IEntityTypeConfiguration<WorkItem>
|
|
{
|
|
public void Configure(EntityTypeBuilder<WorkItem> builder)
|
|
{
|
|
builder.ToTable("work_items");
|
|
|
|
builder.HasKey(w => w.Id);
|
|
|
|
builder.Property(w => w.TenantId)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.Property(w => w.Title)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.Property(w => w.Description)
|
|
.HasMaxLength(2000);
|
|
|
|
builder.Property(w => w.Status)
|
|
.IsRequired()
|
|
.HasConversion<int>();
|
|
|
|
builder.Property(w => w.AssigneeId);
|
|
|
|
builder.Property(w => w.CreatedById)
|
|
.IsRequired();
|
|
|
|
builder.Property(w => w.ClubId)
|
|
.IsRequired();
|
|
|
|
builder.Property(w => w.DueDate);
|
|
|
|
builder.Property(w => w.CreatedAt)
|
|
.IsRequired();
|
|
|
|
builder.Property(w => w.UpdatedAt)
|
|
.IsRequired();
|
|
|
|
builder.Property(w => w.RowVersion)
|
|
.IsRowVersion()
|
|
.HasColumnName("xmin")
|
|
.HasColumnType("xid")
|
|
.ValueGeneratedOnAddOrUpdate();
|
|
|
|
builder.HasIndex(w => w.TenantId)
|
|
.HasDatabaseName("ix_work_items_tenant_id");
|
|
|
|
builder.HasIndex(w => w.ClubId)
|
|
.HasDatabaseName("ix_work_items_club_id");
|
|
|
|
builder.HasIndex(w => w.Status)
|
|
.HasDatabaseName("ix_work_items_status");
|
|
|
|
builder.HasIndex(w => w.AssigneeId)
|
|
.HasDatabaseName("ix_work_items_assignee_id");
|
|
}
|
|
}
|