using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Diligent.WebAPI.Data.Migrations { public partial class AddedFileEntity : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Files", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(max)", nullable: false), Size = table.Column(type: "bigint", nullable: false), Extension = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Files", x => x.Id); }); migrationBuilder.CreateTable( name: "Tags", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Tags", x => x.Id); }); migrationBuilder.CreateTable( name: "Categories", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(max)", nullable: false), FileId = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Categories", x => x.Id); table.ForeignKey( name: "FK_Categories_Files_FileId", column: x => x.FileId, principalTable: "Files", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "FileEntityTag", columns: table => new { FilesId = table.Column(type: "int", nullable: false), TagsId = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_FileEntityTag", x => new { x.FilesId, x.TagsId }); table.ForeignKey( name: "FK_FileEntityTag_Files_FilesId", column: x => x.FilesId, principalTable: "Files", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_FileEntityTag_Tags_TagsId", column: x => x.TagsId, principalTable: "Tags", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Categories_FileId", table: "Categories", column: "FileId"); migrationBuilder.CreateIndex( name: "IX_FileEntityTag_TagsId", table: "FileEntityTag", column: "TagsId"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Categories"); migrationBuilder.DropTable( name: "FileEntityTag"); migrationBuilder.DropTable( name: "Files"); migrationBuilder.DropTable( name: "Tags"); } } }