Sms & Email

This commit is contained in:
2026-10-20 10:45:03 +05:30
parent a40e463e8b
commit 0e423b806c
29 changed files with 13845 additions and 26 deletions
@@ -17,8 +17,8 @@ namespace ERPCore.Migrations
/// <remarks>
/// Written by hand rather than scaffolded, and the drop/add is emitted as raw SQL instead of
/// <c>DropCheckConstraint</c>: MariaDB spells the removal <c>DROP CONSTRAINT</c> (MySQL's
/// <c>DROP CHECK</c> is not a safe assumption here), and <c>IF EXISTS</c> keeps this
/// re-runnable on a database where the broken constraint was already removed by hand.
/// <c>DROP CHECK</c> is not a safe assumption here). It is a plain drop, not <c>IF EXISTS</c>:
/// that form is MariaDB-only and a syntax error on MySQL 8, which broke fresh local databases.
/// </remarks>
/// <inheritdoc />
public partial class FixCheckConstraintQuotingForMySql : Migration
@@ -26,13 +26,13 @@ namespace ERPCore.Migrations
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("ALTER TABLE `grn_config` DROP CONSTRAINT IF EXISTS `ck_grn_config_singleton`;");
DropCheck(migrationBuilder, "grn_config", "ck_grn_config_singleton");
migrationBuilder.Sql("ALTER TABLE `grn_config` ADD CONSTRAINT `ck_grn_config_singleton` CHECK (`ConfigId` = 1);");
migrationBuilder.Sql("ALTER TABLE `sales_config` DROP CONSTRAINT IF EXISTS `ck_sales_config_singleton`;");
DropCheck(migrationBuilder, "sales_config", "ck_sales_config_singleton");
migrationBuilder.Sql("ALTER TABLE `sales_config` ADD CONSTRAINT `ck_sales_config_singleton` CHECK (`ConfigId` = 1);");
migrationBuilder.Sql("ALTER TABLE `warranty_periods` DROP CONSTRAINT IF EXISTS `ck_warranty_periods_months`;");
DropCheck(migrationBuilder, "warranty_periods", "ck_warranty_periods_months");
migrationBuilder.Sql("ALTER TABLE `warranty_periods` ADD CONSTRAINT `ck_warranty_periods_months` CHECK (`Months` BETWEEN 1 AND 600);");
}
@@ -40,14 +40,23 @@ namespace ERPCore.Migrations
protected override void Down(MigrationBuilder migrationBuilder)
{
// Restores the original (broken) expressions so the migration is a faithful inverse.
migrationBuilder.Sql("ALTER TABLE `grn_config` DROP CONSTRAINT IF EXISTS `ck_grn_config_singleton`;");
DropCheck(migrationBuilder, "grn_config", "ck_grn_config_singleton");
migrationBuilder.Sql("ALTER TABLE `grn_config` ADD CONSTRAINT `ck_grn_config_singleton` CHECK (\"ConfigId\" = 1);");
migrationBuilder.Sql("ALTER TABLE `sales_config` DROP CONSTRAINT IF EXISTS `ck_sales_config_singleton`;");
DropCheck(migrationBuilder, "sales_config", "ck_sales_config_singleton");
migrationBuilder.Sql("ALTER TABLE `sales_config` ADD CONSTRAINT `ck_sales_config_singleton` CHECK (\"ConfigId\" = 1);");
migrationBuilder.Sql("ALTER TABLE `warranty_periods` DROP CONSTRAINT IF EXISTS `ck_warranty_periods_months`;");
DropCheck(migrationBuilder, "warranty_periods", "ck_warranty_periods_months");
migrationBuilder.Sql("ALTER TABLE `warranty_periods` ADD CONSTRAINT `ck_warranty_periods_months` CHECK (\"Months\" BETWEEN 1 AND 600);");
}
/// <summary>
/// Plain <c>DROP CONSTRAINT</c> — valid on MariaDB and on MySQL 8.0.19+. Deliberately not
/// <c>DROP CONSTRAINT IF EXISTS</c>, which is MariaDB-only and is a syntax error on MySQL 8,
/// breaking fresh local databases. The constraints always exist at this point: the earlier
/// migrations create them.
/// </summary>
private static void DropCheck(MigrationBuilder migrationBuilder, string table, string constraint)
=> migrationBuilder.Sql($"ALTER TABLE `{table}` DROP CONSTRAINT `{constraint}`;");
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,131 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ERPCore.Migrations
{
/// <inheritdoc />
public partial class AddOwnerReport : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "owner_report_config",
columns: table => new
{
ConfigId = table.Column<int>(type: "int", nullable: false),
Enabled = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false),
SmsEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: true),
EmailEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: true),
SendAtLocalTime = table.Column<TimeOnly>(type: "time(6)", nullable: false),
IncludeBranchBreakdown = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: true),
UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
UpdatedBy = table.Column<int>(type: "int", nullable: true),
RowVersion = table.Column<uint>(type: "int unsigned", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_owner_report_config", x => x.ConfigId);
table.CheckConstraint("ck_owner_report_config_singleton", "`ConfigId` = 1");
table.ForeignKey(
name: "FK_owner_report_config_users_UpdatedBy",
column: x => x.UpdatedBy,
principalTable: "users",
principalColumn: "UserId",
onDelete: ReferentialAction.Restrict);
})
.Annotation("Relational:Collation", "utf8mb4_unicode_ci");
migrationBuilder.CreateTable(
name: "owner_report_recipients",
columns: table => new
{
RecipientId = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, collation: "utf8mb4_unicode_ci"),
Mobile = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true, collation: "utf8mb4_unicode_ci"),
Email = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true, collation: "utf8mb4_unicode_ci"),
IsActive = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: true)
},
constraints: table =>
{
table.PrimaryKey("PK_owner_report_recipients", x => x.RecipientId);
})
.Annotation("Relational:Collation", "utf8mb4_unicode_ci");
migrationBuilder.CreateTable(
name: "owner_report_dispatches",
columns: table => new
{
DispatchId = table.Column<long>(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
BusinessDate = table.Column<DateOnly>(type: "date", nullable: false),
Channel = table.Column<string>(type: "varchar(10)", maxLength: 10, nullable: false, collation: "utf8mb4_unicode_ci"),
RecipientId = table.Column<int>(type: "int", nullable: true),
Destination = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, collation: "utf8mb4_unicode_ci"),
RecipientName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, collation: "utf8mb4_unicode_ci"),
Status = table.Column<string>(type: "varchar(10)", maxLength: 10, nullable: false, collation: "utf8mb4_unicode_ci"),
Attempts = table.Column<int>(type: "int", nullable: false),
Error = table.Column<string>(type: "varchar(1000)", maxLength: 1000, nullable: true, collation: "utf8mb4_unicode_ci"),
IsTest = table.Column<bool>(type: "tinyint(1)", nullable: false),
DedupeKey = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false, collation: "utf8mb4_unicode_ci"),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
SentAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
NextAttemptAt = table.Column<DateTime>(type: "datetime(6)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_owner_report_dispatches", x => x.DispatchId);
table.ForeignKey(
name: "FK_owner_report_dispatches_owner_report_recipients_RecipientId",
column: x => x.RecipientId,
principalTable: "owner_report_recipients",
principalColumn: "RecipientId",
onDelete: ReferentialAction.SetNull);
})
.Annotation("Relational:Collation", "utf8mb4_unicode_ci");
migrationBuilder.CreateIndex(
name: "IX_owner_report_config_UpdatedBy",
table: "owner_report_config",
column: "UpdatedBy");
migrationBuilder.CreateIndex(
name: "IX_owner_report_dispatches_CreatedAt",
table: "owner_report_dispatches",
column: "CreatedAt");
migrationBuilder.CreateIndex(
name: "IX_owner_report_dispatches_RecipientId",
table: "owner_report_dispatches",
column: "RecipientId");
migrationBuilder.CreateIndex(
name: "IX_owner_report_dispatches_Status_NextAttemptAt",
table: "owner_report_dispatches",
columns: new[] { "Status", "NextAttemptAt" });
migrationBuilder.CreateIndex(
name: "ux_owner_report_dispatch_once",
table: "owner_report_dispatches",
columns: new[] { "BusinessDate", "Channel", "RecipientId", "IsTest", "DedupeKey" },
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "owner_report_config");
migrationBuilder.DropTable(
name: "owner_report_dispatches");
migrationBuilder.DropTable(
name: "owner_report_recipients");
}
}
}
@@ -3733,6 +3733,158 @@ namespace ERPCore.Migrations
b.ToTable("opening_stock_lines", (string)null);
});
modelBuilder.Entity("ERPCore.Domain.Entities.OwnerReportConfig", b =>
{
b.Property<int>("ConfigId")
.HasColumnType("int");
b.Property<bool>("EmailEnabled")
.ValueGeneratedOnAdd()
.HasColumnType("tinyint(1)")
.HasDefaultValue(true);
b.Property<bool>("Enabled")
.ValueGeneratedOnAdd()
.HasColumnType("tinyint(1)")
.HasDefaultValue(false);
b.Property<bool>("IncludeBranchBreakdown")
.ValueGeneratedOnAdd()
.HasColumnType("tinyint(1)")
.HasDefaultValue(true);
b.Property<uint>("RowVersion")
.IsConcurrencyToken()
.HasColumnType("int unsigned");
b.Property<TimeOnly>("SendAtLocalTime")
.HasColumnType("time(6)");
b.Property<bool>("SmsEnabled")
.ValueGeneratedOnAdd()
.HasColumnType("tinyint(1)")
.HasDefaultValue(true);
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("datetime(6)");
b.Property<int?>("UpdatedBy")
.HasColumnType("int");
b.HasKey("ConfigId");
b.HasIndex("UpdatedBy");
b.ToTable("owner_report_config", null, t =>
{
t.HasCheckConstraint("ck_owner_report_config_singleton", "`ConfigId` = 1");
});
});
modelBuilder.Entity("ERPCore.Domain.Entities.OwnerReportDispatch", b =>
{
b.Property<long>("DispatchId")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<long>("DispatchId"));
b.Property<int>("Attempts")
.HasColumnType("int");
b.Property<DateOnly>("BusinessDate")
.HasColumnType("date");
b.Property<string>("Channel")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("varchar(10)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<string>("DedupeKey")
.IsRequired()
.HasMaxLength(40)
.HasColumnType("varchar(40)");
b.Property<string>("Destination")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("varchar(200)");
b.Property<string>("Error")
.HasMaxLength(1000)
.HasColumnType("varchar(1000)");
b.Property<bool>("IsTest")
.HasColumnType("tinyint(1)");
b.Property<DateTime?>("NextAttemptAt")
.HasColumnType("datetime(6)");
b.Property<int?>("RecipientId")
.HasColumnType("int");
b.Property<string>("RecipientName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)");
b.Property<DateTime?>("SentAt")
.HasColumnType("datetime(6)");
b.Property<string>("Status")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("varchar(10)");
b.HasKey("DispatchId");
b.HasIndex("CreatedAt");
b.HasIndex("RecipientId");
b.HasIndex("Status", "NextAttemptAt");
b.HasIndex("BusinessDate", "Channel", "RecipientId", "IsTest", "DedupeKey")
.IsUnique()
.HasDatabaseName("ux_owner_report_dispatch_once");
b.ToTable("owner_report_dispatches", (string)null);
});
modelBuilder.Entity("ERPCore.Domain.Entities.OwnerReportRecipient", b =>
{
b.Property<int>("RecipientId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("RecipientId"));
b.Property<string>("Email")
.HasMaxLength(200)
.HasColumnType("varchar(200)");
b.Property<bool>("IsActive")
.ValueGeneratedOnAdd()
.HasColumnType("tinyint(1)")
.HasDefaultValue(true);
b.Property<string>("Mobile")
.HasMaxLength(20)
.HasColumnType("varchar(20)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)");
b.HasKey("RecipientId");
b.ToTable("owner_report_recipients", (string)null);
});
modelBuilder.Entity("ERPCore.Domain.Entities.PayrollLine", b =>
{
b.Property<int>("PayrollLineId")
@@ -9631,6 +9783,26 @@ namespace ERPCore.Migrations
b.Navigation("Warehouse");
});
modelBuilder.Entity("ERPCore.Domain.Entities.OwnerReportConfig", b =>
{
b.HasOne("ERPCore.Domain.Entities.User", "UpdatedByUser")
.WithMany()
.HasForeignKey("UpdatedBy")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("UpdatedByUser");
});
modelBuilder.Entity("ERPCore.Domain.Entities.OwnerReportDispatch", b =>
{
b.HasOne("ERPCore.Domain.Entities.OwnerReportRecipient", "Recipient")
.WithMany()
.HasForeignKey("RecipientId")
.OnDelete(DeleteBehavior.SetNull);
b.Navigation("Recipient");
});
modelBuilder.Entity("ERPCore.Domain.Entities.PayrollLine", b =>
{
b.HasOne("ERPCore.Domain.Entities.Employee", "Employee")