13 protected override void Up(MigrationBuilder migrationBuilder)
15 ArgumentNullException.ThrowIfNull(migrationBuilder);
17 migrationBuilder.AddColumn<
long>(
22 migrationBuilder.CreateTable(
26 Id = table.Column<
long>(nullable:
false)
27 .Annotation(
"Sqlite:Autoincrement",
true),
28 Name = table.Column<
string>(maxLength: 100, nullable:
false),
32 table.PrimaryKey(
"PK_Groups", x => x.Id);
35 migrationBuilder.CreateTable(
36 name:
"PermissionSets",
39 Id = table.Column<
long>(nullable:
false)
40 .Annotation(
"Sqlite:Autoincrement",
true),
41 AdministrationRights = table.Column<ulong>(nullable:
false),
42 InstanceManagerRights = table.Column<ulong>(nullable:
false),
43 UserId = table.Column<
long>(nullable:
true),
44 GroupId = table.Column<
long>(nullable:
true),
48 table.PrimaryKey(
"PK_PermissionSets", x => x.Id);
50 name:
"FK_PermissionSets_Groups_GroupId",
51 column: x => x.GroupId,
52 principalTable:
"Groups",
53 principalColumn:
"Id",
54 onDelete: ReferentialAction.Cascade);
56 name:
"FK_PermissionSets_Users_UserId",
57 column: x => x.UserId,
58 principalTable:
"Users",
59 principalColumn:
"Id",
60 onDelete: ReferentialAction.Cascade);
63 migrationBuilder.CreateTable(
64 name:
"InstancePermissionSets",
67 Id = table.Column<
long>(nullable:
false)
68 .Annotation(
"Sqlite:Autoincrement",
true),
69 PermissionSetId = table.Column<
long>(nullable:
false),
70 InstancePermissionSetRights = table.Column<ulong>(nullable:
false),
71 ByondRights = table.Column<ulong>(nullable:
false),
72 DreamDaemonRights = table.Column<ulong>(nullable:
false),
73 DreamMakerRights = table.Column<ulong>(nullable:
false),
74 RepositoryRights = table.Column<ulong>(nullable:
false),
75 ChatBotRights = table.Column<ulong>(nullable:
false),
76 ConfigurationRights = table.Column<ulong>(nullable:
false),
77 InstanceId = table.Column<
long>(nullable:
false),
81 table.PrimaryKey(
"PK_InstancePermissionSets", x => x.Id);
83 name:
"FK_InstancePermissionSets_Instances_InstanceId",
84 column: x => x.InstanceId,
85 principalTable:
"Instances",
86 principalColumn:
"Id",
87 onDelete: ReferentialAction.Cascade);
89 name:
"FK_InstancePermissionSets_PermissionSets_PermissionSetId",
90 column: x => x.PermissionSetId,
91 principalTable:
"PermissionSets",
92 principalColumn:
"Id",
93 onDelete: ReferentialAction.Cascade);
96 migrationBuilder.RenameTable(
100 migrationBuilder.CreateTable(
102 columns: table =>
new
104 Id = table.Column<
long>(nullable:
false)
105 .Annotation(
"Sqlite:Autoincrement",
true),
106 Enabled = table.Column<
bool>(nullable:
false),
107 CreatedAt = table.Column<DateTimeOffset>(nullable:
false),
108 SystemIdentifier = table.Column<
string>(nullable:
true),
109 Name = table.Column<
string>(maxLength: 10000, nullable:
false),
110 PasswordHash = table.Column<
string>(nullable:
true),
111 CreatedById = table.Column<
long>(nullable:
true),
112 GroupId = table.Column<
long>(nullable:
true),
113 CanonicalName = table.Column<
string>(nullable:
false),
114 LastPasswordUpdate = table.Column<DateTimeOffset>(nullable:
true),
116 constraints: table =>
118 table.PrimaryKey(
"PK_Users", x => x.Id);
120 name:
"FK_Users_Users_CreatedById",
121 column: x => x.CreatedById,
122 principalTable:
"Users",
123 principalColumn:
"Id",
124 onDelete: ReferentialAction.Restrict);
126 name:
"FK_Users_Groups_GroupId",
127 column: x => x.GroupId,
128 principalTable:
"Users",
129 principalColumn:
"Id",
130 onDelete: ReferentialAction.Restrict);
133 migrationBuilder.CreateIndex(
134 name:
"IX_Users_GroupId",
138 migrationBuilder.CreateIndex(
139 name:
"IX_Groups_Name",
144 migrationBuilder.CreateIndex(
145 name:
"IX_InstancePermissionSets_InstanceId",
146 table:
"InstancePermissionSets",
147 column:
"InstanceId");
149 migrationBuilder.CreateIndex(
150 name:
"IX_InstancePermissionSets_PermissionSetId_InstanceId",
151 table:
"InstancePermissionSets",
152 columns:
new[] {
"PermissionSetId",
"InstanceId" },
155 migrationBuilder.CreateIndex(
156 name:
"IX_PermissionSets_GroupId",
157 table:
"PermissionSets",
161 migrationBuilder.CreateIndex(
162 name:
"IX_PermissionSets_UserId",
163 table:
"PermissionSets",
167 migrationBuilder.Sql(
168 "INSERT INTO Users (Id, Enabled, CreatedAt, SystemIdentifier, Name, PasswordHash, CreatedById, CanonicalName, LastPasswordUpdate) SELECT Id, Enabled, CreatedAt, SystemIdentifier, Name, PasswordHash, CreatedById, CanonicalName, LastPasswordUpdate FROM Users_up");
170 migrationBuilder.Sql(
171 "INSERT INTO PermissionSets (UserId, AdministrationRights, InstanceManagerRights) SELECT Id, AdministrationRights, InstanceManagerRights FROM Users_up");
173 migrationBuilder.Sql(
174 "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");
176 migrationBuilder.DropTable(
177 name:
"InstanceUsers");
179 migrationBuilder.DropTable(
183 migrationBuilder.RenameTable(
185 newName:
"Users_up");
187 migrationBuilder.RenameTable(
193 protected override void Down(MigrationBuilder migrationBuilder)
195 ArgumentNullException.ThrowIfNull(migrationBuilder);
197 migrationBuilder.CreateTable(
198 name:
"InstanceUsers",
199 columns: table =>
new
201 Id = table.Column<
long>(type:
"INTEGER", nullable:
false)
202 .Annotation(
"Sqlite:Autoincrement",
true),
203 ByondRights = table.Column<ulong>(type:
"INTEGER", nullable:
false),
204 ChatBotRights = table.Column<ulong>(type:
"INTEGER", nullable:
false),
205 ConfigurationRights = table.Column<ulong>(type:
"INTEGER", nullable:
false),
206 DreamDaemonRights = table.Column<ulong>(type:
"INTEGER", nullable:
false),
207 DreamMakerRights = table.Column<ulong>(type:
"INTEGER", nullable:
false),
208 InstanceId = table.Column<
long>(type:
"INTEGER", nullable:
false),
209 InstanceUserRights = table.Column<ulong>(type:
"INTEGER", nullable:
false),
210 RepositoryRights = table.Column<ulong>(type:
"INTEGER", nullable:
false),
211 UserId = table.Column<
long>(type:
"INTEGER", nullable:
false),
213 constraints: table =>
215 table.PrimaryKey(
"PK_InstanceUsers", x => x.Id);
217 name:
"FK_InstanceUsers_Instances_InstanceId",
218 column: x => x.InstanceId,
219 principalTable:
"Instances",
220 principalColumn:
"Id",
221 onDelete: ReferentialAction.Cascade);
223 name:
"FK_InstanceUsers_Users_UserId",
224 column: x => x.UserId,
225 principalTable:
"Users",
226 principalColumn:
"Id",
227 onDelete: ReferentialAction.Cascade);
230 migrationBuilder.CreateIndex(
231 name:
"IX_InstanceUsers_InstanceId",
232 table:
"InstanceUsers",
233 column:
"InstanceId");
235 migrationBuilder.CreateIndex(
236 name:
"IX_InstanceUsers_UserId_InstanceId",
237 table:
"InstanceUsers",
238 columns:
new[] {
"UserId",
"InstanceId" },
241 migrationBuilder.RenameTable(
243 newName:
"Users_down");
245 migrationBuilder.CreateTable(
247 columns: table =>
new
249 Id = table.Column<
long>(nullable:
false)
250 .Annotation(
"Sqlite:Autoincrement",
true),
251 Enabled = table.Column<
bool>(nullable:
false),
252 CreatedAt = table.Column<DateTimeOffset>(nullable:
false),
253 SystemIdentifier = table.Column<
string>(nullable:
true),
254 Name = table.Column<
string>(maxLength: 100, nullable:
false),
255 AdministrationRights = table.Column<ulong>(nullable:
false),
256 InstanceManagerRights = table.Column<ulong>(nullable:
false),
257 PasswordHash = table.Column<
string>(nullable:
true),
258 CreatedById = table.Column<
long>(nullable:
true),
259 CanonicalName = table.Column<
string>(maxLength: 100, nullable:
false),
260 LastPasswordUpdate = table.Column<DateTimeOffset>(nullable:
true),
261 GroupId = table.Column<
long>(nullable:
true),
263 constraints: table =>
265 table.PrimaryKey(
"PK_Users", x => x.Id);
267 name:
"FK_Users_Users_CreatedById",
268 column: x => x.CreatedById,
269 principalTable:
"Users",
270 principalColumn:
"Id",
271 onDelete: ReferentialAction.Restrict);
274 migrationBuilder.Sql(
275 "INSERT INTO Users (Id, Enabled, CreatedAt, SystemIdentifier, Name, PasswordHash, CreatedById, CanonicalName, LastPasswordUpdate, AdministrationRights, InstanceManagerRights) SELECT u.Id, u.Enabled, u.CreatedAt, u.SystemIdentifier, u.Name, u.PasswordHash, u.CreatedById, u.CanonicalName, u.LastPasswordUpdate, p.AdministrationRights, p.InstanceManagerRights FROM Users_down u JOIN PermissionSets p ON p.UserId = u.Id WHERE u.GroupId = NULL");
277 migrationBuilder.Sql(
278 "INSERT INTO Users (Id, Enabled, CreatedAt, SystemIdentifier, Name, PasswordHash, CreatedById, CanonicalName, LastPasswordUpdate, AdministrationRights, InstanceManagerRights) SELECT u.Id, u.Enabled, u.CreatedAt, u.SystemIdentifier, u.Name, u.PasswordHash, u.CreatedById, u.CanonicalName, u.LastPasswordUpdate, p.AdministrationRights, p.InstanceManagerRights FROM Users_down u JOIN PermissionSets p ON p.GroupId = u.GroupId WHERE u.GroupId != NULL");
280 migrationBuilder.Sql(
281 "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");
283 migrationBuilder.Sql(
284 "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_down u ON p.GroupId = u.GroupId WHERE p.GroupId != NULL");
286 migrationBuilder.DropTable(
287 name:
"InstancePermissionSets");
289 migrationBuilder.DropTable(
290 name:
"PermissionSets");
292 migrationBuilder.DropTable(
295 migrationBuilder.DropTable(
298 migrationBuilder.RenameTable(
300 newName:
"Users_down");
302 migrationBuilder.RenameTable(