using System; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace SPMS.Infrastructure.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AlterDatabase() .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Admin", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), AdminCode = table.Column(type: "varchar(8)", maxLength: 8, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Email = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Password = table.Column(type: "varchar(64)", maxLength: 64, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Phone = table.Column(type: "varchar(20)", maxLength: 20, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Name = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Role = table.Column(type: "tinyint", nullable: false), EmailVerified = table.Column(type: "tinyint(1)", nullable: false, defaultValue: false), EmailVerifiedAt = table.Column(type: "datetime(6)", nullable: true), CreatedAt = table.Column(type: "datetime(6)", nullable: false), LastLoginAt = table.Column(type: "datetime(6)", nullable: true), IsDeleted = table.Column(type: "tinyint(1)", nullable: false, defaultValue: false), DeletedAt = table.Column(type: "datetime(6)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Admin", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Service", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), ServiceCode = table.Column(type: "varchar(8)", maxLength: 8, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), ServiceName = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Description = table.Column(type: "varchar(500)", maxLength: 500, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), ApiKey = table.Column(type: "varchar(64)", maxLength: 64, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), ApiKeyCreatedAt = table.Column(type: "datetime(6)", nullable: false), ApnsBundleId = table.Column(type: "varchar(100)", maxLength: 100, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), ApnsKeyId = table.Column(type: "varchar(10)", maxLength: 10, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), ApnsTeamId = table.Column(type: "varchar(10)", maxLength: 10, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), ApnsPrivateKey = table.Column(type: "text", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), FcmCredentials = table.Column(type: "text", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), WebhookUrl = table.Column(type: "varchar(500)", maxLength: 500, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), Tags = table.Column(type: "json", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), SubTier = table.Column(type: "tinyint", nullable: false), SubStartedAt = table.Column(type: "datetime(6)", nullable: true), Status = table.Column(type: "tinyint", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), CreatedBy = table.Column(type: "bigint", nullable: false), UpdatedAt = table.Column(type: "datetime(6)", nullable: true), IsDeleted = table.Column(type: "tinyint(1)", nullable: false, defaultValue: false), DeletedAt = table.Column(type: "datetime(6)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Service", x => x.Id); table.ForeignKey( name: "FK_Service_Admin_CreatedBy", column: x => x.CreatedBy, principalTable: "Admin", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "DailyStat", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), ServiceId = table.Column(type: "bigint", nullable: false), StatDate = table.Column(type: "date", nullable: false), SentCnt = table.Column(type: "int", nullable: false, defaultValue: 0), SuccessCnt = table.Column(type: "int", nullable: false, defaultValue: 0), FailCnt = table.Column(type: "int", nullable: false, defaultValue: 0), OpenCnt = table.Column(type: "int", nullable: false, defaultValue: 0), CreatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DailyStat", x => x.Id); table.ForeignKey( name: "FK_DailyStat_Service_ServiceId", column: x => x.ServiceId, principalTable: "Service", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Device", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), ServiceId = table.Column(type: "bigint", nullable: false), DeviceToken = table.Column(type: "varchar(255)", maxLength: 255, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Platform = table.Column(type: "tinyint", nullable: false), AppVersion = table.Column(type: "varchar(20)", maxLength: 20, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), OsVersion = table.Column(type: "varchar(20)", maxLength: 20, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), DeviceModel = table.Column(type: "varchar(50)", maxLength: 50, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), Tags = table.Column(type: "json", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), PushAgreed = table.Column(type: "tinyint(1)", nullable: false), MarketingAgreed = table.Column(type: "tinyint(1)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false, defaultValue: true), CreatedAt = table.Column(type: "datetime(6)", nullable: false), UpdatedAt = table.Column(type: "datetime(6)", nullable: true), AgreeUpdatedAt = table.Column(type: "datetime(6)", nullable: true), MktAgreeUpdatedAt = table.Column(type: "datetime(6)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Device", x => x.Id); table.ForeignKey( name: "FK_Device_Service_ServiceId", column: x => x.ServiceId, principalTable: "Service", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "File", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), ServiceId = table.Column(type: "bigint", nullable: false), FileName = table.Column(type: "varchar(200)", maxLength: 200, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), FilePath = table.Column(type: "varchar(500)", maxLength: 500, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), FileSize = table.Column(type: "bigint", nullable: false), FileType = table.Column(type: "varchar(20)", maxLength: 20, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), MimeType = table.Column(type: "varchar(100)", maxLength: 100, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), CreatedAt = table.Column(type: "datetime(6)", nullable: false), CreatedBy = table.Column(type: "bigint", nullable: false) }, constraints: table => { table.PrimaryKey("PK_File", x => x.Id); table.ForeignKey( name: "FK_File_Admin_CreatedBy", column: x => x.CreatedBy, principalTable: "Admin", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_File_Service_ServiceId", column: x => x.ServiceId, principalTable: "Service", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Message", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), ServiceId = table.Column(type: "bigint", nullable: false), MessageCode = table.Column(type: "varchar(10)", maxLength: 10, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Title = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Body = table.Column(type: "varchar(500)", maxLength: 500, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), ImageUrl = table.Column(type: "varchar(500)", maxLength: 500, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), LinkUrl = table.Column(type: "varchar(500)", maxLength: 500, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), CustomData = table.Column(type: "json", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), CreatedAt = table.Column(type: "datetime(6)", nullable: false), CreatedBy = table.Column(type: "bigint", nullable: false), IsDeleted = table.Column(type: "tinyint(1)", nullable: false, defaultValue: false), DeletedAt = table.Column(type: "datetime(6)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Message", x => x.Id); table.ForeignKey( name: "FK_Message_Admin_CreatedBy", column: x => x.CreatedBy, principalTable: "Admin", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Message_Service_ServiceId", column: x => x.ServiceId, principalTable: "Service", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Payment", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), ServiceId = table.Column(type: "bigint", nullable: false), AdminId = table.Column(type: "bigint", nullable: false), Amount = table.Column(type: "int", nullable: false), Currency = table.Column(type: "varchar(10)", maxLength: 10, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), PaymentMethod = table.Column(type: "varchar(50)", maxLength: 50, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), PaymentKey = table.Column(type: "varchar(100)", maxLength: 100, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), Status = table.Column(type: "tinyint", nullable: false), TierBefore = table.Column(type: "tinyint", nullable: true), TierAfter = table.Column(type: "tinyint", nullable: false), PaidAt = table.Column(type: "datetime(6)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Payment", x => x.Id); table.ForeignKey( name: "FK_Payment_Admin_AdminId", column: x => x.AdminId, principalTable: "Admin", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Payment_Service_ServiceId", column: x => x.ServiceId, principalTable: "Service", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "ServiceIp", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), ServiceId = table.Column(type: "bigint", nullable: false), IpAddress = table.Column(type: "varchar(45)", maxLength: 45, nullable: false) .Annotation("MySql:CharSet", "utf8mb4") }, constraints: table => { table.PrimaryKey("PK_ServiceIp", x => x.Id); table.ForeignKey( name: "FK_ServiceIp_Service_ServiceId", column: x => x.ServiceId, principalTable: "Service", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "SystemLog", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), ServiceId = table.Column(type: "bigint", nullable: true), AdminId = table.Column(type: "bigint", nullable: true), Action = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), TargetType = table.Column(type: "varchar(50)", maxLength: 50, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), TargetId = table.Column(type: "bigint", nullable: true), Details = table.Column(type: "json", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), IpAddress = table.Column(type: "varchar(45)", maxLength: 45, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), CreatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_SystemLog", x => x.Id); table.ForeignKey( name: "FK_SystemLog_Admin_AdminId", column: x => x.AdminId, principalTable: "Admin", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_SystemLog_Service_ServiceId", column: x => x.ServiceId, principalTable: "Service", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "WebhookLog", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), ServiceId = table.Column(type: "bigint", nullable: false), WebhookUrl = table.Column(type: "varchar(500)", maxLength: 500, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), EventType = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Payload = table.Column(type: "json", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Status = table.Column(type: "tinyint", nullable: false), ResponseCode = table.Column(type: "int", nullable: true), ResponseBody = table.Column(type: "text", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), SentAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_WebhookLog", x => x.Id); table.ForeignKey( name: "FK_WebhookLog_Service_ServiceId", column: x => x.ServiceId, principalTable: "Service", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "PushOpenLog", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), ServiceId = table.Column(type: "bigint", nullable: false), MessageId = table.Column(type: "bigint", nullable: false), DeviceId = table.Column(type: "bigint", nullable: false), OpenedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PushOpenLog", x => x.Id); table.ForeignKey( name: "FK_PushOpenLog_Device_DeviceId", column: x => x.DeviceId, principalTable: "Device", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_PushOpenLog_Message_MessageId", column: x => x.MessageId, principalTable: "Message", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_PushOpenLog_Service_ServiceId", column: x => x.ServiceId, principalTable: "Service", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "PushSendLog", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), ServiceId = table.Column(type: "bigint", nullable: false), MessageId = table.Column(type: "bigint", nullable: false), DeviceId = table.Column(type: "bigint", nullable: false), Status = table.Column(type: "tinyint", nullable: false), FailReason = table.Column(type: "varchar(200)", maxLength: 200, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), SentAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PushSendLog", x => x.Id); table.ForeignKey( name: "FK_PushSendLog_Device_DeviceId", column: x => x.DeviceId, principalTable: "Device", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_PushSendLog_Message_MessageId", column: x => x.MessageId, principalTable: "Message", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_PushSendLog_Service_ServiceId", column: x => x.ServiceId, principalTable: "Service", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateIndex( name: "IX_Admin_AdminCode", table: "Admin", column: "AdminCode", unique: true); migrationBuilder.CreateIndex( name: "IX_Admin_Email", table: "Admin", column: "Email", unique: true); migrationBuilder.CreateIndex( name: "IX_DailyStat_ServiceId_StatDate", table: "DailyStat", columns: new[] { "ServiceId", "StatDate" }, unique: true); migrationBuilder.CreateIndex( name: "IX_Device_ServiceId_DeviceToken", table: "Device", columns: new[] { "ServiceId", "DeviceToken" }); migrationBuilder.CreateIndex( name: "IX_File_CreatedBy", table: "File", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_File_ServiceId", table: "File", column: "ServiceId"); migrationBuilder.CreateIndex( name: "IX_Message_CreatedBy", table: "Message", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_Message_MessageCode", table: "Message", column: "MessageCode", unique: true); migrationBuilder.CreateIndex( name: "IX_Message_ServiceId", table: "Message", column: "ServiceId"); migrationBuilder.CreateIndex( name: "IX_Payment_AdminId", table: "Payment", column: "AdminId"); migrationBuilder.CreateIndex( name: "IX_Payment_ServiceId", table: "Payment", column: "ServiceId"); migrationBuilder.CreateIndex( name: "IX_PushOpenLog_DeviceId", table: "PushOpenLog", column: "DeviceId"); migrationBuilder.CreateIndex( name: "IX_PushOpenLog_MessageId", table: "PushOpenLog", column: "MessageId"); migrationBuilder.CreateIndex( name: "IX_PushOpenLog_ServiceId_OpenedAt", table: "PushOpenLog", columns: new[] { "ServiceId", "OpenedAt" }); migrationBuilder.CreateIndex( name: "IX_PushSendLog_DeviceId", table: "PushSendLog", column: "DeviceId"); migrationBuilder.CreateIndex( name: "IX_PushSendLog_MessageId", table: "PushSendLog", column: "MessageId"); migrationBuilder.CreateIndex( name: "IX_PushSendLog_ServiceId_SentAt", table: "PushSendLog", columns: new[] { "ServiceId", "SentAt" }); migrationBuilder.CreateIndex( name: "IX_Service_CreatedBy", table: "Service", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_Service_ServiceCode", table: "Service", column: "ServiceCode", unique: true); migrationBuilder.CreateIndex( name: "IX_ServiceIp_ServiceId", table: "ServiceIp", column: "ServiceId"); migrationBuilder.CreateIndex( name: "IX_SystemLog_AdminId", table: "SystemLog", column: "AdminId"); migrationBuilder.CreateIndex( name: "IX_SystemLog_CreatedAt", table: "SystemLog", column: "CreatedAt"); migrationBuilder.CreateIndex( name: "IX_SystemLog_ServiceId", table: "SystemLog", column: "ServiceId"); migrationBuilder.CreateIndex( name: "IX_WebhookLog_ServiceId_SentAt", table: "WebhookLog", columns: new[] { "ServiceId", "SentAt" }); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "DailyStat"); migrationBuilder.DropTable( name: "File"); migrationBuilder.DropTable( name: "Payment"); migrationBuilder.DropTable( name: "PushOpenLog"); migrationBuilder.DropTable( name: "PushSendLog"); migrationBuilder.DropTable( name: "ServiceIp"); migrationBuilder.DropTable( name: "SystemLog"); migrationBuilder.DropTable( name: "WebhookLog"); migrationBuilder.DropTable( name: "Device"); migrationBuilder.DropTable( name: "Message"); migrationBuilder.DropTable( name: "Service"); migrationBuilder.DropTable( name: "Admin"); } } }