feat(expense-snapshot): register snapshot tables + EF migration

This commit is contained in:
Chris Chen
2026-06-25 14:58:18 -07:00
parent c5405a95c3
commit 5957d0f45e
4 changed files with 2781 additions and 0 deletions
+43
View File
@@ -23,6 +23,8 @@ public class AppDbContext : IdentityDbContext<AppUser, AppRole, string>
public DbSet<Form990ExpenseLine> Form990ExpenseLines => Set<Form990ExpenseLine>();
public DbSet<Expense> Expenses => Set<Expense>();
public DbSet<ExpenseLine> ExpenseLines => Set<ExpenseLine>();
public DbSet<ExpenseSnapshot> ExpenseSnapshots => Set<ExpenseSnapshot>();
public DbSet<ExpenseSnapshotLine> ExpenseSnapshotLines => Set<ExpenseSnapshotLine>();
public DbSet<MonthlyStatement> MonthlyStatements => Set<MonthlyStatement>();
public DbSet<ChurchProfile> ChurchProfiles => Set<ChurchProfile>();
public DbSet<Check> Checks => Set<Check>();
@@ -292,6 +294,47 @@ public class AppDbContext : IdentityDbContext<AppUser, AppRole, string>
.HasForeignKey(e => e.SubCategoryId).OnDelete(DeleteBehavior.Restrict);
});
// ── ExpenseSnapshot (reusable vendor-payment template) ───────────────
builder.Entity<ExpenseSnapshot>(entity =>
{
entity.HasQueryFilter(s => !s.IsDeleted);
entity.Property(e => e.Name).HasMaxLength(150).IsRequired();
entity.Property(e => e.Description).HasMaxLength(500).IsRequired();
entity.Property(e => e.VendorName).HasMaxLength(200);
entity.Property(e => e.CheckNumber).HasMaxLength(50);
entity.Property(e => e.CreatedBy).HasMaxLength(450);
entity.Property(e => e.UpdatedBy).HasMaxLength(450);
entity.Property(e => e.DeletedBy).HasMaxLength(450);
entity.HasIndex(e => e.CreatedAt);
entity.HasOne(e => e.Ministry).WithMany()
.HasForeignKey(e => e.MinistryId).OnDelete(DeleteBehavior.Restrict);
});
// ── ExpenseSnapshotLine (category breakdown of one snapshot) ─────────
builder.Entity<ExpenseSnapshotLine>(entity =>
{
// Mirror the parent snapshot's soft-delete filter (required relationship).
entity.HasQueryFilter(l => !l.Snapshot!.IsDeleted);
entity.Property(e => e.FunctionalClass).HasMaxLength(20);
entity.Property(e => e.Amount).HasColumnType("decimal(18,2)");
entity.Property(e => e.Description).HasMaxLength(500);
entity.Property(e => e.CreatedBy).HasMaxLength(450);
entity.Property(e => e.UpdatedBy).HasMaxLength(450);
entity.HasIndex(e => e.SnapshotId);
entity.HasOne(e => e.Snapshot).WithMany(x => x.Lines)
.HasForeignKey(e => e.SnapshotId).OnDelete(DeleteBehavior.Cascade);
entity.HasOne(e => e.CategoryGroup).WithMany()
.HasForeignKey(e => e.CategoryGroupId).OnDelete(DeleteBehavior.Restrict);
entity.HasOne(e => e.SubCategory).WithMany()
.HasForeignKey(e => e.SubCategoryId).OnDelete(DeleteBehavior.Restrict);
});
// ── ChurchProfile (singleton settings) ───────────────────────────────
builder.Entity<ChurchProfile>(entity =>
{
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,122 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace ROLAC.API.Migrations
{
/// <inheritdoc />
public partial class AddExpenseSnapshots : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ExpenseSnapshots",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "character varying(150)", maxLength: 150, nullable: false),
MinistryId = table.Column<int>(type: "integer", nullable: false),
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
VendorName = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
CheckNumber = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
Notes = table.Column<string>(type: "text", nullable: true),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
CreatedBy = table.Column<string>(type: "character varying(450)", maxLength: 450, nullable: false),
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
UpdatedBy = table.Column<string>(type: "character varying(450)", maxLength: 450, nullable: false),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
DeletedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
DeletedBy = table.Column<string>(type: "character varying(450)", maxLength: 450, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ExpenseSnapshots", x => x.Id);
table.ForeignKey(
name: "FK_ExpenseSnapshots_Ministries_MinistryId",
column: x => x.MinistryId,
principalTable: "Ministries",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "ExpenseSnapshotLines",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
SnapshotId = table.Column<int>(type: "integer", nullable: false),
CategoryGroupId = table.Column<int>(type: "integer", nullable: false),
SubCategoryId = table.Column<int>(type: "integer", nullable: false),
FunctionalClass = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true),
Amount = table.Column<decimal>(type: "numeric(18,2)", nullable: false),
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
CreatedBy = table.Column<string>(type: "character varying(450)", maxLength: 450, nullable: false),
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
UpdatedBy = table.Column<string>(type: "character varying(450)", maxLength: 450, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ExpenseSnapshotLines", x => x.Id);
table.ForeignKey(
name: "FK_ExpenseSnapshotLines_ExpenseCategoryGroups_CategoryGroupId",
column: x => x.CategoryGroupId,
principalTable: "ExpenseCategoryGroups",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_ExpenseSnapshotLines_ExpenseSnapshots_SnapshotId",
column: x => x.SnapshotId,
principalTable: "ExpenseSnapshots",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ExpenseSnapshotLines_ExpenseSubCategories_SubCategoryId",
column: x => x.SubCategoryId,
principalTable: "ExpenseSubCategories",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_ExpenseSnapshotLines_CategoryGroupId",
table: "ExpenseSnapshotLines",
column: "CategoryGroupId");
migrationBuilder.CreateIndex(
name: "IX_ExpenseSnapshotLines_SnapshotId",
table: "ExpenseSnapshotLines",
column: "SnapshotId");
migrationBuilder.CreateIndex(
name: "IX_ExpenseSnapshotLines_SubCategoryId",
table: "ExpenseSnapshotLines",
column: "SubCategoryId");
migrationBuilder.CreateIndex(
name: "IX_ExpenseSnapshots_CreatedAt",
table: "ExpenseSnapshots",
column: "CreatedAt");
migrationBuilder.CreateIndex(
name: "IX_ExpenseSnapshots_MinistryId",
table: "ExpenseSnapshots",
column: "MinistryId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ExpenseSnapshotLines");
migrationBuilder.DropTable(
name: "ExpenseSnapshots");
}
}
}
@@ -762,6 +762,128 @@ namespace ROLAC.API.Migrations
b.ToTable("ExpenseLines");
});
modelBuilder.Entity("ROLAC.API.Entities.ExpenseSnapshot", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("CheckNumber")
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("CreatedBy")
.IsRequired()
.HasMaxLength(450)
.HasColumnType("character varying(450)");
b.Property<DateTimeOffset?>("DeletedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("DeletedBy")
.HasMaxLength(450)
.HasColumnType("character varying(450)");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("character varying(500)");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<int>("MinistryId")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(150)
.HasColumnType("character varying(150)");
b.Property<string>("Notes")
.HasColumnType("text");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("UpdatedBy")
.IsRequired()
.HasMaxLength(450)
.HasColumnType("character varying(450)");
b.Property<string>("VendorName")
.HasMaxLength(200)
.HasColumnType("character varying(200)");
b.HasKey("Id");
b.HasIndex("CreatedAt");
b.HasIndex("MinistryId");
b.ToTable("ExpenseSnapshots");
});
modelBuilder.Entity("ROLAC.API.Entities.ExpenseSnapshotLine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<decimal>("Amount")
.HasColumnType("decimal(18,2)");
b.Property<int>("CategoryGroupId")
.HasColumnType("integer");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("CreatedBy")
.IsRequired()
.HasMaxLength(450)
.HasColumnType("character varying(450)");
b.Property<string>("Description")
.HasMaxLength(500)
.HasColumnType("character varying(500)");
b.Property<string>("FunctionalClass")
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<int>("SnapshotId")
.HasColumnType("integer");
b.Property<int>("SubCategoryId")
.HasColumnType("integer");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("UpdatedBy")
.IsRequired()
.HasMaxLength(450)
.HasColumnType("character varying(450)");
b.HasKey("Id");
b.HasIndex("CategoryGroupId");
b.HasIndex("SnapshotId");
b.HasIndex("SubCategoryId");
b.ToTable("ExpenseSnapshotLines");
});
modelBuilder.Entity("ROLAC.API.Entities.ExpenseSubCategory", b =>
{
b.Property<int>("Id")
@@ -2128,6 +2250,44 @@ namespace ROLAC.API.Migrations
b.Navigation("SubCategory");
});
modelBuilder.Entity("ROLAC.API.Entities.ExpenseSnapshot", b =>
{
b.HasOne("ROLAC.API.Entities.Ministry", "Ministry")
.WithMany()
.HasForeignKey("MinistryId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Ministry");
});
modelBuilder.Entity("ROLAC.API.Entities.ExpenseSnapshotLine", b =>
{
b.HasOne("ROLAC.API.Entities.ExpenseCategoryGroup", "CategoryGroup")
.WithMany()
.HasForeignKey("CategoryGroupId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("ROLAC.API.Entities.ExpenseSnapshot", "Snapshot")
.WithMany("Lines")
.HasForeignKey("SnapshotId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ROLAC.API.Entities.ExpenseSubCategory", "SubCategory")
.WithMany()
.HasForeignKey("SubCategoryId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("CategoryGroup");
b.Navigation("Snapshot");
b.Navigation("SubCategory");
});
modelBuilder.Entity("ROLAC.API.Entities.ExpenseSubCategory", b =>
{
b.HasOne("ROLAC.API.Entities.Form990ExpenseLine", "Form990Line")
@@ -2273,6 +2433,11 @@ namespace ROLAC.API.Migrations
b.Navigation("SubCategories");
});
modelBuilder.Entity("ROLAC.API.Entities.ExpenseSnapshot", b =>
{
b.Navigation("Lines");
});
modelBuilder.Entity("ROLAC.API.Entities.OfferingSession", b =>
{
b.Navigation("Givings");