14 protected override void Up(MigrationBuilder migrationBuilder)
16 ArgumentNullException.ThrowIfNull(migrationBuilder);
18 migrationBuilder.AlterColumn<
string>(
19 name:
"SystemIdentifier",
23 oldClrType: typeof(
string),
27 migrationBuilder.AlterColumn<
string>(
32 oldClrType: typeof(
string),
33 oldType:
"character varying(10000)",
36 migrationBuilder.AlterColumn<
string>(
37 name:
"CanonicalName",
41 oldClrType: typeof(
string),
44 migrationBuilder.AddColumn<
long>(
49 migrationBuilder.CreateTable(
53 Id = table.Column<
long>(nullable:
false)
54 .Annotation(
"Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
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(
"Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
68 AdministrationRights = table.Column<decimal>(nullable:
false),
69 InstanceManagerRights = table.Column<decimal>(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(
"Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
96 PermissionSetId = table.Column<
long>(nullable:
false),
97 InstancePermissionSetRights = table.Column<decimal>(nullable:
false),
98 ByondRights = table.Column<decimal>(nullable:
false),
99 DreamDaemonRights = table.Column<decimal>(nullable:
false),
100 DreamMakerRights = table.Column<decimal>(nullable:
false),
101 RepositoryRights = table.Column<decimal>(nullable:
false),
102 ChatBotRights = table.Column<decimal>(nullable:
false),
103 ConfigurationRights = table.Column<decimal>(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",
193 oldClrType: typeof(
string),
197 migrationBuilder.AlterColumn<
string>(
200 type:
"character varying(10000)",
203 oldClrType: typeof(
string),
206 migrationBuilder.AlterColumn<
string>(
207 name:
"CanonicalName",
211 oldClrType: typeof(
string),
214 migrationBuilder.AddColumn<decimal>(
215 name:
"AdministrationRights",
217 type:
"numeric(20,0)",
221 migrationBuilder.AddColumn<decimal>(
222 name:
"InstanceManagerRights",
224 type:
"numeric(20,0)",
228 migrationBuilder.CreateTable(
229 name:
"InstanceUsers",
230 columns: table =>
new
232 Id = table.Column<
long>(type:
"bigint", nullable:
false)
233 .Annotation(
"Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
234 ByondRights = table.Column<decimal>(type:
"numeric(20,0)", nullable:
false),
235 ChatBotRights = table.Column<decimal>(type:
"numeric(20,0)", nullable:
false),
236 ConfigurationRights = table.Column<decimal>(type:
"numeric(20,0)", nullable:
false),
237 DreamDaemonRights = table.Column<decimal>(type:
"numeric(20,0)", nullable:
false),
238 DreamMakerRights = table.Column<decimal>(type:
"numeric(20,0)", nullable:
false),
239 InstanceId = table.Column<
long>(type:
"bigint", nullable:
false),
240 InstanceUserRights = table.Column<decimal>(type:
"numeric(20,0)", nullable:
false),
241 RepositoryRights = table.Column<decimal>(type:
"numeric(20,0)", 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\" SET \"AdministrationRights\" = p.\"AdministrationRights\", \"InstanceManagerRights\" = p.\"InstanceManagerRights\" FROM \"Users\" u JOIN \"PermissionSets\" p ON u.\"Id\" = p.\"UserId\" WHERE p.\"UserId\" != NULL");
275 migrationBuilder.Sql(
276 "UPDATE \"Users\" SET \"AdministrationRights\" = p.\"AdministrationRights\", \"InstanceManagerRights\" = p.\"InstanceManagerRights\" FROM \"Users\" u JOIN \"PermissionSets\" p ON u.\"GroupId\" = p.\"GroupId\" WHERE p.\"GroupId\" != 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\" != 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\" != 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(