From 2c9c2cc3b414115bca9b6c63ca7b20d49a8a8ec1 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Thu, 15 Sep 2022 20:55:44 -0500 Subject: Agregar autor --- .../20220915213615_InitialCreate.Designer.cs | 56 ----------- Migrations/20220915213615_InitialCreate.cs | 36 ------- Migrations/20220915225908_AddBookTitle.Designer.cs | 60 ------------ Migrations/20220915225908_AddBookTitle.cs | 26 ------ ...20915235337_DropBookPublicationDate.Designer.cs | 57 ------------ .../20220915235337_DropBookPublicationDate.cs | 27 ------ ...220915235413_AddBookPublicationYear.Designer.cs | 60 ------------ .../20220915235413_AddBookPublicationYear.cs | 26 ------ .../20220916003408_InitialMigration.Designer.cs | 54 +++++++++++ Migrations/20220916003408_InitialMigration.cs | 36 +++++++ Migrations/20220916003555_AddBookTable.Designer.cs | 103 +++++++++++++++++++++ Migrations/20220916003555_AddBookTable.cs | 49 ++++++++++ Migrations/20220916004044_RenameTables.Designer.cs | 103 +++++++++++++++++++++ Migrations/20220916004044_RenameTables.cs | 101 ++++++++++++++++++++ Migrations/LibraryContextModelSnapshot.cs | 50 +++++++++- 15 files changed, 492 insertions(+), 352 deletions(-) delete mode 100644 Migrations/20220915213615_InitialCreate.Designer.cs delete mode 100644 Migrations/20220915213615_InitialCreate.cs delete mode 100644 Migrations/20220915225908_AddBookTitle.Designer.cs delete mode 100644 Migrations/20220915225908_AddBookTitle.cs delete mode 100644 Migrations/20220915235337_DropBookPublicationDate.Designer.cs delete mode 100644 Migrations/20220915235337_DropBookPublicationDate.cs delete mode 100644 Migrations/20220915235413_AddBookPublicationYear.Designer.cs delete mode 100644 Migrations/20220915235413_AddBookPublicationYear.cs create mode 100644 Migrations/20220916003408_InitialMigration.Designer.cs create mode 100644 Migrations/20220916003408_InitialMigration.cs create mode 100644 Migrations/20220916003555_AddBookTable.Designer.cs create mode 100644 Migrations/20220916003555_AddBookTable.cs create mode 100644 Migrations/20220916004044_RenameTables.Designer.cs create mode 100644 Migrations/20220916004044_RenameTables.cs (limited to 'Migrations') diff --git a/Migrations/20220915213615_InitialCreate.Designer.cs b/Migrations/20220915213615_InitialCreate.Designer.cs deleted file mode 100644 index 9c88b15..0000000 --- a/Migrations/20220915213615_InitialCreate.Designer.cs +++ /dev/null @@ -1,56 +0,0 @@ -// -using System; -using LibraryAPI.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace LibraryAPI.Migrations -{ - [DbContext(typeof(LibraryContext))] - [Migration("20220915213615_InitialCreate")] - partial class InitialCreate - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.9") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("LibraryAPI.Models.Book", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Edition") - .HasColumnType("integer"); - - b.Property("Genres") - .IsRequired() - .HasColumnType("text[]"); - - b.Property("ISBN") - .IsRequired() - .HasColumnType("text"); - - b.Property("PublicationDate") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("Books"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Migrations/20220915213615_InitialCreate.cs b/Migrations/20220915213615_InitialCreate.cs deleted file mode 100644 index ae3abe2..0000000 --- a/Migrations/20220915213615_InitialCreate.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace LibraryAPI.Migrations -{ - public partial class InitialCreate : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Books", - columns: table => new - { - Id = table.Column(type: "bigint", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - PublicationDate = table.Column(type: "timestamp with time zone", nullable: false), - Genres = table.Column(type: "text[]", nullable: false), - Edition = table.Column(type: "integer", nullable: false), - ISBN = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Books", x => x.Id); - }); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Books"); - } - } -} diff --git a/Migrations/20220915225908_AddBookTitle.Designer.cs b/Migrations/20220915225908_AddBookTitle.Designer.cs deleted file mode 100644 index 1208102..0000000 --- a/Migrations/20220915225908_AddBookTitle.Designer.cs +++ /dev/null @@ -1,60 +0,0 @@ -// -using System; -using LibraryAPI.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace LibraryAPI.Migrations -{ - [DbContext(typeof(LibraryContext))] - [Migration("20220915225908_AddBookTitle")] - partial class AddBookTitle - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.9") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("LibraryAPI.Models.Book", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Edition") - .HasColumnType("integer"); - - b.Property("Genres") - .IsRequired() - .HasColumnType("text[]"); - - b.Property("ISBN") - .IsRequired() - .HasColumnType("text"); - - b.Property("PublicationDate") - .HasColumnType("timestamp with time zone"); - - b.Property("Title") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("Books"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Migrations/20220915225908_AddBookTitle.cs b/Migrations/20220915225908_AddBookTitle.cs deleted file mode 100644 index ef3f3a7..0000000 --- a/Migrations/20220915225908_AddBookTitle.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace LibraryAPI.Migrations -{ - public partial class AddBookTitle : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "Title", - table: "Books", - type: "text", - nullable: false, - defaultValue: ""); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "Title", - table: "Books"); - } - } -} diff --git a/Migrations/20220915235337_DropBookPublicationDate.Designer.cs b/Migrations/20220915235337_DropBookPublicationDate.Designer.cs deleted file mode 100644 index e97f909..0000000 --- a/Migrations/20220915235337_DropBookPublicationDate.Designer.cs +++ /dev/null @@ -1,57 +0,0 @@ -// -using System; -using LibraryAPI.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace LibraryAPI.Migrations -{ - [DbContext(typeof(LibraryContext))] - [Migration("20220915235337_DropBookPublicationDate")] - partial class DropBookPublicationDate - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.9") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("LibraryAPI.Models.Book", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Edition") - .HasColumnType("integer"); - - b.Property("Genres") - .IsRequired() - .HasColumnType("text[]"); - - b.Property("ISBN") - .IsRequired() - .HasColumnType("text"); - - b.Property("Title") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("Books"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Migrations/20220915235337_DropBookPublicationDate.cs b/Migrations/20220915235337_DropBookPublicationDate.cs deleted file mode 100644 index 4d16267..0000000 --- a/Migrations/20220915235337_DropBookPublicationDate.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace LibraryAPI.Migrations -{ - public partial class DropBookPublicationDate : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "PublicationDate", - table: "Books"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "PublicationDate", - table: "Books", - type: "timestamp with time zone", - nullable: false, - defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); - } - } -} diff --git a/Migrations/20220915235413_AddBookPublicationYear.Designer.cs b/Migrations/20220915235413_AddBookPublicationYear.Designer.cs deleted file mode 100644 index 072bb5c..0000000 --- a/Migrations/20220915235413_AddBookPublicationYear.Designer.cs +++ /dev/null @@ -1,60 +0,0 @@ -// -using System; -using LibraryAPI.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace LibraryAPI.Migrations -{ - [DbContext(typeof(LibraryContext))] - [Migration("20220915235413_AddBookPublicationYear")] - partial class AddBookPublicationYear - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.9") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("LibraryAPI.Models.Book", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Edition") - .HasColumnType("integer"); - - b.Property("Genres") - .IsRequired() - .HasColumnType("text[]"); - - b.Property("ISBN") - .IsRequired() - .HasColumnType("text"); - - b.Property("PublicationYear") - .HasColumnType("integer"); - - b.Property("Title") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("Books"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Migrations/20220915235413_AddBookPublicationYear.cs b/Migrations/20220915235413_AddBookPublicationYear.cs deleted file mode 100644 index 12bf4b3..0000000 --- a/Migrations/20220915235413_AddBookPublicationYear.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace LibraryAPI.Migrations -{ - public partial class AddBookPublicationYear : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "PublicationYear", - table: "Books", - type: "integer", - nullable: false, - defaultValue: 0); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "PublicationYear", - table: "Books"); - } - } -} diff --git a/Migrations/20220916003408_InitialMigration.Designer.cs b/Migrations/20220916003408_InitialMigration.Designer.cs new file mode 100644 index 0000000..a4985b4 --- /dev/null +++ b/Migrations/20220916003408_InitialMigration.Designer.cs @@ -0,0 +1,54 @@ +// +using System; +using LibraryAPI.Models; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace LibraryAPI.Migrations +{ + [DbContext(typeof(LibraryContext))] + [Migration("20220916003408_InitialMigration")] + partial class InitialMigration + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("LibraryAPI.Models.Author", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Country") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("YearOfBirth") + .HasColumnType("integer"); + + b.Property("languages") + .HasColumnType("text[]"); + + b.HasKey("Id"); + + b.ToTable("Author"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20220916003408_InitialMigration.cs b/Migrations/20220916003408_InitialMigration.cs new file mode 100644 index 0000000..620f926 --- /dev/null +++ b/Migrations/20220916003408_InitialMigration.cs @@ -0,0 +1,36 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace LibraryAPI.Migrations +{ + public partial class InitialMigration : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Author", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Country = table.Column(type: "text", nullable: true), + Name = table.Column(type: "text", nullable: true), + YearOfBirth = table.Column(type: "integer", nullable: false), + languages = table.Column(type: "text[]", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Author", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Author"); + } + } +} diff --git a/Migrations/20220916003555_AddBookTable.Designer.cs b/Migrations/20220916003555_AddBookTable.Designer.cs new file mode 100644 index 0000000..b4a1609 --- /dev/null +++ b/Migrations/20220916003555_AddBookTable.Designer.cs @@ -0,0 +1,103 @@ +// +using System; +using LibraryAPI.Models; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace LibraryAPI.Migrations +{ + [DbContext(typeof(LibraryContext))] + [Migration("20220916003555_AddBookTable")] + partial class AddBookTable + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("LibraryAPI.Models.Author", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Country") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("YearOfBirth") + .HasColumnType("integer"); + + b.Property("languages") + .HasColumnType("text[]"); + + b.HasKey("Id"); + + b.ToTable("Author"); + }); + + modelBuilder.Entity("LibraryAPI.Models.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AuthorId") + .HasColumnType("bigint"); + + b.Property("Edition") + .HasColumnType("integer"); + + b.Property("Genres") + .HasColumnType("text[]"); + + b.Property("ISBN") + .HasColumnType("text"); + + b.Property("PublicationYear") + .HasColumnType("integer"); + + b.Property("Title") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("AuthorId"); + + b.ToTable("Book"); + }); + + modelBuilder.Entity("LibraryAPI.Models.Book", b => + { + b.HasOne("LibraryAPI.Models.Author", "Author") + .WithMany("Books") + .HasForeignKey("AuthorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Author"); + }); + + modelBuilder.Entity("LibraryAPI.Models.Author", b => + { + b.Navigation("Books"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20220916003555_AddBookTable.cs b/Migrations/20220916003555_AddBookTable.cs new file mode 100644 index 0000000..4612dee --- /dev/null +++ b/Migrations/20220916003555_AddBookTable.cs @@ -0,0 +1,49 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace LibraryAPI.Migrations +{ + public partial class AddBookTable : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Book", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + AuthorId = table.Column(type: "bigint", nullable: false), + PublicationYear = table.Column(type: "integer", nullable: false), + Genres = table.Column(type: "text[]", nullable: true), + Edition = table.Column(type: "integer", nullable: false), + ISBN = table.Column(type: "text", nullable: true), + Title = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Book", x => x.Id); + table.ForeignKey( + name: "FK_Book_Author_AuthorId", + column: x => x.AuthorId, + principalTable: "Author", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Book_AuthorId", + table: "Book", + column: "AuthorId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Book"); + } + } +} diff --git a/Migrations/20220916004044_RenameTables.Designer.cs b/Migrations/20220916004044_RenameTables.Designer.cs new file mode 100644 index 0000000..a6d3439 --- /dev/null +++ b/Migrations/20220916004044_RenameTables.Designer.cs @@ -0,0 +1,103 @@ +// +using System; +using LibraryAPI.Models; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace LibraryAPI.Migrations +{ + [DbContext(typeof(LibraryContext))] + [Migration("20220916004044_RenameTables")] + partial class RenameTables + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("LibraryAPI.Models.Author", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Country") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("YearOfBirth") + .HasColumnType("integer"); + + b.Property("languages") + .HasColumnType("text[]"); + + b.HasKey("Id"); + + b.ToTable("Authors"); + }); + + modelBuilder.Entity("LibraryAPI.Models.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AuthorId") + .HasColumnType("bigint"); + + b.Property("Edition") + .HasColumnType("integer"); + + b.Property("Genres") + .HasColumnType("text[]"); + + b.Property("ISBN") + .HasColumnType("text"); + + b.Property("PublicationYear") + .HasColumnType("integer"); + + b.Property("Title") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("AuthorId"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("LibraryAPI.Models.Book", b => + { + b.HasOne("LibraryAPI.Models.Author", "Author") + .WithMany("Books") + .HasForeignKey("AuthorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Author"); + }); + + modelBuilder.Entity("LibraryAPI.Models.Author", b => + { + b.Navigation("Books"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20220916004044_RenameTables.cs b/Migrations/20220916004044_RenameTables.cs new file mode 100644 index 0000000..c5f984b --- /dev/null +++ b/Migrations/20220916004044_RenameTables.cs @@ -0,0 +1,101 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace LibraryAPI.Migrations +{ + public partial class RenameTables : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Book_Author_AuthorId", + table: "Book"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Book", + table: "Book"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Author", + table: "Author"); + + migrationBuilder.RenameTable( + name: "Book", + newName: "Books"); + + migrationBuilder.RenameTable( + name: "Author", + newName: "Authors"); + + migrationBuilder.RenameIndex( + name: "IX_Book_AuthorId", + table: "Books", + newName: "IX_Books_AuthorId"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Books", + table: "Books", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Authors", + table: "Authors", + column: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Books_Authors_AuthorId", + table: "Books", + column: "AuthorId", + principalTable: "Authors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Books_Authors_AuthorId", + table: "Books"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Books", + table: "Books"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Authors", + table: "Authors"); + + migrationBuilder.RenameTable( + name: "Books", + newName: "Book"); + + migrationBuilder.RenameTable( + name: "Authors", + newName: "Author"); + + migrationBuilder.RenameIndex( + name: "IX_Books_AuthorId", + table: "Book", + newName: "IX_Book_AuthorId"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Book", + table: "Book", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Author", + table: "Author", + column: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Book_Author_AuthorId", + table: "Book", + column: "AuthorId", + principalTable: "Author", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/Migrations/LibraryContextModelSnapshot.cs b/Migrations/LibraryContextModelSnapshot.cs index d340ff6..0fa3e9b 100644 --- a/Migrations/LibraryContextModelSnapshot.cs +++ b/Migrations/LibraryContextModelSnapshot.cs @@ -22,6 +22,31 @@ namespace LibraryAPI.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + modelBuilder.Entity("LibraryAPI.Models.Author", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Country") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("YearOfBirth") + .HasColumnType("integer"); + + b.Property("languages") + .HasColumnType("text[]"); + + b.HasKey("Id"); + + b.ToTable("Authors"); + }); + modelBuilder.Entity("LibraryAPI.Models.Book", b => { b.Property("Id") @@ -30,29 +55,46 @@ namespace LibraryAPI.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("AuthorId") + .HasColumnType("bigint"); + b.Property("Edition") .HasColumnType("integer"); b.Property("Genres") - .IsRequired() .HasColumnType("text[]"); b.Property("ISBN") - .IsRequired() .HasColumnType("text"); b.Property("PublicationYear") - .IsRequired() .HasColumnType("integer"); b.Property("Title") - .IsRequired() .HasColumnType("text"); b.HasKey("Id"); + b.HasIndex("AuthorId"); + b.ToTable("Books"); }); + + modelBuilder.Entity("LibraryAPI.Models.Book", b => + { + b.HasOne("LibraryAPI.Models.Author", "Author") + .WithMany("Books") + .HasForeignKey("AuthorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Author"); + }); + + modelBuilder.Entity("LibraryAPI.Models.Author", b => + { + b.Navigation("Books"); + }); #pragma warning restore 612, 618 } } -- cgit v1.2.3