using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace ROLAC.API.Migrations { /// public partial class AddGivingModule : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "GivingCategories", 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: "character varying(500)", maxLength: 500, nullable: true), Description_zh = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), IsActive = table.Column(type: "boolean", nullable: false), SortOrder = table.Column(type: "integer", 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_GivingCategories", x => x.Id); }); migrationBuilder.CreateTable( name: "OfferingSessions", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), SessionDate = table.Column(type: "date", nullable: false), Status = table.Column(type: "character varying(20)", maxLength: 20, nullable: false, defaultValue: "Draft"), CashTotal = table.Column(type: "numeric(18,2)", nullable: false), CheckTotal = table.Column(type: "numeric(18,2)", nullable: false), SystemTotal = table.Column(type: "numeric(18,2)", nullable: false), Difference = table.Column(type: "numeric(18,2)", nullable: false), Notes = table.Column(type: "text", nullable: true), SubmittedAt = table.Column(type: "timestamp with time zone", nullable: true), SubmittedBy = table.Column(type: "character varying(450)", maxLength: 450, nullable: true), ReconciledAt = table.Column(type: "timestamp with time zone", nullable: true), ReconciledBy = 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_OfferingSessions", x => x.Id); }); migrationBuilder.CreateTable( name: "Givings", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), MemberId = table.Column(type: "integer", nullable: true), GivingCategoryId = table.Column(type: "integer", nullable: false), OfferingSessionId = table.Column(type: "integer", nullable: true), Amount = table.Column(type: "numeric(18,2)", nullable: false), PaymentMethod = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), CheckNumber = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), ZelleReferenceCode = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), PayPalTransactionId = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), GivingDate = table.Column(type: "date", nullable: false), IsAnonymous = table.Column(type: "boolean", nullable: false), Notes = table.Column(type: "character varying(500)", maxLength: 500, 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_Givings", x => x.Id); table.ForeignKey( name: "FK_Givings_GivingCategories_GivingCategoryId", column: x => x.GivingCategoryId, principalTable: "GivingCategories", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Givings_Members_MemberId", column: x => x.MemberId, principalTable: "Members", principalColumn: "Id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "FK_Givings_OfferingSessions_OfferingSessionId", column: x => x.OfferingSessionId, principalTable: "OfferingSessions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Givings_GivingCategoryId", table: "Givings", column: "GivingCategoryId"); migrationBuilder.CreateIndex( name: "IX_Givings_GivingDate", table: "Givings", column: "GivingDate"); migrationBuilder.CreateIndex( name: "IX_Givings_MemberId_GivingDate", table: "Givings", columns: new[] { "MemberId", "GivingDate" }); migrationBuilder.CreateIndex( name: "IX_Givings_OfferingSessionId", table: "Givings", column: "OfferingSessionId", filter: "\"OfferingSessionId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_OfferingSessions_SessionDate", table: "OfferingSessions", column: "SessionDate", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Givings"); migrationBuilder.DropTable( name: "GivingCategories"); migrationBuilder.DropTable( name: "OfferingSessions"); } } }