using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace BulletinBoardDatabase.Migrations { /// public partial class InitialCreate : 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) }, constraints: table => { table.PrimaryKey("PK_Categories", x => x.Id); }); migrationBuilder.CreateTable( name: "Regions", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), RegionName = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Regions", 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), Surname = table.Column(type: "text", nullable: false), PhoneNumber = table.Column(type: "text", nullable: false), Email = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "Cities", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), CityName = table.Column(type: "text", nullable: false), RegionId = table.Column(type: "integer", nullable: false), CityId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Cities", x => x.Id); table.ForeignKey( name: "FK_Cities_Regions_CityId", column: x => x.CityId, principalTable: "Regions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Announcements", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Title = table.Column(type: "text", nullable: false), Description = table.Column(type: "text", nullable: false), StartDate = table.Column(type: "timestamp with time zone", nullable: false), ReviewText = table.Column(type: "text", nullable: true), ReviewRating = table.Column(type: "integer", nullable: true), UserId = table.Column(type: "integer", nullable: false), CategoryId = table.Column(type: "integer", nullable: false), RegionId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Announcements", x => x.Id); table.ForeignKey( name: "FK_Announcements_Categories_CategoryId", column: x => x.CategoryId, principalTable: "Categories", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Announcements_Regions_RegionId", column: x => x.RegionId, principalTable: "Regions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Announcements_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Announcements_CategoryId", table: "Announcements", column: "CategoryId"); migrationBuilder.CreateIndex( name: "IX_Announcements_RegionId", table: "Announcements", column: "RegionId"); migrationBuilder.CreateIndex( name: "IX_Announcements_UserId", table: "Announcements", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Cities_CityId", table: "Cities", column: "CityId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Announcements"); migrationBuilder.DropTable( name: "Cities"); migrationBuilder.DropTable( name: "Categories"); migrationBuilder.DropTable( name: "Users"); migrationBuilder.DropTable( name: "Regions"); } } }