using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace VoidCat.Migrations { /// public partial class Init : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Files", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "text", nullable: true), Size = table.Column(type: "numeric(20,0)", nullable: false), Uploaded = table.Column(type: "timestamp with time zone", nullable: false), Description = table.Column(type: "text", nullable: true), MimeType = table.Column(type: "text", nullable: false, defaultValue: "application/octet-stream"), Digest = table.Column(type: "text", nullable: true), EditSecret = table.Column(type: "uuid", nullable: false), Expires = table.Column(type: "timestamp with time zone", nullable: true), Storage = table.Column(type: "text", nullable: false, defaultValue: "local-disk"), EncryptionParams = table.Column(type: "text", nullable: true), MagnetLink = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Files", x => x.Id); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Email = table.Column(type: "text", nullable: false), Password = table.Column(type: "text", nullable: true), Created = table.Column(type: "timestamp with time zone", nullable: false), LastLogin = table.Column(type: "timestamp with time zone", nullable: true), Avatar = table.Column(type: "text", nullable: true), DisplayName = table.Column(type: "text", nullable: false, defaultValue: "void user"), Flags = table.Column(type: "integer", nullable: false), Storage = table.Column(type: "text", nullable: false, defaultValue: "local-disk"), AuthType = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "VirusScanResult", columns: table => new { Id = table.Column(type: "uuid", nullable: false), FileId = table.Column(type: "uuid", nullable: false), ScanTime = table.Column(type: "timestamp with time zone", nullable: false), Scanner = table.Column(type: "text", nullable: false), Score = table.Column(type: "numeric", nullable: false), Names = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_VirusScanResult", x => x.Id); table.ForeignKey( name: "FK_VirusScanResult_Files_FileId", column: x => x.FileId, principalTable: "Files", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "ApiKey", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), Token = table.Column(type: "text", nullable: false), Expiry = table.Column(type: "timestamp with time zone", nullable: false), Created = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ApiKey", x => x.Id); table.ForeignKey( name: "FK_ApiKey_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserFiles", columns: table => new { FileId = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserFiles", x => new { x.UserId, x.FileId }); table.ForeignKey( name: "FK_UserFiles_Files_FileId", column: x => x.FileId, principalTable: "Files", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserFiles_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserRoles", columns: table => new { UserId = table.Column(type: "uuid", nullable: false), Role = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserRoles", x => new { x.UserId, x.Role }); table.ForeignKey( name: "FK_UserRoles_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UsersAuthToken", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), Provider = table.Column(type: "text", nullable: false), AccessToken = table.Column(type: "text", nullable: false), TokenType = table.Column(type: "text", nullable: false), Expires = table.Column(type: "timestamp with time zone", nullable: false), RefreshToken = table.Column(type: "text", nullable: false), Scope = table.Column(type: "text", nullable: false), IdToken = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_UsersAuthToken", x => x.Id); table.ForeignKey( name: "FK_UsersAuthToken_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_ApiKey_UserId", table: "ApiKey", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Files_Uploaded", table: "Files", column: "Uploaded"); migrationBuilder.CreateIndex( name: "IX_UserFiles_FileId", table: "UserFiles", column: "FileId", unique: true); migrationBuilder.CreateIndex( name: "IX_Users_Email", table: "Users", column: "Email"); migrationBuilder.CreateIndex( name: "IX_UsersAuthToken_UserId", table: "UsersAuthToken", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_VirusScanResult_FileId", table: "VirusScanResult", column: "FileId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "ApiKey"); migrationBuilder.DropTable( name: "UserFiles"); migrationBuilder.DropTable( name: "UserRoles"); migrationBuilder.DropTable( name: "UsersAuthToken"); migrationBuilder.DropTable( name: "VirusScanResult"); migrationBuilder.DropTable( name: "Users"); migrationBuilder.DropTable( name: "Files"); } } }