|
| 1 | +using System; |
| 2 | +using Microsoft.EntityFrameworkCore.Migrations; |
| 3 | + |
| 4 | +#nullable disable |
| 5 | + |
| 6 | +namespace MyBlog.Migrations |
| 7 | +{ |
| 8 | + /// <inheritdoc /> |
| 9 | + public partial class InitialCreate : Migration |
| 10 | + { |
| 11 | + /// <inheritdoc /> |
| 12 | + protected override void Up(MigrationBuilder migrationBuilder) |
| 13 | + { |
| 14 | + migrationBuilder.CreateTable( |
| 15 | + name: "Users", |
| 16 | + columns: table => new |
| 17 | + { |
| 18 | + ID = table.Column<int>(type: "int", nullable: false) |
| 19 | + .Annotation("SqlServer:Identity", "1, 1"), |
| 20 | + UserName = table.Column<string>(type: "nvarchar(max)", nullable: true), |
| 21 | + Email = table.Column<string>(type: "nvarchar(max)", nullable: true), |
| 22 | + PasswordHash = table.Column<string>(type: "nvarchar(max)", nullable: true), |
| 23 | + CreationDate = table.Column<DateTime>(type: "datetime2", nullable: true) |
| 24 | + }, |
| 25 | + constraints: table => |
| 26 | + { |
| 27 | + table.PrimaryKey("PK_Users", x => x.ID); |
| 28 | + }); |
| 29 | + |
| 30 | + migrationBuilder.CreateTable( |
| 31 | + name: "Posts", |
| 32 | + columns: table => new |
| 33 | + { |
| 34 | + ID = table.Column<int>(type: "int", nullable: false) |
| 35 | + .Annotation("SqlServer:Identity", "1, 1"), |
| 36 | + AuthorId = table.Column<int>(type: "int", nullable: false), |
| 37 | + Title = table.Column<string>(type: "nvarchar(max)", nullable: true), |
| 38 | + Content = table.Column<string>(type: "nvarchar(max)", nullable: true), |
| 39 | + AuthoredDate = table.Column<DateTime>(type: "datetime2", nullable: true) |
| 40 | + }, |
| 41 | + constraints: table => |
| 42 | + { |
| 43 | + table.PrimaryKey("PK_Posts", x => x.ID); |
| 44 | + table.ForeignKey( |
| 45 | + name: "FK_Posts_Users_AuthorId", |
| 46 | + column: x => x.AuthorId, |
| 47 | + principalTable: "Users", |
| 48 | + principalColumn: "ID", |
| 49 | + onDelete: ReferentialAction.Cascade); |
| 50 | + }); |
| 51 | + |
| 52 | + migrationBuilder.CreateTable( |
| 53 | + name: "Comments", |
| 54 | + columns: table => new |
| 55 | + { |
| 56 | + ID = table.Column<int>(type: "int", nullable: false) |
| 57 | + .Annotation("SqlServer:Identity", "1, 1"), |
| 58 | + Content = table.Column<string>(type: "nvarchar(max)", nullable: true), |
| 59 | + DatePosted = table.Column<DateTime>(type: "datetime2", nullable: true), |
| 60 | + AuthorID = table.Column<int>(type: "int", nullable: true), |
| 61 | + PostID = table.Column<int>(type: "int", nullable: true) |
| 62 | + }, |
| 63 | + constraints: table => |
| 64 | + { |
| 65 | + table.PrimaryKey("PK_Comments", x => x.ID); |
| 66 | + table.ForeignKey( |
| 67 | + name: "FK_Comments_Posts_PostID", |
| 68 | + column: x => x.PostID, |
| 69 | + principalTable: "Posts", |
| 70 | + principalColumn: "ID"); |
| 71 | + table.ForeignKey( |
| 72 | + name: "FK_Comments_Users_AuthorID", |
| 73 | + column: x => x.AuthorID, |
| 74 | + principalTable: "Users", |
| 75 | + principalColumn: "ID"); |
| 76 | + }); |
| 77 | + |
| 78 | + migrationBuilder.CreateIndex( |
| 79 | + name: "IX_Comments_AuthorID", |
| 80 | + table: "Comments", |
| 81 | + column: "AuthorID"); |
| 82 | + |
| 83 | + migrationBuilder.CreateIndex( |
| 84 | + name: "IX_Comments_PostID", |
| 85 | + table: "Comments", |
| 86 | + column: "PostID"); |
| 87 | + |
| 88 | + migrationBuilder.CreateIndex( |
| 89 | + name: "IX_Posts_AuthorId", |
| 90 | + table: "Posts", |
| 91 | + column: "AuthorId"); |
| 92 | + } |
| 93 | + |
| 94 | + /// <inheritdoc /> |
| 95 | + protected override void Down(MigrationBuilder migrationBuilder) |
| 96 | + { |
| 97 | + migrationBuilder.DropTable( |
| 98 | + name: "Comments"); |
| 99 | + |
| 100 | + migrationBuilder.DropTable( |
| 101 | + name: "Posts"); |
| 102 | + |
| 103 | + migrationBuilder.DropTable( |
| 104 | + name: "Users"); |
| 105 | + } |
| 106 | + } |
| 107 | +} |
0 commit comments