using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Metadata; namespace Haoliang.Data.Migrations { public partial class InitialCreate : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Alarms", columns: table => new { AlarmId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), DeviceId = table.Column(type: "int", nullable: true), DeviceCode = table.Column(type: "varchar(100)", nullable: true), AlarmType = table.Column(type: "varchar(50)", nullable: false), AlarmSeverity = table.Column(type: "int", nullable: false), Title = table.Column(type: "varchar(255)", nullable: false), Description = table.Column(type: "text", nullable: true), AlarmStatus = table.Column(type: "int", nullable: false), CreateTime = table.Column(type: "datetime", nullable: false), AcknowledgedTime = table.Column(type: "datetime", nullable: true), ResolvedTime = table.Column(type: "datetime", nullable: true), AcknowledgeNote = table.Column(type: "text", nullable: true), ResolutionNote = table.Column(type: "text", nullable: true), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Alarms", x => x.AlarmId); }); migrationBuilder.CreateTable( name: "AlarmNotifications", columns: table => new { NotificationId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), AlarmId = table.Column(type: "int", nullable: false), NotificationType = table.Column(type: "int", nullable: false), Recipient = table.Column(type: "varchar(255)", nullable: false), Message = table.Column(type: "text", nullable: false), Status = table.Column(type: "int", nullable: false), SendTime = table.Column(type: "datetime", nullable: false), ErrorMessage = table.Column(type: "text", nullable: true), RetryTime = table.Column(type: "datetime", nullable: true), RetryCount = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AlarmNotifications", x => x.NotificationId); table.ForeignKey( name: "FK_AlarmNotifications_Alarms", column: x => x.AlarmId, principalTable: "Alarms", principalColumn: "AlarmId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "AlarmRules", columns: table => new { RuleId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), RuleName = table.Column(type: "varchar(100)", nullable: false), DeviceId = table.Column(type: "int", nullable: true), AlarmType = table.Column(type: "varchar(50)", nullable: false), Condition = table.Column(type: "text", nullable: false), Threshold = table.Column(type: "varchar(100)", nullable: true), IsActive = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false), UpdatedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_AlarmRules", x => x.RuleId); }); migrationBuilder.CreateTable( name: "CollectionConfigs", columns: table => new { ConfigId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), DeviceId = table.Column(type: "int", nullable: false), CollectionInterval = table.Column(type: "int", nullable: false), TimeoutSeconds = table.Column(type: "int", nullable: false), RetryAttempts = table.Column(type: "int", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false), UpdatedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_CollectionConfigs", x => x.ConfigId); }); migrationBuilder.CreateTable( name: "CollectionLogs", columns: table => new { LogId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), DeviceId = table.Column(type: "int", nullable: false), LogLevel = table.Column(type: "int", nullable: false), LogCategory = table.Column(type: "varchar(50)", nullable: false), LogMessage = table.Column(type: "text", nullable: false), LogData = table.Column(type: "text", nullable: true), LogTime = table.Column(type: "datetime", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false) }, constraints: table => { table.PrimaryKey("PK_CollectionLogs", x => x.LogId); }); migrationBuilder.CreateTable( name: "CollectionResults", columns: table => new { ResultId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), DeviceId = table.Column(type: "int", nullable: false), IsSuccess = table.Column(type: "tinyint(1)", nullable: false), RawData = table.Column(type: "text", nullable: true), ParsedData = table.Column(type: "text", nullable: true), CollectionTime = table.Column(type: "datetime", nullable: false), ResponseTimeMs = table.Column(type: "int", nullable: true), DataSize = table.Column(type: "int", nullable: true), ErrorMessage = table.Column(type: "text", nullable: true), CreatedAt = table.Column(type: "datetime", nullable: false) }, constraints: table => { table.PrimaryKey("PK_CollectionResults", x => x.ResultId); }); migrationBuilder.CreateTable( name: "CollectionTasks", columns: table => new { TaskId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), DeviceId = table.Column(type: "int", nullable: false), TaskName = table.Column(type: "varchar(100)", nullable: false), Status = table.Column(type: "varchar(20)", nullable: false), ScheduledTime = table.Column(type: "datetime", nullable: false), StartTime = table.Column(type: "datetime", nullable: true), EndTime = table.Column(type: "datetime", nullable: true), IsSuccess = table.Column(type: "tinyint(1)", nullable: false), ErrorMessage = table.Column(type: "text", nullable: true), RetryCount = table.Column(type: "int", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false) }, constraints: table => { table.PrimaryKey("PK_CollectionTasks", x => x.TaskId); }); migrationBuilder.CreateTable( name: "CNCDevices", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), DeviceCode = table.Column(type: "varchar(50)", nullable: false), DeviceName = table.Column(type: "varchar(100)", nullable: false), IPAddress = table.Column(type: "varchar(15)", nullable: false), HttpUrl = table.Column(type: "varchar(255)", nullable: false), CollectionInterval = table.Column(type: "int", nullable: false), TemplateId = table.Column(type: "int", nullable: false), IsAvailable = table.Column(type: "tinyint(1)", nullable: false), IsOnline = table.Column(type: "tinyint(1)", nullable: false), LastCollectionTime = table.Column(type: "datetime", nullable: true), CreatedAt = table.Column(type: "datetime", nullable: false), UpdatedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_CNCDevices", x => x.Id); }); migrationBuilder.CreateTable( name: "CNCTemplates", columns: table => new { TemplateId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), TemplateName = table.Column(type: "varchar(100)", nullable: false), BrandName = table.Column(type: "varchar(50)", nullable: false), Version = table.Column(type: "varchar(20)", nullable: false), Description = table.Column(type: "text", nullable: true), TagsJson = table.Column(type: "text", nullable: true), DataProcessingRulesJson = table.Column(type: "text", nullable: true), IsActive = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false), UpdatedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_CNCTemplates", x => x.TemplateId); }); migrationBuilder.CreateTable( name: "DeviceAssignments", columns: table => new { AssignmentId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), DeviceId = table.Column(type: "int", nullable: false), EmployeeId = table.Column(type: "int", nullable: false), AssignmentDate = table.Column(type: "datetime", nullable: false), AssignmentType = table.Column(type: "varchar(20)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false), UpdatedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_DeviceAssignments", x => x.AssignmentId); }); migrationBuilder.CreateTable( name: "DeviceStatus", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), DeviceId = table.Column(type: "int", nullable: false), Status = table.Column(type: "varchar(20)", nullable: false), IsRunning = table.Column(type: "tinyint(1)", nullable: false), NCProgram = table.Column(type: "varchar(100)", nullable: true), CumulativeCount = table.Column(type: "int", nullable: false), OperatingMode = table.Column(type: "varchar(20)", nullable: true), RecordTime = table.Column(type: "datetime", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DeviceStatus", x => x.Id); }); migrationBuilder.CreateTable( name: "Employees", columns: table => new { EmployeeId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), FirstName = table.Column(type: "varchar(50)", nullable: false), LastName = table.Column(type: "varchar(50)", nullable: false), Department = table.Column(type: "varchar(50)", nullable: false), Position = table.Column(type: "varchar(50)", nullable: true), HireDate = table.Column(type: "datetime", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false), UpdatedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Employees", x => x.EmployeeId); }); migrationBuilder.CreateTable( name: "LogEntries", columns: table => new { LogId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), LogLevel = table.Column(type: "int", nullable: false), Category = table.Column(type: "varchar(50)", nullable: false), Message = table.Column(type: "text", nullable: false), ExceptionMessage = table.Column(type: "text", nullable: true), StackTrace = table.Column(type: "text", nullable: true), Properties = table.Column(type: "json", nullable: true), Timestamp = table.Column(type: "datetime", nullable: false) }, constraints: table => { table.PrimaryKey("PK_LogEntries", x => x.LogId); }); migrationBuilder.CreateTable( name: "PasswordResets", columns: table => new { ResetId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), UserId = table.Column(type: "int", nullable: false), Token = table.Column(type: "varchar(255)", nullable: false), ExpiresAt = table.Column(type: "datetime", nullable: false), IsUsed = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PasswordResets", x => x.ResetId); table.ForeignKey( name: "FK_PasswordResets_Users", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Permissions", columns: table => new { PermissionId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), PermissionName = table.Column(type: "varchar(100)", nullable: false), Description = table.Column(type: "text", nullable: true), Category = table.Column(type: "varchar(50)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Permissions", x => x.PermissionId); }); migrationBuilder.CreateTable( name: "ProductionRecords", columns: table => new { RecordId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), DeviceId = table.Column(type: "int", nullable: false), DeviceName = table.Column(type: "varchar(100)", nullable: false), ProgramName = table.Column(type: "varchar(100)", nullable: false), Quantity = table.Column(type: "int", nullable: false), ProductionDate = table.Column(type: "datetime", nullable: false), ProductionTime = table.Column(type: "time", nullable: false), IsCompleted = table.Column(type: "tinyint(1)", nullable: false), Operator = table.Column(type: "varchar(50)", nullable: true), CreatedAt = table.Column(type: "datetime", nullable: false), UpdatedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_ProductionRecords", x => x.RecordId); }); migrationBuilder.CreateTable( name: "ProgramProductionSummaries", columns: table => new { SummaryId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), DeviceId = table.Column(type: "int", nullable: false), DeviceName = table.Column(type: "varchar(100)", nullable: false), ProgramName = table.Column(type: "varchar(100)", nullable: false), Quantity = table.Column(type: "int", nullable: false), ProductionDate = table.Column(type: "date", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false), UpdatedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_ProgramProductionSummaries", x => x.SummaryId); }); migrationBuilder.CreateTable( name: "ProductionSummaries", columns: table => new { SummaryId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), ProductionDate = table.Column(type: "date", nullable: false), DeviceId = table.Column(type: "int", nullable: false), DeviceName = table.Column(type: "varchar(100)", nullable: false), TotalQuantity = table.Column(type: "int", nullable: false), ProgramCount = table.Column(type: "int", nullable: false), TotalProductionTime = table.Column(type: "time", nullable: true), QualityRate = table.Column(type: "decimal(5,2)", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false), UpdatedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_ProductionSummaries", x => x.SummaryId); }); migrationBuilder.CreateTable( name: "Roles", columns: table => new { RoleId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), RoleName = table.Column(type: "varchar(50)", nullable: false), Description = table.Column(type: "text", nullable: true), IsActive = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false), UpdatedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Roles", x => x.RoleId); }); migrationBuilder.CreateTable( name: "ScheduledTasks", columns: table => new { TaskId = table.Column(type: "varchar(50)", nullable: false), TaskName = table.Column(type: "varchar(100)", nullable: false), CronExpression = table.Column(type: "varchar(100)", nullable: false), Description = table.Column(type: "text", nullable: true), TaskStatus = table.Column(type: "int", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false), LastRunAt = table.Column(type: "datetime", nullable: true), NextRunTime = table.Column(type: "datetime", nullable: true), CreatedAt = table.Column(type: "datetime", nullable: false), CompletedAt = table.Column(type: "datetime", nullable: true), ErrorMessage = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_ScheduledTasks", x => x.TaskId); }); migrationBuilder.CreateTable( name: "StatisticResults", columns: table => new { ResultId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), RuleId = table.Column(type: "int", nullable: false), ResultDate = table.Column(type: "datetime", nullable: false), ResultValue = table.Column(type: "decimal(18,4)", nullable: false), ResultData = table.Column(type: "json", nullable: true), CreatedAt = table.Column(type: "datetime", nullable: false) }, constraints: table => { table.PrimaryKey("PK_StatisticResults", x => x.ResultId); table.ForeignKey( name: "FK_StatisticResults_StatisticRules", column: x => x.RuleId, principalTable: "StatisticRules", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "StatisticRules", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), RuleName = table.Column(type: "varchar(100)", nullable: false), Description = table.Column(type: "text", nullable: true), MetricFormula = table.Column(type: "text", nullable: false), GroupByDimensions = table.Column(type: "text", nullable: false), IsEnabled = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false), UpdatedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_StatisticRules", x => x.Id); }); migrationBuilder.CreateTable( name: "SystemConfigs", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), ConfigKey = table.Column(type: "varchar(100)", nullable: false), ConfigValue = table.Column(type: "text", nullable: false), Description = table.Column(type: "text", nullable: true), Category = table.Column(type: "varchar(50)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false), IsDefault = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false), UpdatedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_SystemConfigs", x => x.Id); }); migrationBuilder.CreateTable( name: "TagMappings", columns: table => new { MappingId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), TemplateId = table.Column(type: "int", nullable: false), DeviceTagId = table.Column(type: "varchar(50)", nullable: false), SystemTagId = table.Column(type: "varchar(50)", nullable: false), DataType = table.Column(type: "varchar(20)", nullable: false), ConversionFormula = table.Column(type: "varchar(100)", nullable: true), Description = table.Column(type: "text", nullable: true), IsActive = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false), UpdatedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_TagMappings", x => x.MappingId); }); migrationBuilder.CreateTable( name: "TemplateFieldMappings", columns: table => new { MappingId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), TemplateId = table.Column(type: "int", nullable: false), FieldName = table.Column(type: "varchar(50)", nullable: false), FieldValue = table.Column(type: "text", nullable: true), DataType = table.Column(type: "varchar(20)", nullable: false), IsRequired = table.Column(type: "tinyint(1)", nullable: false), ValidationRegex = table.Column(type: "varchar(200)", nullable: true), CreatedAt = table.Column(type: "datetime", nullable: false), UpdatedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_TemplateFieldMappings", x => x.MappingId); }); migrationBuilder.CreateTable( name: "TaskExecutionResults", columns: table => new { ExecutionId = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), TaskId = table.Column(type: "varchar(50)", nullable: false), Status = table.Column(type: "int", nullable: false), ExecutionTime = table.Column(type: "datetime", nullable: false), ExecutionDurationMs = table.Column(type: "time", nullable: true), ErrorMessage = table.Column(type: "text", nullable: true), ResultData = table.Column(type: "json", nullable: true) }, constraints: table => { table.PrimaryKey("PK_TaskExecutionResults", x => x.ExecutionId); table.ForeignKey( name: "FK_TaskExecutionResults_ScheduledTasks", column: x => x.TaskId, principalTable: "ScheduledTasks", principalColumn: "TaskId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityIncrement), Username = table.Column(type: "varchar(50)", nullable: false), Email = table.Column(type: "varchar(100)", nullable: false), PasswordHash = table.Column(type: "varchar(255)", nullable: false), FirstName = table.Column(type: "varchar(50)", nullable: false), LastName = table.Column(type: "varchar(50)", nullable: false), Department = table.Column(type: "varchar(50)", nullable: true), RoleId = table.Column(type: "int", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false), LastLogin = table.Column(type: "datetime", nullable: true), CreatedAt = table.Column(type: "datetime", nullable: false), UpdatedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); table.ForeignKey( name: "FK_Users_Roles", column: x => x.RoleId, principalTable: "Roles", principalColumn: "RoleId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserPermissions", columns: table => new { UserId = table.Column(type: "int", nullable: false), PermissionId = table.Column(type: "int", nullable: false), AssignedAt = table.Column(type: "datetime", nullable: false), AssignedBy = table.Column(type: "int", nullable: true) }, constraints: table => { table.PrimaryKey("PK_UserPermissions", x => new { x.UserId, x.PermissionId }); table.ForeignKey( name: "FK_UserPermissions_Permissions", column: x => x.PermissionId, principalTable: "Permissions", principalColumn: "PermissionId", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserPermissions_Users", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "RolePermissions", columns: table => new { RoleId = table.Column(type: "int", nullable: false), PermissionId = table.Column(type: "int", nullable: false), AssignedAt = table.Column(type: "datetime", nullable: false), AssignedBy = table.Column(type: "int", nullable: true) }, constraints: table => { table.PrimaryKey("PK_RolePermissions", x => new { x.RoleId, x.PermissionId }); table.ForeignKey( name: "FK_RolePermissions_Permissions", column: x => x.PermissionId, principalTable: "Permissions", principalColumn: "PermissionId", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_RolePermissions_Roles", column: x => x.RoleId, principalTable: "Roles", principalColumn: "RoleId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserSessions", columns: table => new { SessionId = table.Column(type: "varchar(100)", nullable: false), UserId = table.Column(type: "int", nullable: false), RefreshToken = table.Column(type: "varchar(255)", nullable: false), ExpiresAt = table.Column(type: "datetime", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false), LastAccessedAt = table.Column(type: "datetime", nullable: true) }, constraints: table => { table.PrimaryKey("PK_UserSessions", x => x.SessionId); table.ForeignKey( name: "FK_UserSessions_Users", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_AlarmNotifications_AlarmId", table: "AlarmNotifications", column: "AlarmId"); migrationBuilder.CreateIndex( name: "IX_CollectionConfigs_DeviceId", table: "CollectionConfigs", column: "DeviceId"); migrationBuilder.CreateIndex( name: "IX_CollectionLogs_DeviceId", table: "CollectionLogs", column: "DeviceId"); migrationBuilder.CreateIndex( name: "IX_CollectionResults_DeviceId", table: "CollectionResults", column: "DeviceId"); migrationBuilder.CreateIndex( name: "IX_CollectionTasks_DeviceId", table: "CollectionTasks", column: "DeviceId"); migrationBuilder.CreateIndex( name: "IX_CNCDevices_TemplateId", table: "CNCDevices", column: "TemplateId"); migrationBuilder.CreateIndex( name: "IX_DeviceAssignments_DeviceId", table: "DeviceAssignments", column: "DeviceId"); migrationBuilder.CreateIndex( name: "IX_DeviceAssignments_EmployeeId", table: "DeviceAssignments", column: "EmployeeId"); migrationBuilder.CreateIndex( name: "IX_PasswordResets_UserId", table: "PasswordResets", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_ProductionRecords_DeviceId", table: "ProductionRecords", column: "DeviceId"); migrationBuilder.CreateIndex( name: "IX_ProductionRecords_ProductionDate", table: "ProductionRecords", column: "ProductionDate"); migrationBuilder.CreateIndex( name: "IX_ProgramProductionSummaries_DeviceId", table: "ProgramProductionSummaries", column: "DeviceId"); migrationBuilder.CreateIndex( name: "IX_ProgramProductionSummaries_ProductionDate", table: "ProgramProductionSummaries", column: "ProductionDate"); migrationBuilder.CreateIndex( name: "IX_ProductionSummaries_DeviceId", table: "ProductionSummaries", column: "DeviceId"); migrationBuilder.CreateIndex( name: "IX_ProductionSummaries_ProductionDate", table: "ProductionSummaries", column: "ProductionDate"); migrationBuilder.CreateIndex( name: "IX_StatisticResults_RuleId", table: "StatisticResults", column: "RuleId"); migrationBuilder.CreateIndex( name: "IX_TagMappings_TemplateId", table: "TagMappings", column: "TemplateId"); migrationBuilder.CreateIndex( name: "IX_TaskExecutionResults_TaskId", table: "TaskExecutionResults", column: "TaskId"); migrationBuilder.CreateIndex( name: "IX_Users_RoleId", table: "Users", column: "RoleId"); migrationBuilder.CreateIndex( name: "IX_Users_Username", table: "Users", column: "Username", unique: true); migrationBuilder.CreateIndex( name: "IX_Users_Email", table: "Users", column: "Email", unique: true); migrationBuilder.CreateIndex( name: "IX_UserPermissions_PermissionId", table: "UserPermissions", column: "PermissionId"); migrationBuilder.CreateIndex( name: "IX_UserPermissions_UserId", table: "UserPermissions", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_RolePermissions_PermissionId", table: "RolePermissions", column: "PermissionId"); migrationBuilder.CreateIndex( name: "IX_RolePermissions_RoleId", table: "RolePermissions", column: "RoleId"); migrationBuilder.CreateIndex( name: "IX_UserSessions_UserId", table: "UserSessions", column: "UserId"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "AlarmNotifications"); migrationBuilder.DropTable( name: "UserPermissions"); migrationBuilder.DropTable( name: "RolePermissions"); migrationBuilder.DropTable( name: "UserSessions"); migrationBuilder.DropTable( name: "TaskExecutionResults"); migrationBuilder.DropTable( name: "TagMappings"); migrationBuilder.DropTable( name: "ProductionSummaries"); migrationBuilder.DropTable( name: "ProgramProductionSummaries"); migrationBuilder.DropTable( name: "ProductionRecords"); migrationBuilder.DropTable( name: "StatisticResults"); migrationBuilder.DropTable( name: "RolePermissions"); migrationBuilder.DropTable( name: "UserPermissions"); migrationBuilder.DropTable( name: "ScheduledTasks"); migrationBuilder.DropTable( name: "PasswordResets"); migrationBuilder.DropTable( name: "TemplateFieldMappings"); migrationBuilder.DropTable( name: "UserSessions"); migrationBuilder.DropTable( name: "StatisticRules"); migrationBuilder.DropTable( name: "SystemConfigs"); migrationBuilder.DropTable( name: "Roles"); migrationBuilder.DropTable( name: "ProductionRecords"); migrationBuilder.DropTable( name: "ProgramProductionSummaries"); migrationBuilder.DropTable( name: "ProductionSummaries"); migrationBuilder.DropTable( name: "Employees"); migrationBuilder.DropTable( name: "LogEntries"); migrationBuilder.DropTable( name: "UserPermissions"); migrationBuilder.DropTable( name: "RolePermissions"); migrationBuilder.DropTable( name: "UserSessions"); migrationBuilder.DropTable( name: "PasswordResets"); migrationBuilder.DropTable( name: "Permissions"); migrationBuilder.DropTable( name: "CollectionResults"); migrationBuilder.DropTable( name: "CollectionTasks"); migrationBuilder.DropTable( name: "CollectionLogs"); migrationBuilder.DropTable( name: "CollectionConfigs"); migrationBuilder.DropTable( name: "TaskExecutionResults"); migrationBuilder.DropTable( name: "TagMappings"); migrationBuilder.DropTable( name: "TemplateFieldMappings"); migrationBuilder.DropTable( name: "ScheduledTasks"); migrationBuilder.DropTable( name: "SystemConfigs"); migrationBuilder.DropTable( name: "LogEntries"); migrationBuilder.DropTable( name: "PasswordResets"); migrationBuilder.DropTable( name: "Employees"); migrationBuilder.DropTable( name: "UserPermissions"); migrationBuilder.DropTable( name: "RolePermissions"); migrationBuilder.DropTable( name: "UserSessions"); migrationBuilder.DropTable( name: "Permissions"); migrationBuilder.DropTable( name: "CollectionResults"); migrationBuilder.DropTable( name: "CollectionTasks"); migrationBuilder.DropTable( name: "CollectionLogs"); migrationBuilder.DropTable( name: "CollectionConfigs"); migrationBuilder.DropTable( name: "DeviceAssignments"); migrationBuilder.DropTable( name: "DeviceStatus"); migrationBuilder.DropTable( name: "CNCTemplates"); migrationBuilder.DropTable( name: "CNCDevices"); migrationBuilder.DropTable( name: "StatisticResults"); migrationBuilder.DropTable( name: "StatisticRules"); migrationBuilder.DropTable( name: "ProductionSummaries"); migrationBuilder.DropTable( name: "ProgramProductionSummaries"); migrationBuilder.DropTable( name: "ProductionRecords"); migrationBuilder.DropTable( name: "Users"); migrationBuilder.DropTable( name: "Roles"); migrationBuilder.DropTable( name: "TaskExecutionResults"); migrationBuilder.DropTable( name: "TagMappings"); migrationBuilder.DropTable( name: "TemplateFieldMappings"); migrationBuilder.DropTable( name: "SystemConfigs"); migrationBuilder.DropTable( name: "LogEntries"); migrationBuilder.DropTable( name: "PasswordResets"); migrationBuilder.DropTable( name: "Employees"); migrationBuilder.DropTable( name: "UserPermissions"); migrationBuilder.DropTable( name: "RolePermissions"); migrationBuilder.DropTable( name: "UserSessions"); migrationBuilder.DropTable( name: "Permissions"); migrationBuilder.DropTable( name: "AlarmNotifications"); migrationBuilder.DropTable( name: "AlarmRules"); migrationBuilder.DropTable( name: "Alarms"); } } }