using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace BlogDatabaseImplement.Migrations { /// public partial class Start : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Tags", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false), NewsId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Tags", x => x.Id); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false), DateCreate = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "News", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Title = table.Column(type: "text", nullable: false), Text = table.Column(type: "text", nullable: false), UserId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_News", x => x.Id); table.ForeignKey( name: "FK_News_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Comments", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Text = table.Column(type: "text", nullable: false), NewsId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Comments", x => x.Id); table.ForeignKey( name: "FK_Comments_News_NewsId", column: x => x.NewsId, principalTable: "News", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "NewsTags", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), NewsId = table.Column(type: "integer", nullable: false), TagId = table.Column(type: "integer", nullable: false), Count = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_NewsTags", x => x.Id); table.ForeignKey( name: "FK_NewsTags_News_NewsId", column: x => x.NewsId, principalTable: "News", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_NewsTags_Tags_TagId", column: x => x.TagId, principalTable: "Tags", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Comments_NewsId", table: "Comments", column: "NewsId"); migrationBuilder.CreateIndex( name: "IX_News_UserId", table: "News", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_NewsTags_NewsId", table: "NewsTags", column: "NewsId"); migrationBuilder.CreateIndex( name: "IX_NewsTags_TagId", table: "NewsTags", column: "TagId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Comments"); migrationBuilder.DropTable( name: "NewsTags"); migrationBuilder.DropTable( name: "News"); migrationBuilder.DropTable( name: "Tags"); migrationBuilder.DropTable( name: "Users"); } } }