using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace QuotifyBE.Migrations { /// public partial class revised_model : 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: true) }, constraints: table => { table.PrimaryKey("PK_Categories", x => x.Id); }); migrationBuilder.CreateTable( name: "Images", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Url = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Images", 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), Email = table.Column(type: "text", nullable: false), PasswordHash = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "Quotes", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Text = table.Column(type: "text", nullable: false), Author = table.Column(type: "text", nullable: false), ImageId = table.Column(type: "integer", nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), LastUpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), UserId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Quotes", x => x.Id); table.ForeignKey( name: "FK_Quotes_Images_ImageId", column: x => x.ImageId, principalTable: "Images", principalColumn: "Id"); table.ForeignKey( name: "FK_Quotes_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "QuoteCategories", columns: table => new { QuoteId = table.Column(type: "integer", nullable: false), CategoryId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_QuoteCategories", x => new { x.QuoteId, x.CategoryId }); table.ForeignKey( name: "FK_QuoteCategories_Categories_CategoryId", column: x => x.CategoryId, principalTable: "Categories", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_QuoteCategories_Quotes_QuoteId", column: x => x.QuoteId, principalTable: "Quotes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_QuoteCategories_CategoryId", table: "QuoteCategories", column: "CategoryId"); migrationBuilder.CreateIndex( name: "IX_Quotes_ImageId", table: "Quotes", column: "ImageId"); migrationBuilder.CreateIndex( name: "IX_Quotes_UserId", table: "Quotes", column: "UserId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "QuoteCategories"); migrationBuilder.DropTable( name: "Categories"); migrationBuilder.DropTable( name: "Quotes"); migrationBuilder.DropTable( name: "Images"); migrationBuilder.DropTable( name: "Users"); } } }