using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace NexusReader.Data.Migrations { /// public partial class NormalizeAuthor : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.DropColumn( name: "Author", table: "Ebooks"); migrationBuilder.AddColumn( name: "AuthorId", table: "Ebooks", type: "integer", nullable: false, defaultValue: 0); migrationBuilder.CreateTable( name: "Authors", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "character varying(255)", maxLength: 255, nullable: false) }, constraints: table => { table.PrimaryKey("PK_Authors", x => x.Id); }); migrationBuilder.CreateIndex( name: "IX_Ebooks_AuthorId", table: "Ebooks", column: "AuthorId"); migrationBuilder.AddForeignKey( name: "FK_Ebooks_Authors_AuthorId", table: "Ebooks", column: "AuthorId", principalTable: "Authors", principalColumn: "Id", onDelete: ReferentialAction.Restrict); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_Ebooks_Authors_AuthorId", table: "Ebooks"); migrationBuilder.DropTable( name: "Authors"); migrationBuilder.DropIndex( name: "IX_Ebooks_AuthorId", table: "Ebooks"); migrationBuilder.DropColumn( name: "AuthorId", table: "Ebooks"); migrationBuilder.AddColumn( name: "Author", table: "Ebooks", type: "character varying(255)", maxLength: 255, nullable: false, defaultValue: ""); } } }