♻️ refactored - removed ID from db
Co-authored-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
		
							parent
							
								
									0fdc0e6af5
								
							
						
					
					
						commit
						f19dda9a42
					
				
					 6 changed files with 21 additions and 49 deletions
				
			
		|  | @ -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 | ||||
|     { | ||||
|         /// <inheritdoc /> | ||||
|  | @ -25,11 +25,8 @@ namespace backend.Migrations | |||
| 
 | ||||
|             modelBuilder.Entity("backend.MovieDB", b => | ||||
|                 { | ||||
|                     b.Property<int>("Id") | ||||
|                         .ValueGeneratedOnAdd() | ||||
|                         .HasColumnType("integer"); | ||||
| 
 | ||||
|                     NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); | ||||
|                     b.Property<string>("imdbID") | ||||
|                         .HasColumnType("text"); | ||||
| 
 | ||||
|                     b.Property<string>("Poster") | ||||
|                         .HasColumnType("text"); | ||||
|  | @ -43,10 +40,7 @@ namespace backend.Migrations | |||
|                     b.Property<string>("Year") | ||||
|                         .HasColumnType("text"); | ||||
| 
 | ||||
|                     b.Property<string>("imdbID") | ||||
|                         .HasColumnType("text"); | ||||
| 
 | ||||
|                     b.HasKey("Id"); | ||||
|                     b.HasKey("imdbID"); | ||||
| 
 | ||||
|                     b.ToTable("Movies"); | ||||
|                 }); | ||||
|  | @ -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<int>(type: "integer", nullable: false) | ||||
|                         .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), | ||||
|                     imdbID = table.Column<string>(type: "text", nullable: false), | ||||
|                     Title = table.Column<string>(type: "text", nullable: true), | ||||
|                     Year = table.Column<string>(type: "text", nullable: true), | ||||
|                     imdbID = table.Column<string>(type: "text", nullable: true), | ||||
|                     Type = table.Column<string>(type: "text", nullable: true), | ||||
|                     Poster = table.Column<string>(type: "text", nullable: true) | ||||
|                 }, | ||||
|                 constraints: table => | ||||
|                 { | ||||
|                     table.PrimaryKey("PK_Movies", x => x.Id); | ||||
|                     table.PrimaryKey("PK_Movies", x => x.imdbID); | ||||
|                 }); | ||||
|         } | ||||
| 
 | ||||
|  | @ -22,11 +22,8 @@ namespace backend.Migrations | |||
| 
 | ||||
|             modelBuilder.Entity("backend.MovieDB", b => | ||||
|                 { | ||||
|                     b.Property<int>("Id") | ||||
|                         .ValueGeneratedOnAdd() | ||||
|                         .HasColumnType("integer"); | ||||
| 
 | ||||
|                     NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); | ||||
|                     b.Property<string>("imdbID") | ||||
|                         .HasColumnType("text"); | ||||
| 
 | ||||
|                     b.Property<string>("Poster") | ||||
|                         .HasColumnType("text"); | ||||
|  | @ -40,10 +37,7 @@ namespace backend.Migrations | |||
|                     b.Property<string>("Year") | ||||
|                         .HasColumnType("text"); | ||||
| 
 | ||||
|                     b.Property<string>("imdbID") | ||||
|                         .HasColumnType("text"); | ||||
| 
 | ||||
|                     b.HasKey("Id"); | ||||
|                     b.HasKey("imdbID"); | ||||
| 
 | ||||
|                     b.ToTable("Movies"); | ||||
|                 }); | ||||
|  |  | |||
|  | @ -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<MovieDB> | ||||
| { | ||||
|     public MovieDBMap() | ||||
|     { | ||||
|         AutoMap(CultureInfo.InvariantCulture); | ||||
|         Map(m => m.Id).Ignore(); | ||||
|     } | ||||
| } | ||||
|  | @ -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<MovieDBMap>(); | ||||
|             var records = csv.GetRecords<MovieDB>().ToList(); | ||||
|             context.Movies.AddRange(records); | ||||
|             context.SaveChanges(); | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
| 
 | 
		Reference in a new issue
	
	 haraldnilsen
						haraldnilsen