using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace ROLAC.API.Migrations { /// public partial class AddExpenseModule : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "ExpenseCategoryGroups", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name_en = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Name_zh = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), SortOrder = table.Column(type: "integer", nullable: false), IsActive = table.Column(type: "boolean", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), CreatedBy = table.Column(type: "character varying(450)", maxLength: 450, nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedBy = table.Column(type: "character varying(450)", maxLength: 450, nullable: false) }, constraints: table => { table.PrimaryKey("PK_ExpenseCategoryGroups", x => x.Id); }); migrationBuilder.CreateTable( name: "Ministries", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name_en = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Name_zh = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), Description_en = table.Column(type: "text", nullable: true), Description_zh = table.Column(type: "text", nullable: true), SortOrder = table.Column(type: "integer", nullable: false), IsActive = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Ministries", x => x.Id); }); migrationBuilder.CreateTable( name: "MonthlyStatements", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Year = table.Column(type: "integer", nullable: false), Month = table.Column(type: "integer", nullable: false), OpeningBalance = table.Column(type: "numeric(18,2)", nullable: false), TotalGiving = table.Column(type: "numeric(18,2)", nullable: false), TotalOtherIncome = table.Column(type: "numeric(18,2)", nullable: false), TotalExpenses = table.Column(type: "numeric(18,2)", nullable: false), CalculatedClosingBalance = table.Column(type: "numeric(18,2)", nullable: false), BankStatementBalance = table.Column(type: "numeric(18,2)", nullable: false), Difference = table.Column(type: "numeric(18,2)", nullable: false), Notes = table.Column(type: "text", nullable: true), IsFinalized = table.Column(type: "boolean", nullable: false), FinalizedAt = table.Column(type: "timestamp with time zone", nullable: true), FinalizedBy = table.Column(type: "character varying(450)", maxLength: 450, nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), CreatedBy = table.Column(type: "character varying(450)", maxLength: 450, nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedBy = table.Column(type: "character varying(450)", maxLength: 450, nullable: false) }, constraints: table => { table.PrimaryKey("PK_MonthlyStatements", x => x.Id); }); migrationBuilder.CreateTable( name: "ExpenseSubCategories", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), GroupId = table.Column(type: "integer", nullable: false), Name_en = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Name_zh = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), SortOrder = table.Column(type: "integer", nullable: false), IsActive = table.Column(type: "boolean", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), CreatedBy = table.Column(type: "character varying(450)", maxLength: 450, nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedBy = table.Column(type: "character varying(450)", maxLength: 450, nullable: false) }, constraints: table => { table.PrimaryKey("PK_ExpenseSubCategories", x => x.Id); table.ForeignKey( name: "FK_ExpenseSubCategories_ExpenseCategoryGroups_GroupId", column: x => x.GroupId, principalTable: "ExpenseCategoryGroups", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Expenses", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), MinistryId = table.Column(type: "integer", nullable: false), CategoryGroupId = table.Column(type: "integer", nullable: false), SubCategoryId = table.Column(type: "integer", nullable: false), Type = table.Column(type: "character varying(30)", maxLength: 30, nullable: false), Status = table.Column(type: "character varying(30)", maxLength: 30, nullable: false, defaultValue: "Draft"), Amount = table.Column(type: "numeric(18,2)", nullable: false), Description = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), VendorName = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), MemberId = table.Column(type: "integer", nullable: true), CheckNumber = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), ExpenseDate = table.Column(type: "date", nullable: false), ReceiptBlobPath = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), Notes = table.Column(type: "text", nullable: true), SubmittedBy = table.Column(type: "character varying(450)", maxLength: 450, nullable: true), SubmittedAt = table.Column(type: "timestamp with time zone", nullable: true), ReviewedBy = table.Column(type: "character varying(450)", maxLength: 450, nullable: true), ReviewedAt = table.Column(type: "timestamp with time zone", nullable: true), ReviewNotes = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), PaidAt = table.Column(type: "timestamp with time zone", nullable: true), PaidBy = table.Column(type: "character varying(450)", maxLength: 450, nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), CreatedBy = table.Column(type: "character varying(450)", maxLength: 450, nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedBy = table.Column(type: "character varying(450)", maxLength: 450, nullable: false), IsDeleted = table.Column(type: "boolean", nullable: false), DeletedAt = table.Column(type: "timestamp with time zone", nullable: true), DeletedBy = table.Column(type: "character varying(450)", maxLength: 450, nullable: true) }, constraints: table => { table.PrimaryKey("PK_Expenses", x => x.Id); table.ForeignKey( name: "FK_Expenses_ExpenseCategoryGroups_CategoryGroupId", column: x => x.CategoryGroupId, principalTable: "ExpenseCategoryGroups", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Expenses_ExpenseSubCategories_SubCategoryId", column: x => x.SubCategoryId, principalTable: "ExpenseSubCategories", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Expenses_Members_MemberId", column: x => x.MemberId, principalTable: "Members", principalColumn: "Id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "FK_Expenses_Ministries_MinistryId", column: x => x.MinistryId, principalTable: "Ministries", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( name: "IX_Expenses_CategoryGroupId", table: "Expenses", column: "CategoryGroupId"); migrationBuilder.CreateIndex( name: "IX_Expenses_ExpenseDate", table: "Expenses", column: "ExpenseDate"); migrationBuilder.CreateIndex( name: "IX_Expenses_MemberId", table: "Expenses", column: "MemberId"); migrationBuilder.CreateIndex( name: "IX_Expenses_MinistryId", table: "Expenses", column: "MinistryId"); migrationBuilder.CreateIndex( name: "IX_Expenses_Status", table: "Expenses", column: "Status", filter: "\"IsDeleted\" = false"); migrationBuilder.CreateIndex( name: "IX_Expenses_SubCategoryId", table: "Expenses", column: "SubCategoryId"); migrationBuilder.CreateIndex( name: "IX_ExpenseSubCategories_GroupId", table: "ExpenseSubCategories", column: "GroupId"); migrationBuilder.CreateIndex( name: "IX_MonthlyStatements_Year_Month", table: "MonthlyStatements", columns: new[] { "Year", "Month" }, unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Expenses"); migrationBuilder.DropTable( name: "MonthlyStatements"); migrationBuilder.DropTable( name: "ExpenseSubCategories"); migrationBuilder.DropTable( name: "Ministries"); migrationBuilder.DropTable( name: "ExpenseCategoryGroups"); } } }