using System; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using TakeoutSaaS.Infrastructure.App.Persistence; #nullable disable namespace TakeoutSaaS.Infrastructure.Migrations; /// /// 新增财务中心发票管理表结构。 /// [DbContext(typeof(TakeoutAppDbContext))] [Migration("20260305103000_AddFinanceInvoiceModule")] public sealed class AddFinanceInvoiceModule : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "finance_invoice_records", columns: table => new { Id = table.Column(type: "bigint", nullable: false, comment: "实体唯一标识。") .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), InvoiceNo = table.Column(type: "character varying(32)", maxLength: 32, nullable: false, comment: "发票号码。"), ApplicantName = table.Column(type: "character varying(64)", maxLength: 64, nullable: false, comment: "申请人。"), CompanyName = table.Column(type: "character varying(128)", maxLength: 128, nullable: false, comment: "开票抬头(公司名)。"), TaxpayerNumber = table.Column(type: "character varying(64)", maxLength: 64, nullable: true, comment: "纳税人识别号快照。"), InvoiceType = table.Column(type: "integer", nullable: false, comment: "发票类型。"), Amount = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false, comment: "开票金额。"), OrderNo = table.Column(type: "character varying(32)", maxLength: 32, nullable: false, comment: "关联订单号。"), ContactEmail = table.Column(type: "character varying(128)", maxLength: 128, nullable: true, comment: "接收邮箱。"), ContactPhone = table.Column(type: "character varying(32)", maxLength: 32, nullable: true, comment: "联系电话。"), ApplyRemark = table.Column(type: "character varying(256)", maxLength: 256, nullable: true, comment: "申请备注。"), Status = table.Column(type: "integer", nullable: false, comment: "发票状态。"), AppliedAt = table.Column(type: "timestamp with time zone", nullable: false, comment: "申请时间(UTC)。"), IssuedAt = table.Column(type: "timestamp with time zone", nullable: true, comment: "开票时间(UTC)。"), IssuedByUserId = table.Column(type: "bigint", nullable: true, comment: "开票人 ID。"), IssueRemark = table.Column(type: "character varying(256)", maxLength: 256, nullable: true, comment: "开票备注。"), VoidedAt = table.Column(type: "timestamp with time zone", nullable: true, comment: "作废时间(UTC)。"), VoidedByUserId = table.Column(type: "bigint", nullable: true, comment: "作废人 ID。"), VoidReason = table.Column(type: "character varying(256)", maxLength: 256, nullable: true, comment: "作废原因。"), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, comment: "创建时间(UTC)。"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true, comment: "最近一次更新时间(UTC),从未更新时为 null。"), DeletedAt = table.Column(type: "timestamp with time zone", nullable: true, comment: "软删除时间(UTC),未删除时为 null。"), CreatedBy = table.Column(type: "bigint", nullable: true, comment: "创建人用户标识,匿名或系统操作时为 null。"), UpdatedBy = table.Column(type: "bigint", nullable: true, comment: "最后更新人用户标识,匿名或系统操作时为 null。"), DeletedBy = table.Column(type: "bigint", nullable: true, comment: "删除人用户标识(软删除),未删除时为 null。"), TenantId = table.Column(type: "bigint", nullable: false, comment: "所属租户 ID。") }, constraints: table => { table.PrimaryKey("PK_finance_invoice_records", x => x.Id); }, comment: "租户发票记录。"); migrationBuilder.CreateTable( name: "finance_invoice_settings", columns: table => new { Id = table.Column(type: "bigint", nullable: false, comment: "实体唯一标识。") .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), CompanyName = table.Column(type: "character varying(128)", maxLength: 128, nullable: false, comment: "企业名称。"), TaxpayerNumber = table.Column(type: "character varying(64)", maxLength: 64, nullable: false, comment: "纳税人识别号。"), RegisteredAddress = table.Column(type: "character varying(256)", maxLength: 256, nullable: true, comment: "注册地址。"), RegisteredPhone = table.Column(type: "character varying(32)", maxLength: 32, nullable: true, comment: "注册电话。"), BankName = table.Column(type: "character varying(128)", maxLength: 128, nullable: true, comment: "开户银行。"), BankAccount = table.Column(type: "character varying(64)", maxLength: 64, nullable: true, comment: "银行账号。"), EnableElectronicNormalInvoice = table.Column(type: "boolean", nullable: false, comment: "是否启用电子普通发票。"), EnableElectronicSpecialInvoice = table.Column(type: "boolean", nullable: false, comment: "是否启用电子专用发票。"), EnableAutoIssue = table.Column(type: "boolean", nullable: false, comment: "是否启用自动开票。"), AutoIssueMaxAmount = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false, comment: "自动开票单张最大金额。"), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, comment: "创建时间(UTC)。"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true, comment: "最近一次更新时间(UTC),从未更新时为 null。"), DeletedAt = table.Column(type: "timestamp with time zone", nullable: true, comment: "软删除时间(UTC),未删除时为 null。"), CreatedBy = table.Column(type: "bigint", nullable: true, comment: "创建人用户标识,匿名或系统操作时为 null。"), UpdatedBy = table.Column(type: "bigint", nullable: true, comment: "最后更新人用户标识,匿名或系统操作时为 null。"), DeletedBy = table.Column(type: "bigint", nullable: true, comment: "删除人用户标识(软删除),未删除时为 null。"), TenantId = table.Column(type: "bigint", nullable: false, comment: "所属租户 ID。") }, constraints: table => { table.PrimaryKey("PK_finance_invoice_settings", x => x.Id); }, comment: "租户发票开票基础设置。"); migrationBuilder.CreateIndex( name: "IX_finance_invoice_records_TenantId_InvoiceNo", table: "finance_invoice_records", columns: new[] { "TenantId", "InvoiceNo" }, unique: true); migrationBuilder.CreateIndex( name: "IX_finance_invoice_records_TenantId_InvoiceType_AppliedAt", table: "finance_invoice_records", columns: new[] { "TenantId", "InvoiceType", "AppliedAt" }); migrationBuilder.CreateIndex( name: "IX_finance_invoice_records_TenantId_OrderNo", table: "finance_invoice_records", columns: new[] { "TenantId", "OrderNo" }); migrationBuilder.CreateIndex( name: "IX_finance_invoice_records_TenantId_Status_AppliedAt", table: "finance_invoice_records", columns: new[] { "TenantId", "Status", "AppliedAt" }); migrationBuilder.CreateIndex( name: "IX_finance_invoice_records_TenantId_Status_IssuedAt", table: "finance_invoice_records", columns: new[] { "TenantId", "Status", "IssuedAt" }); migrationBuilder.CreateIndex( name: "IX_finance_invoice_settings_TenantId", table: "finance_invoice_settings", column: "TenantId", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "finance_invoice_records"); migrationBuilder.DropTable( name: "finance_invoice_settings"); } }