using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace BlogDatabase.Migrations { /// public partial class mig4 : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Categories", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false), UserId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Categories", x => x.Id); }); migrationBuilder.CreateTable( name: "Roles", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Roles", x => x.Id); }); migrationBuilder.CreateTable( name: "Topics", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false), UserId = table.Column(type: "integer", nullable: false), CategoryId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Topics", x => x.Id); table.ForeignKey( name: "FK_Topics_Categories_CategoryId", column: x => x.CategoryId, principalTable: "Categories", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Username = table.Column(type: "text", nullable: false), Email = table.Column(type: "text", nullable: false), Password = table.Column(type: "text", nullable: false), RegistrationDate = table.Column(type: "timestamp with time zone", nullable: false), RoleId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); table.ForeignKey( name: "FK_Users_Roles_RoleId", column: x => x.RoleId, principalTable: "Roles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Messages", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Text = table.Column(type: "text", nullable: false), Date = table.Column(type: "timestamp with time zone", nullable: false), UserId = table.Column(type: "integer", nullable: false), TopicId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Messages", x => x.Id); table.ForeignKey( name: "FK_Messages_Topics_TopicId", column: x => x.TopicId, principalTable: "Topics", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Messages_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Messages_TopicId", table: "Messages", column: "TopicId"); migrationBuilder.CreateIndex( name: "IX_Messages_UserId", table: "Messages", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Topics_CategoryId", table: "Topics", column: "CategoryId"); migrationBuilder.CreateIndex( name: "IX_Users_RoleId", table: "Users", column: "RoleId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Messages"); migrationBuilder.DropTable( name: "Topics"); migrationBuilder.DropTable( name: "Users"); migrationBuilder.DropTable( name: "Categories"); migrationBuilder.DropTable( name: "Roles"); } } }