summaryrefslogtreecommitdiff
path: root/Migrations/20230920052204_Security.cs
blob: 982cb97c10e2b8e33e26bd0d20d2be4f898dc812 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HyperBooru.Migrations
{
    /// <inheritdoc />
    public partial class Security : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Users_Objects_ObjectId",
                table: "Users");

            migrationBuilder.DropIndex(
                name: "IX_Users_Username",
                table: "Users");

            migrationBuilder.DropColumn(
                name: "Username",
                table: "Users");

            migrationBuilder.CreateTable(
                name: "Acls",
                columns: table => new
                {
                    ObjectId = table.Column<int>(type: "integer", nullable: false),
                    SubjectTempId1 = table.Column<int>(type: "integer", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Acls", x => x.ObjectId);
                    table.ForeignKey(
                        name: "FK_Acls_Objects_ObjectId",
                        column: x => x.ObjectId,
                        principalTable: "Objects",
                        principalColumn: "ObjectId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Principals",
                columns: table => new
                {
                    ObjectId = table.Column<int>(type: "integer", nullable: false),
                    Name = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Principals", x => x.ObjectId);
                });

            migrationBuilder.CreateTable(
                name: "AclRules",
                columns: table => new
                {
                    ObjectId = table.Column<int>(type: "integer", nullable: false),
                    PrincipalObjectId = table.Column<int>(type: "integer", nullable: false),
                    Action = table.Column<int>(type: "integer", nullable: false),
                    Permissions = table.Column<long>(type: "bigint", nullable: false),
                    AclObjectId = table.Column<int>(type: "integer", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AclRules", x => x.ObjectId);
                    table.ForeignKey(
                        name: "FK_AclRules_Acls_AclObjectId",
                        column: x => x.AclObjectId,
                        principalTable: "Acls",
                        principalColumn: "ObjectId");
                    table.ForeignKey(
                        name: "FK_AclRules_Principals_PrincipalObjectId",
                        column: x => x.PrincipalObjectId,
                        principalTable: "Principals",
                        principalColumn: "ObjectId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Groups",
                columns: table => new
                {
                    ObjectId = table.Column<int>(type: "integer", nullable: false),
                    HBPrincipalObjectId = table.Column<int>(type: "integer", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Groups", x => x.ObjectId);
                    table.ForeignKey(
                        name: "FK_Groups_Principals_HBPrincipalObjectId",
                        column: x => x.HBPrincipalObjectId,
                        principalTable: "Principals",
                        principalColumn: "ObjectId");
                });

            migrationBuilder.UpdateData(
                table: "Objects",
                keyColumn: "ObjectId",
                keyValue: -3,
                column: "Guid",
                value: new Guid("8fbbc2e9-0609-460a-ab3a-c3bdd10ab793"));

            migrationBuilder.InsertData(
                table: "Principals",
                columns: new[] { "ObjectId", "Name" },
                values: new object[] { -3, "admin" });

            migrationBuilder.CreateIndex(
                name: "IX_AclRules_AclObjectId",
                table: "AclRules",
                column: "AclObjectId");

            migrationBuilder.CreateIndex(
                name: "IX_AclRules_PrincipalObjectId",
                table: "AclRules",
                column: "PrincipalObjectId");

            migrationBuilder.CreateIndex(
                name: "IX_Groups_HBPrincipalObjectId",
                table: "Groups",
                column: "HBPrincipalObjectId");

            migrationBuilder.CreateIndex(
                name: "IX_Principals_Name",
                table: "Principals",
                column: "Name");

            migrationBuilder.AddForeignKey(
                name: "FK_Users_Principals_ObjectId",
                table: "Users",
                column: "ObjectId",
                principalTable: "Principals",
                principalColumn: "ObjectId",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Users_Principals_ObjectId",
                table: "Users");

            migrationBuilder.DropTable(
                name: "AclRules");

            migrationBuilder.DropTable(
                name: "Groups");

            migrationBuilder.DropTable(
                name: "Acls");

            migrationBuilder.DropTable(
                name: "Principals");

            migrationBuilder.AddColumn<string>(
                name: "Username",
                table: "Users",
                type: "text",
                nullable: false,
                defaultValue: "");

            migrationBuilder.UpdateData(
                table: "Objects",
                keyColumn: "ObjectId",
                keyValue: -3,
                column: "Guid",
                value: new Guid("4fa948f4-7c45-4f81-bb6b-e417491e6c96"));

            migrationBuilder.UpdateData(
                table: "Users",
                keyColumn: "ObjectId",
                keyValue: -3,
                column: "Username",
                value: "admin");

            migrationBuilder.CreateIndex(
                name: "IX_Users_Username",
                table: "Users",
                column: "Username");

            migrationBuilder.AddForeignKey(
                name: "FK_Users_Objects_ObjectId",
                table: "Users",
                column: "ObjectId",
                principalTable: "Objects",
                principalColumn: "ObjectId",
                onDelete: ReferentialAction.Cascade);
        }
    }
}