using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations { /// public partial class V3Initial : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "ConfigAuditLog", columns: table => new { AuditId = table.Column(type: "bigint", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Timestamp = table.Column(type: "datetime2(3)", nullable: false, defaultValueSql: "SYSUTCDATETIME()"), Principal = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), EventType = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), ClusterId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), NodeId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), GenerationId = table.Column(type: "bigint", nullable: true), DetailsJson = table.Column(type: "nvarchar(max)", nullable: true), EventId = table.Column(type: "uniqueidentifier", nullable: true), CorrelationId = table.Column(type: "uniqueidentifier", nullable: true), Outcome = table.Column(type: "nvarchar(16)", maxLength: 16, nullable: true) }, constraints: table => { table.PrimaryKey("PK_ConfigAuditLog", x => x.AuditId); table.CheckConstraint("CK_ConfigAuditLog_DetailsJson_IsJson", "DetailsJson IS NULL OR ISJSON(DetailsJson) = 1"); }); migrationBuilder.CreateTable( name: "ConfigEdit", columns: table => new { EditId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), EntityType = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), EntityId = table.Column(type: "uniqueidentifier", nullable: false), FieldsJson = table.Column(type: "nvarchar(max)", nullable: false), ExecutionId = table.Column(type: "uniqueidentifier", nullable: true), EditedBy = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), EditedAtUtc = table.Column(type: "datetime2(3)", nullable: false, defaultValueSql: "SYSUTCDATETIME()"), SourceNode = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false) }, constraints: table => { table.PrimaryKey("PK_ConfigEdit", x => x.EditId); table.CheckConstraint("CK_ConfigEdit_FieldsJson_IsJson", "ISJSON(FieldsJson) = 1"); }); migrationBuilder.CreateTable( name: "DataProtectionKeys", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), FriendlyName = table.Column(type: "nvarchar(max)", nullable: true), Xml = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_DataProtectionKeys", x => x.Id); }); migrationBuilder.CreateTable( name: "Deployment", columns: table => new { DeploymentId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), RevisionHash = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Status = table.Column(type: "int", nullable: false), CreatedBy = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), CreatedAtUtc = table.Column(type: "datetime2(3)", nullable: false, defaultValueSql: "SYSUTCDATETIME()"), ArtifactBlob = table.Column(type: "varbinary(max)", nullable: false), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false), FailureReason = table.Column(type: "nvarchar(2048)", maxLength: 2048, nullable: true), SealedAtUtc = table.Column(type: "datetime2(3)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Deployment", x => x.DeploymentId); }); migrationBuilder.CreateTable( name: "Device", columns: table => new { DeviceRowId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), DeviceId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), DriverInstanceId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Name = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), Enabled = table.Column(type: "bit", nullable: false), DeviceConfig = table.Column(type: "nvarchar(max)", nullable: false), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false) }, constraints: table => { table.PrimaryKey("PK_Device", x => x.DeviceRowId); table.CheckConstraint("CK_Device_DeviceConfig_IsJson", "ISJSON(DeviceConfig) = 1"); }); migrationBuilder.CreateTable( name: "DriverHostStatus", columns: table => new { NodeId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), DriverInstanceId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), HostName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), State = table.Column(type: "nvarchar(16)", maxLength: 16, nullable: false), StateChangedUtc = table.Column(type: "datetime2(3)", nullable: false), LastSeenUtc = table.Column(type: "datetime2(3)", nullable: false), Detail = table.Column(type: "nvarchar(1024)", maxLength: 1024, nullable: true) }, constraints: table => { table.PrimaryKey("PK_DriverHostStatus", x => new { x.NodeId, x.DriverInstanceId, x.HostName }); }); migrationBuilder.CreateTable( name: "DriverInstanceResilienceStatus", columns: table => new { DriverInstanceId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), HostName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), LastCircuitBreakerOpenUtc = table.Column(type: "datetime2(3)", nullable: true), ConsecutiveFailures = table.Column(type: "int", nullable: false), CurrentBulkheadDepth = table.Column(type: "int", nullable: false), LastRecycleUtc = table.Column(type: "datetime2(3)", nullable: true), BaselineFootprintBytes = table.Column(type: "bigint", nullable: false), CurrentFootprintBytes = table.Column(type: "bigint", nullable: false), LastSampledUtc = table.Column(type: "datetime2(3)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DriverInstanceResilienceStatus", x => new { x.DriverInstanceId, x.HostName }); }); migrationBuilder.CreateTable( name: "Equipment", columns: table => new { EquipmentRowId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), EquipmentId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), EquipmentUuid = table.Column(type: "uniqueidentifier", nullable: false), UnsLineId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Name = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: false), MachineCode = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), ZTag = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), SAPID = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), Manufacturer = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), Model = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), SerialNumber = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), HardwareRevision = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: true), SoftwareRevision = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: true), YearOfConstruction = table.Column(type: "smallint", nullable: true), AssetLocation = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), ManufacturerUri = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: true), DeviceManualUri = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: true), EquipmentClassRef = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: true), Enabled = table.Column(type: "bit", nullable: false), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false) }, constraints: table => { table.PrimaryKey("PK_Equipment", x => x.EquipmentRowId); }); migrationBuilder.CreateTable( name: "ExternalIdReservation", columns: table => new { ReservationId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), Kind = table.Column(type: "nvarchar(16)", maxLength: 16, nullable: false), Value = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), EquipmentUuid = table.Column(type: "uniqueidentifier", nullable: false), ClusterId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), FirstPublishedAt = table.Column(type: "datetime2(3)", nullable: false, defaultValueSql: "SYSUTCDATETIME()"), FirstPublishedBy = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), LastPublishedAt = table.Column(type: "datetime2(3)", nullable: false, defaultValueSql: "SYSUTCDATETIME()"), ReleasedAt = table.Column(type: "datetime2(3)", nullable: true), ReleasedBy = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: true), ReleaseReason = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: true) }, constraints: table => { table.PrimaryKey("PK_ExternalIdReservation", x => x.ReservationId); }); migrationBuilder.CreateTable( name: "NodeAcl", columns: table => new { NodeAclRowId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), NodeAclId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), ClusterId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), LdapGroup = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), ScopeKind = table.Column(type: "nvarchar(16)", maxLength: 16, nullable: false), ScopeId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), PermissionFlags = table.Column(type: "int", nullable: false), Notes = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: true), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false) }, constraints: table => { table.PrimaryKey("PK_NodeAcl", x => x.NodeAclRowId); }); migrationBuilder.CreateTable( name: "PollGroup", columns: table => new { PollGroupRowId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), PollGroupId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), DriverInstanceId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Name = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), IntervalMs = table.Column(type: "int", nullable: false), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false) }, constraints: table => { table.PrimaryKey("PK_PollGroup", x => x.PollGroupRowId); table.CheckConstraint("CK_PollGroup_IntervalMs_Min", "IntervalMs >= 50"); }); migrationBuilder.CreateTable( name: "Script", columns: table => new { ScriptRowId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), ScriptId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), Name = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), SourceCode = table.Column(type: "nvarchar(max)", nullable: false), SourceHash = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Language = table.Column(type: "nvarchar(16)", maxLength: 16, nullable: false), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false) }, constraints: table => { table.PrimaryKey("PK_Script", x => x.ScriptRowId); }); migrationBuilder.CreateTable( name: "ScriptedAlarm", columns: table => new { ScriptedAlarmRowId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), ScriptedAlarmId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), EquipmentId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Name = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), AlarmType = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: false), Severity = table.Column(type: "int", nullable: false), MessageTemplate = table.Column(type: "nvarchar(1024)", maxLength: 1024, nullable: false), PredicateScriptId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), HistorizeToAveva = table.Column(type: "bit", nullable: false), Retain = table.Column(type: "bit", nullable: false), Enabled = table.Column(type: "bit", nullable: false), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false) }, constraints: table => { table.PrimaryKey("PK_ScriptedAlarm", x => x.ScriptedAlarmRowId); table.CheckConstraint("CK_ScriptedAlarm_AlarmType", "AlarmType IN ('AlarmCondition','LimitAlarm','OffNormalAlarm','DiscreteAlarm')"); table.CheckConstraint("CK_ScriptedAlarm_Severity_Range", "Severity BETWEEN 1 AND 1000"); }); migrationBuilder.CreateTable( name: "ScriptedAlarmState", columns: table => new { ScriptedAlarmId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), EnabledState = table.Column(type: "nvarchar(16)", maxLength: 16, nullable: false), AckedState = table.Column(type: "nvarchar(16)", maxLength: 16, nullable: false), ConfirmedState = table.Column(type: "nvarchar(16)", maxLength: 16, nullable: false), ShelvingState = table.Column(type: "nvarchar(16)", maxLength: 16, nullable: false), ShelvingExpiresUtc = table.Column(type: "datetime2(3)", nullable: true), LastAckUser = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: true), LastAckComment = table.Column(type: "nvarchar(1024)", maxLength: 1024, nullable: true), LastAckUtc = table.Column(type: "datetime2(3)", nullable: true), LastConfirmUser = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: true), LastConfirmComment = table.Column(type: "nvarchar(1024)", maxLength: 1024, nullable: true), LastConfirmUtc = table.Column(type: "datetime2(3)", nullable: true), CommentsJson = table.Column(type: "nvarchar(max)", nullable: false), UpdatedAtUtc = table.Column(type: "datetime2(3)", nullable: false, defaultValueSql: "SYSUTCDATETIME()") }, constraints: table => { table.PrimaryKey("PK_ScriptedAlarmState", x => x.ScriptedAlarmId); table.CheckConstraint("CK_ScriptedAlarmState_CommentsJson_IsJson", "ISJSON(CommentsJson) = 1"); }); migrationBuilder.CreateTable( name: "ServerCluster", columns: table => new { ClusterId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Name = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), Enterprise = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: false), Site = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: false), NodeCount = table.Column(type: "tinyint", nullable: false), RedundancyMode = table.Column(type: "nvarchar(16)", maxLength: 16, nullable: false), Enabled = table.Column(type: "bit", nullable: false), Notes = table.Column(type: "nvarchar(1024)", maxLength: 1024, nullable: true), CreatedAt = table.Column(type: "datetime2(3)", nullable: false, defaultValueSql: "SYSUTCDATETIME()"), CreatedBy = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), ModifiedAt = table.Column(type: "datetime2(3)", nullable: true), ModifiedBy = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: true) }, constraints: table => { table.PrimaryKey("PK_ServerCluster", x => x.ClusterId); table.CheckConstraint("CK_ServerCluster_RedundancyMode_NodeCount", "((NodeCount = 1 AND RedundancyMode = 'None') OR (NodeCount = 2 AND RedundancyMode IN ('Warm', 'Hot')))"); }); migrationBuilder.CreateTable( name: "Tag", columns: table => new { TagRowId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), TagId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), DeviceId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), TagGroupId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), Name = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), DataType = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: false), AccessLevel = table.Column(type: "nvarchar(16)", maxLength: 16, nullable: false), WriteIdempotent = table.Column(type: "bit", nullable: false), PollGroupId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), TagConfig = table.Column(type: "nvarchar(max)", nullable: false), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false) }, constraints: table => { table.PrimaryKey("PK_Tag", x => x.TagRowId); table.CheckConstraint("CK_Tag_TagConfig_IsJson", "ISJSON(TagConfig) = 1"); }); migrationBuilder.CreateTable( name: "TagGroup", columns: table => new { TagGroupRowId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), TagGroupId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), DeviceId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), ParentTagGroupId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), Name = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), SortOrder = table.Column(type: "int", nullable: false), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false) }, constraints: table => { table.PrimaryKey("PK_TagGroup", x => x.TagGroupRowId); }); migrationBuilder.CreateTable( name: "UnsLine", columns: table => new { UnsLineRowId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), UnsLineId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), UnsAreaId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Name = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: false), Notes = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: true), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false) }, constraints: table => { table.PrimaryKey("PK_UnsLine", x => x.UnsLineRowId); }); migrationBuilder.CreateTable( name: "UnsTagReference", columns: table => new { UnsTagReferenceRowId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), UnsTagReferenceId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), EquipmentId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), TagId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), DisplayNameOverride = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: true), SortOrder = table.Column(type: "int", nullable: false), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false) }, constraints: table => { table.PrimaryKey("PK_UnsTagReference", x => x.UnsTagReferenceRowId); }); migrationBuilder.CreateTable( name: "VirtualTag", columns: table => new { VirtualTagRowId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), VirtualTagId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), EquipmentId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Name = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), DataType = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: false), ScriptId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), ChangeTriggered = table.Column(type: "bit", nullable: false), TimerIntervalMs = table.Column(type: "int", nullable: true), Historize = table.Column(type: "bit", nullable: false), Enabled = table.Column(type: "bit", nullable: false), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false) }, constraints: table => { table.PrimaryKey("PK_VirtualTag", x => x.VirtualTagRowId); table.CheckConstraint("CK_VirtualTag_TimerInterval_Min", "TimerIntervalMs IS NULL OR TimerIntervalMs >= 50"); table.CheckConstraint("CK_VirtualTag_Trigger_AtLeastOne", "ChangeTriggered = 1 OR TimerIntervalMs IS NOT NULL"); }); migrationBuilder.CreateTable( name: "ClusterNode", columns: table => new { NodeId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), ClusterId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Host = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), OpcUaPort = table.Column(type: "int", nullable: false), DashboardPort = table.Column(type: "int", nullable: false), ApplicationUri = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), ServiceLevelBase = table.Column(type: "tinyint", nullable: false), DriverConfigOverridesJson = table.Column(type: "nvarchar(max)", nullable: true), Enabled = table.Column(type: "bit", nullable: false), LastSeenAt = table.Column(type: "datetime2(3)", nullable: true), CreatedAt = table.Column(type: "datetime2(3)", nullable: false, defaultValueSql: "SYSUTCDATETIME()"), CreatedBy = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false) }, constraints: table => { table.PrimaryKey("PK_ClusterNode", x => x.NodeId); table.ForeignKey( name: "FK_ClusterNode_ServerCluster_ClusterId", column: x => x.ClusterId, principalTable: "ServerCluster", principalColumn: "ClusterId", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "DriverInstance", columns: table => new { DriverInstanceRowId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), DriverInstanceId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), ClusterId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), RawFolderId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), Name = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), DriverType = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: false), Enabled = table.Column(type: "bit", nullable: false), DriverConfig = table.Column(type: "nvarchar(max)", nullable: false), ResilienceConfig = table.Column(type: "nvarchar(max)", nullable: true), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false) }, constraints: table => { table.PrimaryKey("PK_DriverInstance", x => x.DriverInstanceRowId); table.CheckConstraint("CK_DriverInstance_DriverConfig_IsJson", "ISJSON(DriverConfig) = 1"); table.CheckConstraint("CK_DriverInstance_ResilienceConfig_IsJson", "ResilienceConfig IS NULL OR ISJSON(ResilienceConfig) = 1"); table.ForeignKey( name: "FK_DriverInstance_ServerCluster_ClusterId", column: x => x.ClusterId, principalTable: "ServerCluster", principalColumn: "ClusterId", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "LdapGroupRoleMapping", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), LdapGroup = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: false), Role = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: false), ClusterId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), IsSystemWide = table.Column(type: "bit", nullable: false), CreatedAtUtc = table.Column(type: "datetime2(3)", nullable: false), Notes = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: true) }, constraints: table => { table.PrimaryKey("PK_LdapGroupRoleMapping", x => x.Id); table.ForeignKey( name: "FK_LdapGroupRoleMapping_ServerCluster_ClusterId", column: x => x.ClusterId, principalTable: "ServerCluster", principalColumn: "ClusterId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "RawFolder", columns: table => new { RawFolderRowId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), RawFolderId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), ClusterId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), ParentRawFolderId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), Name = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), SortOrder = table.Column(type: "int", nullable: false), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false) }, constraints: table => { table.PrimaryKey("PK_RawFolder", x => x.RawFolderRowId); table.ForeignKey( name: "FK_RawFolder_ServerCluster_ClusterId", column: x => x.ClusterId, principalTable: "ServerCluster", principalColumn: "ClusterId", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "UnsArea", columns: table => new { UnsAreaRowId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), UnsAreaId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: true), ClusterId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Name = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: false), Notes = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: true), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false) }, constraints: table => { table.PrimaryKey("PK_UnsArea", x => x.UnsAreaRowId); table.ForeignKey( name: "FK_UnsArea_ServerCluster_ClusterId", column: x => x.ClusterId, principalTable: "ServerCluster", principalColumn: "ClusterId", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "ClusterNodeCredential", columns: table => new { CredentialId = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWSEQUENTIALID()"), NodeId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Kind = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: false), Value = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: false), Enabled = table.Column(type: "bit", nullable: false), RotatedAt = table.Column(type: "datetime2(3)", nullable: true), CreatedAt = table.Column(type: "datetime2(3)", nullable: false, defaultValueSql: "SYSUTCDATETIME()"), CreatedBy = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false) }, constraints: table => { table.PrimaryKey("PK_ClusterNodeCredential", x => x.CredentialId); table.ForeignKey( name: "FK_ClusterNodeCredential_ClusterNode_NodeId", column: x => x.NodeId, principalTable: "ClusterNode", principalColumn: "NodeId", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "NodeDeploymentState", columns: table => new { NodeId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), DeploymentId = table.Column(type: "uniqueidentifier", nullable: false), Status = table.Column(type: "int", nullable: false), StartedAtUtc = table.Column(type: "datetime2(3)", nullable: false, defaultValueSql: "SYSUTCDATETIME()"), AppliedAtUtc = table.Column(type: "datetime2(3)", nullable: true), FailureReason = table.Column(type: "nvarchar(2048)", maxLength: 2048, nullable: true), RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: false) }, constraints: table => { table.PrimaryKey("PK_NodeDeploymentState", x => new { x.NodeId, x.DeploymentId }); table.ForeignKey( name: "FK_NodeDeploymentState_ClusterNode_NodeId", column: x => x.NodeId, principalTable: "ClusterNode", principalColumn: "NodeId", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_NodeDeploymentState_Deployment_DeploymentId", column: x => x.DeploymentId, principalTable: "Deployment", principalColumn: "DeploymentId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_ClusterNode_ClusterId", table: "ClusterNode", column: "ClusterId"); migrationBuilder.CreateIndex( name: "UX_ClusterNode_ApplicationUri", table: "ClusterNode", column: "ApplicationUri", unique: true); migrationBuilder.CreateIndex( name: "IX_ClusterNodeCredential_NodeId", table: "ClusterNodeCredential", columns: new[] { "NodeId", "Enabled" }); migrationBuilder.CreateIndex( name: "UX_ClusterNodeCredential_Value", table: "ClusterNodeCredential", columns: new[] { "Kind", "Value" }, unique: true, filter: "[Enabled] = 1"); migrationBuilder.CreateIndex( name: "IX_ConfigAuditLog_Cluster_Time", table: "ConfigAuditLog", columns: new[] { "ClusterId", "Timestamp" }, descending: new[] { false, true }); migrationBuilder.CreateIndex( name: "IX_ConfigAuditLog_Generation", table: "ConfigAuditLog", column: "GenerationId", filter: "[GenerationId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "UX_ConfigAuditLog_EventId", table: "ConfigAuditLog", column: "EventId", unique: true, filter: "[EventId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_ConfigEdit_EditedAt", table: "ConfigEdit", column: "EditedAtUtc"); migrationBuilder.CreateIndex( name: "IX_ConfigEdit_Entity", table: "ConfigEdit", columns: new[] { "EntityType", "EntityId" }); migrationBuilder.CreateIndex( name: "IX_ConfigEdit_Execution", table: "ConfigEdit", column: "ExecutionId", filter: "[ExecutionId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_Deployment_CreatedAt", table: "Deployment", column: "CreatedAtUtc"); migrationBuilder.CreateIndex( name: "IX_Deployment_Status", table: "Deployment", column: "Status"); migrationBuilder.CreateIndex( name: "IX_Device_Driver", table: "Device", column: "DriverInstanceId"); migrationBuilder.CreateIndex( name: "UX_Device_Driver_Name", table: "Device", columns: new[] { "DriverInstanceId", "Name" }, unique: true); migrationBuilder.CreateIndex( name: "UX_Device_LogicalId", table: "Device", column: "DeviceId", unique: true, filter: "[DeviceId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_DriverHostStatus_LastSeen", table: "DriverHostStatus", column: "LastSeenUtc"); migrationBuilder.CreateIndex( name: "IX_DriverHostStatus_Node", table: "DriverHostStatus", column: "NodeId"); migrationBuilder.CreateIndex( name: "IX_DriverInstance_Cluster", table: "DriverInstance", column: "ClusterId"); migrationBuilder.CreateIndex( name: "IX_DriverInstance_RawFolder", table: "DriverInstance", column: "RawFolderId"); migrationBuilder.CreateIndex( name: "UX_DriverInstance_ClusterRoot_Name", table: "DriverInstance", columns: new[] { "ClusterId", "Name" }, unique: true, filter: "[RawFolderId] IS NULL"); migrationBuilder.CreateIndex( name: "UX_DriverInstance_Folder_Name", table: "DriverInstance", columns: new[] { "ClusterId", "RawFolderId", "Name" }, unique: true, filter: "[RawFolderId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "UX_DriverInstance_LogicalId", table: "DriverInstance", column: "DriverInstanceId", unique: true, filter: "[DriverInstanceId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_DriverResilience_LastSampled", table: "DriverInstanceResilienceStatus", column: "LastSampledUtc"); migrationBuilder.CreateIndex( name: "IX_Equipment_Line", table: "Equipment", column: "UnsLineId"); migrationBuilder.CreateIndex( name: "IX_Equipment_MachineCode", table: "Equipment", column: "MachineCode"); migrationBuilder.CreateIndex( name: "IX_Equipment_SAPID", table: "Equipment", column: "SAPID", filter: "[SAPID] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_Equipment_ZTag", table: "Equipment", column: "ZTag", filter: "[ZTag] IS NOT NULL"); migrationBuilder.CreateIndex( name: "UX_Equipment_LinePath", table: "Equipment", columns: new[] { "UnsLineId", "Name" }, unique: true); migrationBuilder.CreateIndex( name: "UX_Equipment_LogicalId", table: "Equipment", column: "EquipmentId", unique: true, filter: "[EquipmentId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "UX_Equipment_Uuid", table: "Equipment", column: "EquipmentUuid", unique: true); migrationBuilder.CreateIndex( name: "IX_ExternalIdReservation_Equipment", table: "ExternalIdReservation", column: "EquipmentUuid"); migrationBuilder.CreateIndex( name: "UX_ExternalIdReservation_KindValue_Active", table: "ExternalIdReservation", columns: new[] { "Kind", "Value" }, unique: true, filter: "[ReleasedAt] IS NULL"); migrationBuilder.CreateIndex( name: "IX_LdapGroupRoleMapping_ClusterId", table: "LdapGroupRoleMapping", column: "ClusterId"); migrationBuilder.CreateIndex( name: "IX_LdapGroupRoleMapping_Group", table: "LdapGroupRoleMapping", column: "LdapGroup"); migrationBuilder.CreateIndex( name: "UX_LdapGroupRoleMapping_Group_Cluster", table: "LdapGroupRoleMapping", columns: new[] { "LdapGroup", "ClusterId" }, unique: true, filter: "[ClusterId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_NodeAcl_Cluster", table: "NodeAcl", column: "ClusterId"); migrationBuilder.CreateIndex( name: "IX_NodeAcl_Group", table: "NodeAcl", column: "LdapGroup"); migrationBuilder.CreateIndex( name: "IX_NodeAcl_Scope", table: "NodeAcl", columns: new[] { "ScopeKind", "ScopeId" }, filter: "[ScopeId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "UX_NodeAcl_GroupScope", table: "NodeAcl", columns: new[] { "ClusterId", "LdapGroup", "ScopeKind", "ScopeId" }, unique: true, filter: "[ScopeId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "UX_NodeAcl_LogicalId", table: "NodeAcl", column: "NodeAclId", unique: true, filter: "[NodeAclId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_NodeDeploymentState_Deployment", table: "NodeDeploymentState", column: "DeploymentId"); migrationBuilder.CreateIndex( name: "IX_NodeDeploymentState_Status", table: "NodeDeploymentState", column: "Status"); migrationBuilder.CreateIndex( name: "IX_PollGroup_Driver", table: "PollGroup", column: "DriverInstanceId"); migrationBuilder.CreateIndex( name: "UX_PollGroup_LogicalId", table: "PollGroup", column: "PollGroupId", unique: true, filter: "[PollGroupId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_RawFolder_Cluster", table: "RawFolder", column: "ClusterId"); migrationBuilder.CreateIndex( name: "UX_RawFolder_ClusterRoot_Name", table: "RawFolder", columns: new[] { "ClusterId", "Name" }, unique: true, filter: "[ParentRawFolderId] IS NULL"); migrationBuilder.CreateIndex( name: "UX_RawFolder_LogicalId", table: "RawFolder", column: "RawFolderId", unique: true, filter: "[RawFolderId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "UX_RawFolder_Parent_Name", table: "RawFolder", columns: new[] { "ClusterId", "ParentRawFolderId", "Name" }, unique: true, filter: "[ParentRawFolderId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_Script_SourceHash", table: "Script", column: "SourceHash"); migrationBuilder.CreateIndex( name: "UX_Script_LogicalId", table: "Script", column: "ScriptId", unique: true, filter: "[ScriptId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_ScriptedAlarm_Script", table: "ScriptedAlarm", column: "PredicateScriptId"); migrationBuilder.CreateIndex( name: "UX_ScriptedAlarm_EquipmentPath", table: "ScriptedAlarm", columns: new[] { "EquipmentId", "Name" }, unique: true); migrationBuilder.CreateIndex( name: "UX_ScriptedAlarm_LogicalId", table: "ScriptedAlarm", column: "ScriptedAlarmId", unique: true, filter: "[ScriptedAlarmId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_ServerCluster_Site", table: "ServerCluster", column: "Site"); migrationBuilder.CreateIndex( name: "UX_ServerCluster_Name", table: "ServerCluster", column: "Name", unique: true); migrationBuilder.CreateIndex( name: "IX_Tag_Device", table: "Tag", columns: new[] { "DeviceId", "TagGroupId" }); migrationBuilder.CreateIndex( name: "UX_Tag_Device_Name", table: "Tag", columns: new[] { "DeviceId", "Name" }, unique: true, filter: "[TagGroupId] IS NULL"); migrationBuilder.CreateIndex( name: "UX_Tag_Group_Name", table: "Tag", columns: new[] { "DeviceId", "TagGroupId", "Name" }, unique: true, filter: "[TagGroupId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "UX_Tag_LogicalId", table: "Tag", column: "TagId", unique: true, filter: "[TagId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_TagGroup_Device", table: "TagGroup", column: "DeviceId"); migrationBuilder.CreateIndex( name: "UX_TagGroup_DeviceRoot_Name", table: "TagGroup", columns: new[] { "DeviceId", "Name" }, unique: true, filter: "[ParentTagGroupId] IS NULL"); migrationBuilder.CreateIndex( name: "UX_TagGroup_LogicalId", table: "TagGroup", column: "TagGroupId", unique: true, filter: "[TagGroupId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "UX_TagGroup_Parent_Name", table: "TagGroup", columns: new[] { "DeviceId", "ParentTagGroupId", "Name" }, unique: true, filter: "[ParentTagGroupId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_UnsArea_Cluster", table: "UnsArea", column: "ClusterId"); migrationBuilder.CreateIndex( name: "UX_UnsArea_ClusterName", table: "UnsArea", columns: new[] { "ClusterId", "Name" }, unique: true); migrationBuilder.CreateIndex( name: "UX_UnsArea_LogicalId", table: "UnsArea", column: "UnsAreaId", unique: true, filter: "[UnsAreaId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_UnsLine_Area", table: "UnsLine", column: "UnsAreaId"); migrationBuilder.CreateIndex( name: "UX_UnsLine_AreaName", table: "UnsLine", columns: new[] { "UnsAreaId", "Name" }, unique: true); migrationBuilder.CreateIndex( name: "UX_UnsLine_LogicalId", table: "UnsLine", column: "UnsLineId", unique: true, filter: "[UnsLineId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_UnsTagReference_Equipment", table: "UnsTagReference", column: "EquipmentId"); migrationBuilder.CreateIndex( name: "IX_UnsTagReference_Tag", table: "UnsTagReference", column: "TagId"); migrationBuilder.CreateIndex( name: "UX_UnsTagReference_Equip_Tag", table: "UnsTagReference", columns: new[] { "EquipmentId", "TagId" }, unique: true); migrationBuilder.CreateIndex( name: "UX_UnsTagReference_LogicalId", table: "UnsTagReference", column: "UnsTagReferenceId", unique: true, filter: "[UnsTagReferenceId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_VirtualTag_Script", table: "VirtualTag", column: "ScriptId"); migrationBuilder.CreateIndex( name: "UX_VirtualTag_EquipmentPath", table: "VirtualTag", columns: new[] { "EquipmentId", "Name" }, unique: true); migrationBuilder.CreateIndex( name: "UX_VirtualTag_LogicalId", table: "VirtualTag", column: "VirtualTagId", unique: true, filter: "[VirtualTagId] IS NOT NULL"); // Hand-authored SQL squashed in from the retired per-migration proc + grant files // (see V3Initial.StoredProcedures.cs for the full rationale + the v3 rewrites). CreateStoredProcedures(migrationBuilder); CreateAuthorizationGrants(migrationBuilder); } /// protected override void Down(MigrationBuilder migrationBuilder) { DropAuthorizationGrants(migrationBuilder); DropStoredProcedures(migrationBuilder); migrationBuilder.DropTable( name: "ClusterNodeCredential"); migrationBuilder.DropTable( name: "ConfigAuditLog"); migrationBuilder.DropTable( name: "ConfigEdit"); migrationBuilder.DropTable( name: "DataProtectionKeys"); migrationBuilder.DropTable( name: "Device"); migrationBuilder.DropTable( name: "DriverHostStatus"); migrationBuilder.DropTable( name: "DriverInstance"); migrationBuilder.DropTable( name: "DriverInstanceResilienceStatus"); migrationBuilder.DropTable( name: "Equipment"); migrationBuilder.DropTable( name: "ExternalIdReservation"); migrationBuilder.DropTable( name: "LdapGroupRoleMapping"); migrationBuilder.DropTable( name: "NodeAcl"); migrationBuilder.DropTable( name: "NodeDeploymentState"); migrationBuilder.DropTable( name: "PollGroup"); migrationBuilder.DropTable( name: "RawFolder"); migrationBuilder.DropTable( name: "Script"); migrationBuilder.DropTable( name: "ScriptedAlarm"); migrationBuilder.DropTable( name: "ScriptedAlarmState"); migrationBuilder.DropTable( name: "Tag"); migrationBuilder.DropTable( name: "TagGroup"); migrationBuilder.DropTable( name: "UnsArea"); migrationBuilder.DropTable( name: "UnsLine"); migrationBuilder.DropTable( name: "UnsTagReference"); migrationBuilder.DropTable( name: "VirtualTag"); migrationBuilder.DropTable( name: "ClusterNode"); migrationBuilder.DropTable( name: "Deployment"); migrationBuilder.DropTable( name: "ServerCluster"); } } }