14 protected override void Up(MigrationBuilder migrationBuilder)
16 ArgumentNullException.ThrowIfNull(migrationBuilder);
18 migrationBuilder.AlterColumn<
string>(
19 name:
"SystemIdentifier",
23 oldClrType: typeof(
string),
24 oldType:
"varchar(255) CHARACTER SET utf8mb4",
27 migrationBuilder.AlterColumn<
string>(
32 oldClrType: typeof(
string),
33 oldType:
"longtext CHARACTER SET utf8mb4",
36 migrationBuilder.AlterColumn<
string>(
37 name:
"CanonicalName",
41 oldClrType: typeof(
string),
42 oldType:
"varchar(255) CHARACTER SET utf8mb4");
44 migrationBuilder.AddColumn<
long>(
49 migrationBuilder.CreateTable(
53 Id = table.Column<
long>(nullable:
false)
54 .Annotation(
"MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
55 Name = table.Column<
string>(maxLength: 100, nullable:
false),
59 table.PrimaryKey(
"PK_Groups", x => x.Id);
62 migrationBuilder.CreateTable(
63 name:
"PermissionSets",
66 Id = table.Column<
long>(nullable:
false)
67 .Annotation(
"MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
68 AdministrationRights = table.Column<ulong>(nullable:
false),
69 InstanceManagerRights = table.Column<ulong>(nullable:
false),
70 UserId = table.Column<
long>(nullable:
true),
71 GroupId = table.Column<
long>(nullable:
true),
75 table.PrimaryKey(
"PK_PermissionSets", x => x.Id);
77 name:
"FK_PermissionSets_Groups_GroupId",
78 column: x => x.GroupId,
79 principalTable:
"Groups",
80 principalColumn:
"Id",
81 onDelete: ReferentialAction.Cascade);
83 name:
"FK_PermissionSets_Users_UserId",
84 column: x => x.UserId,
85 principalTable:
"Users",
86 principalColumn:
"Id",
87 onDelete: ReferentialAction.Cascade);
90 migrationBuilder.CreateTable(
91 name:
"InstancePermissionSets",
94 Id = table.Column<
long>(nullable:
false)
95 .Annotation(
"MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
96 PermissionSetId = table.Column<
long>(nullable:
false),
97 InstancePermissionSetRights = table.Column<ulong>(nullable:
false),
98 ByondRights = table.Column<ulong>(nullable:
false),
99 DreamDaemonRights = table.Column<ulong>(nullable:
false),
100 DreamMakerRights = table.Column<ulong>(nullable:
false),
101 RepositoryRights = table.Column<ulong>(nullable:
false),
102 ChatBotRights = table.Column<ulong>(nullable:
false),
103 ConfigurationRights = table.Column<ulong>(nullable:
false),
104 InstanceId = table.Column<
long>(nullable:
false),
106 constraints: table =>
108 table.PrimaryKey(
"PK_InstancePermissionSets", x => x.Id);
110 name:
"FK_InstancePermissionSets_Instances_InstanceId",
111 column: x => x.InstanceId,
112 principalTable:
"Instances",
113 principalColumn:
"Id",
114 onDelete: ReferentialAction.Cascade);
116 name:
"FK_InstancePermissionSets_PermissionSets_PermissionSetId",
117 column: x => x.PermissionSetId,
118 principalTable:
"PermissionSets",
119 principalColumn:
"Id",
120 onDelete: ReferentialAction.Cascade);
123 migrationBuilder.CreateIndex(
124 name:
"IX_Users_GroupId",
128 migrationBuilder.CreateIndex(
129 name:
"IX_Groups_Name",
134 migrationBuilder.CreateIndex(
135 name:
"IX_InstancePermissionSets_InstanceId",
136 table:
"InstancePermissionSets",
137 column:
"InstanceId");
139 migrationBuilder.CreateIndex(
140 name:
"IX_InstancePermissionSets_PermissionSetId_InstanceId",
141 table:
"InstancePermissionSets",
142 columns:
new[] {
"PermissionSetId",
"InstanceId" },
145 migrationBuilder.CreateIndex(
146 name:
"IX_PermissionSets_GroupId",
147 table:
"PermissionSets",
151 migrationBuilder.CreateIndex(
152 name:
"IX_PermissionSets_UserId",
153 table:
"PermissionSets",
157 migrationBuilder.AddForeignKey(
158 name:
"FK_Users_Groups_GroupId",
161 principalTable:
"Groups",
162 principalColumn:
"Id",
163 onDelete: ReferentialAction.Restrict);
165 migrationBuilder.Sql(
166 "INSERT INTO PermissionSets (UserId, AdministrationRights, InstanceManagerRights) SELECT Id, AdministrationRights, InstanceManagerRights FROM Users");
168 migrationBuilder.Sql(
169 "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");
171 migrationBuilder.DropTable(
172 name:
"InstanceUsers");
174 migrationBuilder.DropColumn(
175 name:
"AdministrationRights",
178 migrationBuilder.DropColumn(
179 name:
"InstanceManagerRights",
184 protected override void Down(MigrationBuilder migrationBuilder)
186 ArgumentNullException.ThrowIfNull(migrationBuilder);
188 migrationBuilder.AlterColumn<
string>(
189 name:
"SystemIdentifier",
191 type:
"varchar(255) CHARACTER SET utf8mb4",
193 oldClrType: typeof(
string),
197 migrationBuilder.AlterColumn<
string>(
200 type:
"longtext CHARACTER SET utf8mb4",
203 oldClrType: typeof(
string),
206 migrationBuilder.AlterColumn<
string>(
207 name:
"CanonicalName",
209 type:
"varchar(255) CHARACTER SET utf8mb4",
211 oldClrType: typeof(
string),
214 migrationBuilder.AddColumn<ulong>(
215 name:
"AdministrationRights",
217 type:
"bigint unsigned",
221 migrationBuilder.AddColumn<ulong>(
222 name:
"InstanceManagerRights",
224 type:
"bigint unsigned",
228 migrationBuilder.CreateTable(
229 name:
"InstanceUsers",
230 columns: table =>
new
232 Id = table.Column<
long>(type:
"bigint", nullable:
false)
233 .Annotation(
"MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
234 ByondRights = table.Column<ulong>(type:
"bigint unsigned", nullable:
false),
235 ChatBotRights = table.Column<ulong>(type:
"bigint unsigned", nullable:
false),
236 ConfigurationRights = table.Column<ulong>(type:
"bigint unsigned", nullable:
false),
237 DreamDaemonRights = table.Column<ulong>(type:
"bigint unsigned", nullable:
false),
238 DreamMakerRights = table.Column<ulong>(type:
"bigint unsigned", nullable:
false),
239 InstanceId = table.Column<
long>(type:
"bigint", nullable:
false),
240 InstanceUserRights = table.Column<ulong>(type:
"bigint unsigned", nullable:
false),
241 RepositoryRights = table.Column<ulong>(type:
"bigint unsigned", nullable:
false),
242 UserId = table.Column<
long>(type:
"bigint", nullable:
false),
244 constraints: table =>
246 table.PrimaryKey(
"PK_InstanceUsers", x => x.Id);
248 name:
"FK_InstanceUsers_Instances_InstanceId",
249 column: x => x.InstanceId,
250 principalTable:
"Instances",
251 principalColumn:
"Id",
252 onDelete: ReferentialAction.Cascade);
254 name:
"FK_InstanceUsers_Users_UserId",
255 column: x => x.UserId,
256 principalTable:
"Users",
257 principalColumn:
"Id",
258 onDelete: ReferentialAction.Cascade);
261 migrationBuilder.CreateIndex(
262 name:
"IX_InstanceUsers_InstanceId",
263 table:
"InstanceUsers",
264 column:
"InstanceId");
266 migrationBuilder.CreateIndex(
267 name:
"IX_InstanceUsers_UserId_InstanceId",
268 table:
"InstanceUsers",
269 columns:
new[] {
"UserId",
"InstanceId" },
272 migrationBuilder.Sql(
273 "UPDATE Users AS u JOIN PermissionSets p ON u.Id = p.UserId SET u.AdministrationRights = p.AdministrationRights, u.InstanceManagerRights = p.InstanceManagerRights WHERE p.UserId IS NOT NULL");
275 migrationBuilder.Sql(
276 "UPDATE Users AS u JOIN PermissionSets p ON u.GroupId = p.GroupId SET u.AdministrationRights = p.AdministrationRights, u.InstanceManagerRights = p.InstanceManagerRights WHERE p.GroupId IS NOT NULL");
278 migrationBuilder.Sql(
279 "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 IS NOT NULL");
281 migrationBuilder.Sql(
282 "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 IS NOT NULL");
284 migrationBuilder.DropForeignKey(
285 name:
"FK_Users_Groups_GroupId",
288 migrationBuilder.DropTable(
289 name:
"InstancePermissionSets");
291 migrationBuilder.DropTable(
292 name:
"PermissionSets");
294 migrationBuilder.DropTable(
297 migrationBuilder.DropIndex(
298 name:
"IX_Users_GroupId",
301 migrationBuilder.DropColumn(