13 protected override void Up(MigrationBuilder migrationBuilder)
15 ArgumentNullException.ThrowIfNull(migrationBuilder);
17 migrationBuilder.AlterColumn<
string>(
18 name:
"SystemIdentifier",
22 oldClrType: typeof(
string),
23 oldType:
"nvarchar(450)",
26 migrationBuilder.AlterColumn<
string>(
31 oldClrType: typeof(
string),
32 oldType:
"nvarchar(max)",
35 migrationBuilder.AlterColumn<
string>(
36 name:
"CanonicalName",
40 oldClrType: typeof(
string),
41 oldType:
"nvarchar(450)");
43 migrationBuilder.AddColumn<
long>(
48 migrationBuilder.CreateTable(
52 Id = table.Column<
long>(nullable:
false)
53 .Annotation(
"SqlServer:Identity",
"1, 1"),
54 Name = table.Column<
string>(maxLength: 100, nullable:
false),
58 table.PrimaryKey(
"PK_Groups", x => x.Id);
61 migrationBuilder.CreateTable(
62 name:
"PermissionSets",
65 Id = table.Column<
long>(nullable:
false)
66 .Annotation(
"SqlServer:Identity",
"1, 1"),
67 AdministrationRights = table.Column<decimal>(nullable:
false),
68 InstanceManagerRights = table.Column<decimal>(nullable:
false),
69 UserId = table.Column<
long>(nullable:
true),
70 GroupId = table.Column<
long>(nullable:
true),
74 table.PrimaryKey(
"PK_PermissionSets", x => x.Id);
76 name:
"FK_PermissionSets_Groups_GroupId",
77 column: x => x.GroupId,
78 principalTable:
"Groups",
79 principalColumn:
"Id",
80 onDelete: ReferentialAction.Cascade);
82 name:
"FK_PermissionSets_Users_UserId",
83 column: x => x.UserId,
84 principalTable:
"Users",
85 principalColumn:
"Id",
86 onDelete: ReferentialAction.Cascade);
89 migrationBuilder.CreateTable(
90 name:
"InstancePermissionSets",
93 Id = table.Column<
long>(nullable:
false)
94 .Annotation(
"SqlServer:Identity",
"1, 1"),
95 PermissionSetId = table.Column<
long>(nullable:
false),
96 InstancePermissionSetRights = table.Column<decimal>(nullable:
false),
97 ByondRights = table.Column<decimal>(nullable:
false),
98 DreamDaemonRights = table.Column<decimal>(nullable:
false),
99 DreamMakerRights = table.Column<decimal>(nullable:
false),
100 RepositoryRights = table.Column<decimal>(nullable:
false),
101 ChatBotRights = table.Column<decimal>(nullable:
false),
102 ConfigurationRights = table.Column<decimal>(nullable:
false),
103 InstanceId = table.Column<
long>(nullable:
false),
105 constraints: table =>
107 table.PrimaryKey(
"PK_InstancePermissionSets", x => x.Id);
109 name:
"FK_InstancePermissionSets_Instances_InstanceId",
110 column: x => x.InstanceId,
111 principalTable:
"Instances",
112 principalColumn:
"Id",
113 onDelete: ReferentialAction.Cascade);
115 name:
"FK_InstancePermissionSets_PermissionSets_PermissionSetId",
116 column: x => x.PermissionSetId,
117 principalTable:
"PermissionSets",
118 principalColumn:
"Id",
119 onDelete: ReferentialAction.Cascade);
122 migrationBuilder.CreateIndex(
123 name:
"IX_Users_GroupId",
127 migrationBuilder.CreateIndex(
128 name:
"IX_Groups_Name",
133 migrationBuilder.CreateIndex(
134 name:
"IX_InstancePermissionSets_InstanceId",
135 table:
"InstancePermissionSets",
136 column:
"InstanceId");
138 migrationBuilder.CreateIndex(
139 name:
"IX_InstancePermissionSets_PermissionSetId_InstanceId",
140 table:
"InstancePermissionSets",
141 columns:
new[] {
"PermissionSetId",
"InstanceId" },
144 migrationBuilder.CreateIndex(
145 name:
"IX_PermissionSets_GroupId",
146 table:
"PermissionSets",
149 filter:
"[GroupId] IS NOT NULL");
151 migrationBuilder.CreateIndex(
152 name:
"IX_PermissionSets_UserId",
153 table:
"PermissionSets",
156 filter:
"[UserId] IS NOT NULL");
158 migrationBuilder.AddForeignKey(
159 name:
"FK_Users_Groups_GroupId",
162 principalTable:
"Groups",
163 principalColumn:
"Id",
164 onDelete: ReferentialAction.Restrict);
166 migrationBuilder.Sql(
167 "INSERT INTO PermissionSets (UserId, AdministrationRights, InstanceManagerRights) SELECT Id, AdministrationRights, InstanceManagerRights FROM Users");
169 migrationBuilder.Sql(
170 "INSERT INTO InstancePermissionSets (PermissionSetId, InstanceId, InstancePermissionSetRights, ByondRights, DreamDaemonRights, DreamMakerRights, RepositoryRights, ChatBotRights, ConfigurationRights) SELECT p.Id, iu.InstanceId, iu.InstanceUserRights, iu.ByondRights, iu.DreamDaemonRights, iu.DreamMakerRights, iu.RepositoryRights, iu.ChatBotRights, iu.ConfigurationRights FROM InstanceUsers iu JOIN PermissionSets p ON iu.UserId = p.UserId");
172 migrationBuilder.DropTable(
173 name:
"InstanceUsers");
175 migrationBuilder.DropColumn(
176 name:
"AdministrationRights",
179 migrationBuilder.DropColumn(
180 name:
"InstanceManagerRights",
185 protected override void Down(MigrationBuilder migrationBuilder)
187 ArgumentNullException.ThrowIfNull(migrationBuilder);
189 migrationBuilder.AlterColumn<
string>(
190 name:
"SystemIdentifier",
192 type:
"nvarchar(450)",
194 oldClrType: typeof(
string),
198 migrationBuilder.AlterColumn<
string>(
201 type:
"nvarchar(max)",
204 oldClrType: typeof(
string),
207 migrationBuilder.AlterColumn<
string>(
208 name:
"CanonicalName",
210 type:
"nvarchar(450)",
212 oldClrType: typeof(
string),
215 migrationBuilder.AddColumn<decimal>(
216 name:
"AdministrationRights",
218 type:
"decimal(20,0)",
222 migrationBuilder.AddColumn<decimal>(
223 name:
"InstanceManagerRights",
225 type:
"decimal(20,0)",
229 migrationBuilder.CreateTable(
230 name:
"InstanceUsers",
231 columns: table =>
new
233 Id = table.Column<
long>(type:
"bigint", nullable:
false)
234 .Annotation(
"SqlServer:Identity",
"1, 1"),
235 ByondRights = table.Column<decimal>(type:
"decimal(20,0)", nullable:
false),
236 ChatBotRights = table.Column<decimal>(type:
"decimal(20,0)", nullable:
false),
237 ConfigurationRights = table.Column<decimal>(type:
"decimal(20,0)", nullable:
false),
238 DreamDaemonRights = table.Column<decimal>(type:
"decimal(20,0)", nullable:
false),
239 DreamMakerRights = table.Column<decimal>(type:
"decimal(20,0)", nullable:
false),
240 InstanceId = table.Column<
long>(type:
"bigint", nullable:
false),
241 InstanceUserRights = table.Column<decimal>(type:
"decimal(20,0)", nullable:
false),
242 RepositoryRights = table.Column<decimal>(type:
"decimal(20,0)", nullable:
false),
243 UserId = table.Column<
long>(type:
"bigint", nullable:
false),
245 constraints: table =>
247 table.PrimaryKey(
"PK_InstanceUsers", x => x.Id);
249 name:
"FK_InstanceUsers_Instances_InstanceId",
250 column: x => x.InstanceId,
251 principalTable:
"Instances",
252 principalColumn:
"Id",
253 onDelete: ReferentialAction.Cascade);
255 name:
"FK_InstanceUsers_Users_UserId",
256 column: x => x.UserId,
257 principalTable:
"Users",
258 principalColumn:
"Id",
259 onDelete: ReferentialAction.Cascade);
262 migrationBuilder.CreateIndex(
263 name:
"IX_InstanceUsers_InstanceId",
264 table:
"InstanceUsers",
265 column:
"InstanceId");
267 migrationBuilder.CreateIndex(
268 name:
"IX_InstanceUsers_UserId_InstanceId",
269 table:
"InstanceUsers",
270 columns:
new[] {
"UserId",
"InstanceId" },
273 migrationBuilder.Sql(
274 "UPDATE Users SET AdministrationRights = p.AdministrationRights, InstanceManagerRights = p.InstanceManagerRights FROM Users u JOIN PermissionSets p ON u.Id = p.UserId WHERE p.UserId != NULL");
276 migrationBuilder.Sql(
277 "UPDATE Users SET AdministrationRights = p.AdministrationRights, InstanceManagerRights = p.InstanceManagerRights FROM Users u JOIN PermissionSets p ON u.GroupId = p.GroupId WHERE p.GroupId != NULL");
279 migrationBuilder.Sql(
280 "INSERT INTO InstanceUsers (UserId, InstanceId, InstanceUserRights, ByondRights, DreamDaemonRights, DreamMakerRights, RepositoryRights, ChatBotRights, ConfigurationRights) SELECT p.UserId, ips.InstanceId, ips.InstancePermissionSetRights, ips.ByondRights, ips.DreamDaemonRights, ips.DreamMakerRights, ips.RepositoryRights, ips.ChatBotRights, ips.ConfigurationRights FROM InstancePermissionSets ips JOIN PermissionSets p ON ips.PermissionSetId = p.Id WHERE p.UserId != NULL");
282 migrationBuilder.Sql(
283 "INSERT INTO InstanceUsers (UserId, InstanceId, InstanceUserRights, ByondRights, DreamDaemonRights, DreamMakerRights, RepositoryRights, ChatBotRights, ConfigurationRights) SELECT u.Id, ips.InstanceId, ips.InstancePermissionSetRights, ips.ByondRights, ips.DreamDaemonRights, ips.DreamMakerRights, ips.RepositoryRights, ips.ChatBotRights, ips.ConfigurationRights FROM InstancePermissionSets ips JOIN PermissionSets p ON ips.PermissionSetId = p.Id JOIN Users u ON p.GroupId = u.GroupId WHERE p.GroupId != NULL");
285 migrationBuilder.DropForeignKey(
286 name:
"FK_Users_Groups_GroupId",
289 migrationBuilder.DropTable(
290 name:
"InstancePermissionSets");
292 migrationBuilder.DropTable(
293 name:
"PermissionSets");
295 migrationBuilder.DropTable(
298 migrationBuilder.DropIndex(
299 name:
"IX_Users_GroupId",
302 migrationBuilder.DropColumn(