From f19dda9a42eee3a668354c95d67b5aa26d3a87ae Mon Sep 17 00:00:00 2001 From: haraldnilsen Date: Tue, 19 Sep 2023 09:35:10 +0200 Subject: [PATCH] :recycle: refactored - removed ID from db Co-authored-by: Sindre Kjelsrud --- ...cs => 20230919073410_V1__init.Designer.cs} | 14 ++++-------- ...V1__init.cs => 20230919073410_V1__init.cs} | 7 ++---- .../Migrations/MovieDbContextModelSnapshot.cs | 12 +++------- backend/Models/db/MovieDB.cs | 14 +----------- backend/Program.cs | 1 - backend/public/DbMockData.csv | 22 +++++++++---------- 6 files changed, 21 insertions(+), 49 deletions(-) rename backend/Migrations/{20230918090830_V1__init.Designer.cs => 20230919073410_V1__init.Designer.cs} (81%) rename backend/Migrations/{20230918090830_V1__init.cs => 20230919073410_V1__init.cs} (76%) diff --git a/backend/Migrations/20230918090830_V1__init.Designer.cs b/backend/Migrations/20230919073410_V1__init.Designer.cs similarity index 81% rename from backend/Migrations/20230918090830_V1__init.Designer.cs rename to backend/Migrations/20230919073410_V1__init.Designer.cs index 2953f58..a3df251 100644 --- a/backend/Migrations/20230918090830_V1__init.Designer.cs +++ b/backend/Migrations/20230919073410_V1__init.Designer.cs @@ -10,7 +10,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace backend.Migrations { [DbContext(typeof(MovieDbContext))] - [Migration("20230918090830_V1__init")] + [Migration("20230919073410_V1__init")] partial class V1__init { /// @@ -25,11 +25,8 @@ namespace backend.Migrations modelBuilder.Entity("backend.MovieDB", b => { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("imdbID") + .HasColumnType("text"); b.Property("Poster") .HasColumnType("text"); @@ -43,10 +40,7 @@ namespace backend.Migrations b.Property("Year") .HasColumnType("text"); - b.Property("imdbID") - .HasColumnType("text"); - - b.HasKey("Id"); + b.HasKey("imdbID"); b.ToTable("Movies"); }); diff --git a/backend/Migrations/20230918090830_V1__init.cs b/backend/Migrations/20230919073410_V1__init.cs similarity index 76% rename from backend/Migrations/20230918090830_V1__init.cs rename to backend/Migrations/20230919073410_V1__init.cs index 3307df4..5aad6da 100644 --- a/backend/Migrations/20230918090830_V1__init.cs +++ b/backend/Migrations/20230919073410_V1__init.cs @@ -1,5 +1,4 @@ using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable @@ -15,17 +14,15 @@ namespace backend.Migrations name: "Movies", columns: table => new { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + imdbID = table.Column(type: "text", nullable: false), Title = table.Column(type: "text", nullable: true), Year = table.Column(type: "text", nullable: true), - imdbID = table.Column(type: "text", nullable: true), Type = table.Column(type: "text", nullable: true), Poster = table.Column(type: "text", nullable: true) }, constraints: table => { - table.PrimaryKey("PK_Movies", x => x.Id); + table.PrimaryKey("PK_Movies", x => x.imdbID); }); } diff --git a/backend/Migrations/MovieDbContextModelSnapshot.cs b/backend/Migrations/MovieDbContextModelSnapshot.cs index c0199f0..a774f34 100644 --- a/backend/Migrations/MovieDbContextModelSnapshot.cs +++ b/backend/Migrations/MovieDbContextModelSnapshot.cs @@ -22,11 +22,8 @@ namespace backend.Migrations modelBuilder.Entity("backend.MovieDB", b => { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("imdbID") + .HasColumnType("text"); b.Property("Poster") .HasColumnType("text"); @@ -40,10 +37,7 @@ namespace backend.Migrations b.Property("Year") .HasColumnType("text"); - b.Property("imdbID") - .HasColumnType("text"); - - b.HasKey("Id"); + b.HasKey("imdbID"); b.ToTable("Movies"); }); diff --git a/backend/Models/db/MovieDB.cs b/backend/Models/db/MovieDB.cs index eb8dbd6..5a3bd95 100644 --- a/backend/Models/db/MovieDB.cs +++ b/backend/Models/db/MovieDB.cs @@ -6,11 +6,9 @@ using System.Globalization; namespace backend; -// [PrimaryKey(nameof(Id))] +[PrimaryKey(nameof(imdbID))] public class MovieDB { - public int Id { get; set; } - public string Title { get; set; } public string Year { get; set; } @@ -20,14 +18,4 @@ public class MovieDB public string Type { get; set; } public string Poster { get; set; } -} - - -public class MovieDBMap : ClassMap -{ - public MovieDBMap() - { - AutoMap(CultureInfo.InvariantCulture); - Map(m => m.Id).Ignore(); - } } \ No newline at end of file diff --git a/backend/Program.cs b/backend/Program.cs index ca33779..df9e8d6 100644 --- a/backend/Program.cs +++ b/backend/Program.cs @@ -32,7 +32,6 @@ using (var scope = services.CreateScope()) using (var reader = new StreamReader("public/DbMockData.csv")) using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) { - csv.Context.RegisterClassMap(); var records = csv.GetRecords().ToList(); context.Movies.AddRange(records); context.SaveChanges(); diff --git a/backend/public/DbMockData.csv b/backend/public/DbMockData.csv index 5b00b45..7d0bced 100644 --- a/backend/public/DbMockData.csv +++ b/backend/public/DbMockData.csv @@ -1,11 +1,11 @@ -Id,Title,Year,imdbID,Type,Poster -0,The Shawshank Redemption,1994,tt0111161,Movie,https://example.com/poster1.jpg -1,The Godfather,1972,tt0068646,Movie,https://example.com/poster2.jpg -2,Pulp Fiction,1994,tt0110912,Movie,https://example.com/poster3.jpg -3,The Dark Knight,2008,tt0468569,Movie,https://example.com/poster4.jpg -4,Schindler's List,1993,tt0108052,Movie,https://example.com/poster5.jpg -5,Forrest Gump,1994,tt0109830,Movie,https://example.com/poster6.jpg -6,Inception,2010,tt1375666,Movie,https://example.com/poster7.jpg -7,The Matrix,1999,tt0133093,Movie,https://example.com/poster8.jpg -8,The Lord of the Rings: The Fellowship of the Ring,2001,tt0120737,Movie,https://example.com/poster9.jpg -9,The Silence of the Lambs,1991,tt0102926,Movie,https://example.com/poster10.jpg +Title,Year,imdbID,Type,Poster +The Shawshank Redemption,1994,tt0111161,Movie,https://example.com/poster1.jpg +The Godfather,1972,tt0068646,Movie,https://example.com/poster2.jpg +Pulp Fiction,1994,tt0110912,Movie,https://example.com/poster3.jpg +The Dark Knight,2008,tt0468569,Movie,https://example.com/poster4.jpg +Schindler's List,1993,tt0108052,Movie,https://example.com/poster5.jpg +Forrest Gump,1994,tt0109830,Movie,https://example.com/poster6.jpg +Inception,2010,tt1375666,Movie,https://example.com/poster7.jpg +The Matrix,1999,tt0133093,Movie,https://example.com/poster8.jpg +The Lord of the Rings: The Fellowship of the Ring,2001,tt0120737,Movie,https://example.com/poster9.jpg +The Silence of the Lambs,1991,tt0102926,Movie,https://example.com/poster10.jpg