- 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)
68 lines
1.8 KiB
C#
68 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 ShiftConfiguration : IEntityTypeConfiguration<Shift>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Shift> builder)
|
|
{
|
|
builder.ToTable("shifts");
|
|
|
|
builder.HasKey(s => s.Id);
|
|
|
|
builder.Property(s => s.TenantId)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.Property(s => s.Title)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.Property(s => s.Description)
|
|
.HasMaxLength(2000);
|
|
|
|
builder.Property(s => s.Location)
|
|
.HasMaxLength(500);
|
|
|
|
builder.Property(s => s.StartTime)
|
|
.IsRequired();
|
|
|
|
builder.Property(s => s.EndTime)
|
|
.IsRequired();
|
|
|
|
builder.Property(s => s.Capacity)
|
|
.IsRequired()
|
|
.HasDefaultValue(1);
|
|
|
|
builder.Property(s => s.ClubId)
|
|
.IsRequired();
|
|
|
|
builder.Property(s => s.CreatedById)
|
|
.IsRequired();
|
|
|
|
builder.Property(s => s.CreatedAt)
|
|
.IsRequired();
|
|
|
|
builder.Property(s => s.UpdatedAt)
|
|
.IsRequired();
|
|
|
|
builder.Property(s => s.RowVersion)
|
|
.IsRowVersion()
|
|
.HasColumnName("xmin")
|
|
.HasColumnType("xid")
|
|
.ValueGeneratedOnAddOrUpdate();
|
|
|
|
builder.HasIndex(s => s.TenantId)
|
|
.HasDatabaseName("ix_shifts_tenant_id");
|
|
|
|
builder.HasIndex(s => s.ClubId)
|
|
.HasDatabaseName("ix_shifts_club_id");
|
|
|
|
builder.HasIndex(s => s.StartTime)
|
|
.HasDatabaseName("ix_shifts_start_time");
|
|
}
|
|
}
|