| 1 | using KernelRecordsMVC.Domain.Enums;
|
|---|
| 2 | using KernelRecordsMVC.Domain.Models;
|
|---|
| 3 | using KernelRecordsMVC.Models;
|
|---|
| 4 | using Microsoft.EntityFrameworkCore;
|
|---|
| 5 |
|
|---|
| 6 | namespace KernelRecordsMVC.Infrastructure.Data;
|
|---|
| 7 |
|
|---|
| 8 | public class KernelRecordsContext : DbContext
|
|---|
| 9 | {
|
|---|
| 10 | public KernelRecordsContext(DbContextOptions<KernelRecordsContext> options)
|
|---|
| 11 | : base(options)
|
|---|
| 12 | {
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | public DbSet<User> Users => Set<User>();
|
|---|
| 16 | public DbSet<Admin> Admins => Set<Admin>();
|
|---|
| 17 | public DbSet<Consumer> Consumers => Set<Consumer>();
|
|---|
| 18 |
|
|---|
| 19 | public DbSet<Artist> Artists => Set<Artist>();
|
|---|
| 20 | public DbSet<Release> Releases => Set<Release>();
|
|---|
| 21 | public DbSet<Album> Albums => Set<Album>();
|
|---|
| 22 | public DbSet<SingleRelease> SingleReleases => Set<SingleRelease>();
|
|---|
| 23 | public DbSet<Song> Songs => Set<Song>();
|
|---|
| 24 |
|
|---|
| 25 | public DbSet<Product> Products => Set<Product>();
|
|---|
| 26 |
|
|---|
| 27 | public DbSet<Order> Orders => Set<Order>();
|
|---|
| 28 | public DbSet<OrderProduct> OrderProducts => Set<OrderProduct>();
|
|---|
| 29 |
|
|---|
| 30 | public DbSet<Wishlist> Wishlists => Set<Wishlist>();
|
|---|
| 31 | public DbSet<WishlistProduct> WishlistProducts => Set<WishlistProduct>();
|
|---|
| 32 |
|
|---|
| 33 | public DbSet<Modification> Modifications => Set<Modification>();
|
|---|
| 34 | public DbSet<ModificationProduct> ModificationProducts
|
|---|
| 35 | => Set<ModificationProduct>();
|
|---|
| 36 |
|
|---|
| 37 | public DbSet<ReleaseArtist> ReleaseArtists => Set<ReleaseArtist>();
|
|---|
| 38 | public DbSet<SongArtist> SongArtists => Set<SongArtist>();
|
|---|
| 39 | public DbSet<AlbumSong> AlbumSongs => Set<AlbumSong>();
|
|---|
| 40 |
|
|---|
| 41 | /*
|
|---|
| 42 | public DbSet<SingleFeature> SingleFeatures => Set<SingleFeature>();
|
|---|
| 43 | */
|
|---|
| 44 |
|
|---|
| 45 | protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|---|
| 46 | {
|
|---|
| 47 | base.OnModelCreating(modelBuilder);
|
|---|
| 48 |
|
|---|
| 49 | // ==========================================
|
|---|
| 50 | // DATABASE SCHEMA
|
|---|
| 51 | // ==========================================
|
|---|
| 52 |
|
|---|
| 53 | modelBuilder.HasDefaultSchema("project");
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | // ==========================================
|
|---|
| 57 | // POSTGRESQL ENUMS
|
|---|
| 58 | // ==========================================
|
|---|
| 59 |
|
|---|
| 60 | modelBuilder.HasPostgresEnum<AdminType>("project", "admin_type");
|
|---|
| 61 | modelBuilder.HasPostgresEnum<ProductFormat>("project", "product_format");
|
|---|
| 62 | modelBuilder.HasPostgresEnum<PaymentMethodType>("project", "payment_method_type");
|
|---|
| 63 | modelBuilder.HasPostgresEnum<OrderStatusType>("project", "order_status_type");
|
|---|
| 64 | modelBuilder.HasPostgresEnum<ModificationType>("project", "modification_type");
|
|---|
| 65 | modelBuilder.HasPostgresEnum<ArtistReleaseType>("project", "artist_release_type");
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | // ==========================================
|
|---|
| 69 | // USERS
|
|---|
| 70 | // ==========================================
|
|---|
| 71 |
|
|---|
| 72 | modelBuilder.Entity<User>(entity =>
|
|---|
| 73 | {
|
|---|
| 74 | entity.ToTable("users");
|
|---|
| 75 |
|
|---|
| 76 | entity.HasKey(x => x.UserId);
|
|---|
| 77 |
|
|---|
| 78 | entity.Property(x => x.UserId)
|
|---|
| 79 | .HasColumnName("user_id")
|
|---|
| 80 | .ValueGeneratedOnAdd();
|
|---|
| 81 |
|
|---|
| 82 | entity.Property(x => x.Email)
|
|---|
| 83 | .HasColumnName("email")
|
|---|
| 84 | .IsRequired();
|
|---|
| 85 |
|
|---|
| 86 | entity.Property(x => x.Username)
|
|---|
| 87 | .HasColumnName("username")
|
|---|
| 88 | .IsRequired();
|
|---|
| 89 |
|
|---|
| 90 | entity.Property(x => x.Password)
|
|---|
| 91 | .HasColumnName("password")
|
|---|
| 92 | .IsRequired();
|
|---|
| 93 |
|
|---|
| 94 | entity.Property(x => x.DateCreated)
|
|---|
| 95 | .HasColumnName("date_created")
|
|---|
| 96 | .HasColumnType("date");
|
|---|
| 97 |
|
|---|
| 98 | entity.Property(x => x.ShippingAddress)
|
|---|
| 99 | .HasColumnName("shipping_address");
|
|---|
| 100 |
|
|---|
| 101 | entity.Property(x => x.TelephoneNumber)
|
|---|
| 102 | .HasColumnName("telephone_number");
|
|---|
| 103 |
|
|---|
| 104 | entity.HasIndex(x => x.Email)
|
|---|
| 105 | .IsUnique();
|
|---|
| 106 |
|
|---|
| 107 | entity.HasIndex(x => x.Username)
|
|---|
| 108 | .IsUnique();
|
|---|
| 109 | });
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 | // ==========================================
|
|---|
| 113 | // ADMINS
|
|---|
| 114 | // ==========================================
|
|---|
| 115 |
|
|---|
| 116 | modelBuilder.Entity<Admin>(entity =>
|
|---|
| 117 | {
|
|---|
| 118 | entity.ToTable("admins");
|
|---|
| 119 |
|
|---|
| 120 | entity.HasKey(x => x.UserId);
|
|---|
| 121 |
|
|---|
| 122 | entity.Property(x => x.UserId)
|
|---|
| 123 | .HasColumnName("user_id");
|
|---|
| 124 |
|
|---|
| 125 | entity.Property(x => x.Type)
|
|---|
| 126 | .HasColumnName("type")
|
|---|
| 127 | .HasColumnType("project.admin_type");
|
|---|
| 128 |
|
|---|
| 129 | entity.Property(x => x.DiscountPercentage)
|
|---|
| 130 | .HasColumnName("discount_percentage")
|
|---|
| 131 | .HasColumnType("numeric");
|
|---|
| 132 |
|
|---|
| 133 | entity.HasOne(x => x.User)
|
|---|
| 134 | .WithOne(x => x.Admin)
|
|---|
| 135 | .HasForeignKey<Admin>(x => x.UserId)
|
|---|
| 136 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 137 | });
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 | // ==========================================
|
|---|
| 141 | // CONSUMERS
|
|---|
| 142 | // ==========================================
|
|---|
| 143 |
|
|---|
| 144 | modelBuilder.Entity<Consumer>(entity =>
|
|---|
| 145 | {
|
|---|
| 146 | entity.ToTable("consumers");
|
|---|
| 147 |
|
|---|
| 148 | entity.HasKey(x => x.UserId);
|
|---|
| 149 |
|
|---|
| 150 | entity.Property(x => x.UserId)
|
|---|
| 151 | .HasColumnName("user_id");
|
|---|
| 152 |
|
|---|
| 153 | entity.Property(x => x.PointsCollected)
|
|---|
| 154 | .HasColumnName("points_collected");
|
|---|
| 155 |
|
|---|
| 156 | entity.HasOne(x => x.User)
|
|---|
| 157 | .WithOne(x => x.Consumer)
|
|---|
| 158 | .HasForeignKey<Consumer>(x => x.UserId)
|
|---|
| 159 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 160 | });
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 | // ==========================================
|
|---|
| 164 | // ARTISTS
|
|---|
| 165 | // ==========================================
|
|---|
| 166 |
|
|---|
| 167 | modelBuilder.Entity<Artist>(entity =>
|
|---|
| 168 | {
|
|---|
| 169 | entity.ToTable("artists");
|
|---|
| 170 |
|
|---|
| 171 | entity.HasKey(x => x.ArtistId);
|
|---|
| 172 |
|
|---|
| 173 | entity.Property(x => x.ArtistId)
|
|---|
| 174 | .HasColumnName("artist_id");
|
|---|
| 175 |
|
|---|
| 176 | entity.Property(x => x.ArtistName)
|
|---|
| 177 | .HasColumnName("artist_name")
|
|---|
| 178 | .IsRequired();
|
|---|
| 179 |
|
|---|
| 180 | entity.Property(x => x.ArtistDescription)
|
|---|
| 181 | .HasColumnName("artist_description");
|
|---|
| 182 |
|
|---|
| 183 | entity.Property(x => x.ArtistPhoto)
|
|---|
| 184 | .HasColumnName("artist_photo");
|
|---|
| 185 | });
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 | // ==========================================
|
|---|
| 189 | // RELEASES
|
|---|
| 190 | // ==========================================
|
|---|
| 191 |
|
|---|
| 192 | modelBuilder.Entity<Release>(entity =>
|
|---|
| 193 | {
|
|---|
| 194 | entity.ToTable("releases");
|
|---|
| 195 |
|
|---|
| 196 | entity.HasKey(x => x.ReleaseId);
|
|---|
| 197 |
|
|---|
| 198 | entity.Property(x => x.ReleaseId)
|
|---|
| 199 | .HasColumnName("release_id");
|
|---|
| 200 |
|
|---|
| 201 | entity.Property(x => x.Title)
|
|---|
| 202 | .HasColumnName("title")
|
|---|
| 203 | .IsRequired();
|
|---|
| 204 |
|
|---|
| 205 | entity.Property(x => x.RecordLabel)
|
|---|
| 206 | .HasColumnName("record_label");
|
|---|
| 207 |
|
|---|
| 208 | entity.Property(x => x.Genre)
|
|---|
| 209 | .HasColumnName("genre")
|
|---|
| 210 | .IsRequired();
|
|---|
| 211 |
|
|---|
| 212 | entity.Property(x => x.ReleaseDate)
|
|---|
| 213 | .HasColumnName("release_date")
|
|---|
| 214 | .HasColumnType("date");
|
|---|
| 215 |
|
|---|
| 216 | entity.Property(x => x.CoverPhoto)
|
|---|
| 217 | .HasColumnName("cover_photo")
|
|---|
| 218 | .IsRequired();
|
|---|
| 219 | });
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 | // ==========================================
|
|---|
| 223 | // ALBUMS
|
|---|
| 224 | // ==========================================
|
|---|
| 225 |
|
|---|
| 226 | modelBuilder.Entity<Album>(entity =>
|
|---|
| 227 | {
|
|---|
| 228 | entity.ToTable("albums");
|
|---|
| 229 |
|
|---|
| 230 | entity.HasKey(x => x.ReleaseId);
|
|---|
| 231 |
|
|---|
| 232 | entity.Property(x => x.ReleaseId)
|
|---|
| 233 | .HasColumnName("release_id");
|
|---|
| 234 |
|
|---|
| 235 | entity.HasOne(x => x.Release)
|
|---|
| 236 | .WithOne(x => x.Album)
|
|---|
| 237 | .HasForeignKey<Album>(x => x.ReleaseId)
|
|---|
| 238 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 239 | });
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 | // ==========================================
|
|---|
| 243 | // SINGLE RELEASES
|
|---|
| 244 | // ==========================================
|
|---|
| 245 |
|
|---|
| 246 | modelBuilder.Entity<SingleRelease>(entity =>
|
|---|
| 247 | {
|
|---|
| 248 | entity.ToTable("single_releases");
|
|---|
| 249 |
|
|---|
| 250 | entity.HasKey(x => x.ReleaseId);
|
|---|
| 251 |
|
|---|
| 252 | entity.Property(x => x.ReleaseId)
|
|---|
| 253 | .HasColumnName("release_id");
|
|---|
| 254 |
|
|---|
| 255 | entity.Property(x => x.Duration)
|
|---|
| 256 | .HasColumnName("duration")
|
|---|
| 257 | .IsRequired();
|
|---|
| 258 |
|
|---|
| 259 | entity.HasOne(x => x.Release)
|
|---|
| 260 | .WithOne(x => x.SingleRelease)
|
|---|
| 261 | .HasForeignKey<SingleRelease>(x => x.ReleaseId)
|
|---|
| 262 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 263 | });
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 | // ==========================================
|
|---|
| 267 | // SONGS
|
|---|
| 268 | // ==========================================
|
|---|
| 269 |
|
|---|
| 270 | modelBuilder.Entity<Song>(entity =>
|
|---|
| 271 | {
|
|---|
| 272 | entity.ToTable("songs");
|
|---|
| 273 |
|
|---|
| 274 | entity.HasKey(x => x.SongId);
|
|---|
| 275 |
|
|---|
| 276 | entity.Property(x => x.SongId)
|
|---|
| 277 | .HasColumnName("song_id");
|
|---|
| 278 |
|
|---|
| 279 | entity.Property(x => x.SongName)
|
|---|
| 280 | .HasColumnName("song_name")
|
|---|
| 281 | .IsRequired();
|
|---|
| 282 |
|
|---|
| 283 | entity.Property(x => x.SongDuration)
|
|---|
| 284 | .HasColumnName("song_duration")
|
|---|
| 285 | .IsRequired();
|
|---|
| 286 | });
|
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 | // ==========================================
|
|---|
| 290 | // PRODUCTS
|
|---|
| 291 | // ==========================================
|
|---|
| 292 |
|
|---|
| 293 | modelBuilder.Entity<Product>(entity =>
|
|---|
| 294 | {
|
|---|
| 295 | entity.ToTable("products");
|
|---|
| 296 |
|
|---|
| 297 | entity.HasKey(x => x.ProductId);
|
|---|
| 298 |
|
|---|
| 299 | entity.Property(x => x.ProductId)
|
|---|
| 300 | .HasColumnName("product_id");
|
|---|
| 301 |
|
|---|
| 302 | entity.Property(x => x.ReleaseId)
|
|---|
| 303 | .HasColumnName("release_id");
|
|---|
| 304 |
|
|---|
| 305 | entity.Property(x => x.Format)
|
|---|
| 306 | .HasColumnName("format")
|
|---|
| 307 | .HasColumnType("project.product_format");
|
|---|
| 308 |
|
|---|
| 309 | entity.Property(x => x.Price)
|
|---|
| 310 | .HasColumnName("price")
|
|---|
| 311 | .HasColumnType("numeric");
|
|---|
| 312 |
|
|---|
| 313 | entity.Property(x => x.ProductDescription)
|
|---|
| 314 | .HasColumnName("product_description")
|
|---|
| 315 | .IsRequired();
|
|---|
| 316 |
|
|---|
| 317 | entity.Property(x => x.Stock)
|
|---|
| 318 | .HasColumnName("stock");
|
|---|
| 319 |
|
|---|
| 320 | entity.HasOne(x => x.Release)
|
|---|
| 321 | .WithMany(x => x.Products)
|
|---|
| 322 | .HasForeignKey(x => x.ReleaseId)
|
|---|
| 323 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 324 | });
|
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 | // ==========================================
|
|---|
| 328 | // ORDERS
|
|---|
| 329 | // ==========================================
|
|---|
| 330 |
|
|---|
| 331 | modelBuilder.Entity<Order>(entity =>
|
|---|
| 332 | {
|
|---|
| 333 | entity.ToTable("orders");
|
|---|
| 334 |
|
|---|
| 335 | entity.HasKey(x => x.OrderId);
|
|---|
| 336 |
|
|---|
| 337 | entity.Property(x => x.OrderId)
|
|---|
| 338 | .HasColumnName("order_id")
|
|---|
| 339 | .ValueGeneratedOnAdd();
|
|---|
| 340 |
|
|---|
| 341 | entity.Property(x => x.UserId)
|
|---|
| 342 | .HasColumnName("user_id");
|
|---|
| 343 |
|
|---|
| 344 | entity.Property(x => x.PaymentMethod)
|
|---|
| 345 | .HasColumnName("payment_method")
|
|---|
| 346 | .HasColumnType("project.payment_method_type");
|
|---|
| 347 |
|
|---|
| 348 | entity.Property(x => x.PurchaseDate)
|
|---|
| 349 | .HasColumnName("purchase_date")
|
|---|
| 350 | .HasColumnType("date");
|
|---|
| 351 |
|
|---|
| 352 | entity.Property(x => x.PointsEarned)
|
|---|
| 353 | .HasColumnName("points_earned");
|
|---|
| 354 |
|
|---|
| 355 | entity.Property(x => x.PointsUsed)
|
|---|
| 356 | .HasColumnName("points_used");
|
|---|
| 357 |
|
|---|
| 358 | entity.Property(x => x.Status)
|
|---|
| 359 | .HasColumnName("status")
|
|---|
| 360 | .HasColumnType("project.order_status_type");
|
|---|
| 361 |
|
|---|
| 362 | entity.HasOne(x => x.User)
|
|---|
| 363 | .WithMany(x => x.Orders)
|
|---|
| 364 | .HasForeignKey(x => x.UserId)
|
|---|
| 365 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 366 | });
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 | // ==========================================
|
|---|
| 370 | // ORDER_PRODUCTS
|
|---|
| 371 | // ==========================================
|
|---|
| 372 |
|
|---|
| 373 | modelBuilder.Entity<OrderProduct>(entity =>
|
|---|
| 374 | {
|
|---|
| 375 | entity.ToTable("order_products");
|
|---|
| 376 |
|
|---|
| 377 | entity.HasKey(x => new
|
|---|
| 378 | {
|
|---|
| 379 | x.OrderId,
|
|---|
| 380 | x.ProductId
|
|---|
| 381 | });
|
|---|
| 382 |
|
|---|
| 383 | entity.Property(x => x.OrderId)
|
|---|
| 384 | .HasColumnName("order_id");
|
|---|
| 385 |
|
|---|
| 386 | entity.Property(x => x.ProductId)
|
|---|
| 387 | .HasColumnName("product_id");
|
|---|
| 388 |
|
|---|
| 389 | entity.Property(x => x.PriceAtPurchase)
|
|---|
| 390 | .HasColumnName("price_at_purchase")
|
|---|
| 391 | .HasColumnType("numeric");
|
|---|
| 392 |
|
|---|
| 393 | entity.Property(x => x.Quantity)
|
|---|
| 394 | .HasColumnName("quantity");
|
|---|
| 395 |
|
|---|
| 396 | entity.HasOne(x => x.Order)
|
|---|
| 397 | .WithMany(x => x.OrderProducts)
|
|---|
| 398 | .HasForeignKey(x => x.OrderId)
|
|---|
| 399 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 400 |
|
|---|
| 401 | entity.HasOne(x => x.Product)
|
|---|
| 402 | .WithMany(x => x.OrderProducts)
|
|---|
| 403 | .HasForeignKey(x => x.ProductId)
|
|---|
| 404 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 405 | });
|
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 | // ==========================================
|
|---|
| 409 | // WISHLISTS
|
|---|
| 410 | // ==========================================
|
|---|
| 411 |
|
|---|
| 412 | modelBuilder.Entity<Wishlist>(entity =>
|
|---|
| 413 | {
|
|---|
| 414 | entity.ToTable("wishlists");
|
|---|
| 415 |
|
|---|
| 416 | entity.HasKey(x => x.WishlistId);
|
|---|
| 417 |
|
|---|
| 418 | entity.Property(x => x.WishlistId)
|
|---|
| 419 | .HasColumnName("wishlist_id");
|
|---|
| 420 |
|
|---|
| 421 | entity.Property(x => x.UserId)
|
|---|
| 422 | .HasColumnName("user_id");
|
|---|
| 423 |
|
|---|
| 424 | entity.HasIndex(x => x.UserId)
|
|---|
| 425 | .IsUnique();
|
|---|
| 426 |
|
|---|
| 427 | entity.HasOne(x => x.User)
|
|---|
| 428 | .WithOne(x => x.Wishlist)
|
|---|
| 429 | .HasForeignKey<Wishlist>(x => x.UserId)
|
|---|
| 430 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 431 | });
|
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 | // ==========================================
|
|---|
| 435 | // WISHLIST_PRODUCTS
|
|---|
| 436 | // ==========================================
|
|---|
| 437 |
|
|---|
| 438 | modelBuilder.Entity<WishlistProduct>(entity =>
|
|---|
| 439 | {
|
|---|
| 440 | entity.ToTable("wishlist_products");
|
|---|
| 441 |
|
|---|
| 442 | entity.HasKey(x => new
|
|---|
| 443 | {
|
|---|
| 444 | x.WishlistId,
|
|---|
| 445 | x.ProductId
|
|---|
| 446 | });
|
|---|
| 447 |
|
|---|
| 448 | entity.Property(x => x.WishlistId)
|
|---|
| 449 | .HasColumnName("wishlist_id");
|
|---|
| 450 |
|
|---|
| 451 | entity.Property(x => x.ProductId)
|
|---|
| 452 | .HasColumnName("product_id");
|
|---|
| 453 |
|
|---|
| 454 | entity.Property(x => x.AddedAt)
|
|---|
| 455 | .HasColumnName("added_at")
|
|---|
| 456 | .HasColumnType("date");
|
|---|
| 457 |
|
|---|
| 458 | entity.HasOne(x => x.Wishlist)
|
|---|
| 459 | .WithMany(x => x.WishlistProducts)
|
|---|
| 460 | .HasForeignKey(x => x.WishlistId)
|
|---|
| 461 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 462 |
|
|---|
| 463 | entity.HasOne(x => x.Product)
|
|---|
| 464 | .WithMany(x => x.WishlistProducts)
|
|---|
| 465 | .HasForeignKey(x => x.ProductId)
|
|---|
| 466 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 467 | });
|
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 | // ==========================================
|
|---|
| 471 | // MODIFICATIONS
|
|---|
| 472 | // ==========================================
|
|---|
| 473 |
|
|---|
| 474 | modelBuilder.Entity<Modification>(entity =>
|
|---|
| 475 | {
|
|---|
| 476 | entity.ToTable("modifications");
|
|---|
| 477 |
|
|---|
| 478 | entity.HasKey(x => x.ModificationId);
|
|---|
| 479 |
|
|---|
| 480 | entity.Property(x => x.ModificationId)
|
|---|
| 481 | .HasColumnName("modification_id");
|
|---|
| 482 |
|
|---|
| 483 | entity.Property(x => x.AdminId)
|
|---|
| 484 | .HasColumnName("admin_id");
|
|---|
| 485 |
|
|---|
| 486 | entity.Property(x => x.DateModified)
|
|---|
| 487 | .HasColumnName("date_modified")
|
|---|
| 488 | .HasColumnType("date");
|
|---|
| 489 |
|
|---|
| 490 | entity.Property(x => x.TypeOfModification)
|
|---|
| 491 | .HasColumnName("type_of_modification")
|
|---|
| 492 | .HasColumnType("project.modification_type");
|
|---|
| 493 |
|
|---|
| 494 | entity.Property(x => x.Discount)
|
|---|
| 495 | .HasColumnName("discount")
|
|---|
| 496 | .HasColumnType("numeric");
|
|---|
| 497 |
|
|---|
| 498 | entity.HasOne(x => x.Admin)
|
|---|
| 499 | .WithMany(x => x.Modifications)
|
|---|
| 500 | .HasForeignKey(x => x.AdminId)
|
|---|
| 501 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 502 | });
|
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 | // ==========================================
|
|---|
| 506 | // MODIFICATION_PRODUCTS
|
|---|
| 507 | // ==========================================
|
|---|
| 508 |
|
|---|
| 509 | modelBuilder.Entity<ModificationProduct>(entity =>
|
|---|
| 510 | {
|
|---|
| 511 | entity.ToTable("modification_products");
|
|---|
| 512 |
|
|---|
| 513 | entity.HasKey(x => new
|
|---|
| 514 | {
|
|---|
| 515 | x.ModificationId,
|
|---|
| 516 | x.ProductId
|
|---|
| 517 | });
|
|---|
| 518 |
|
|---|
| 519 | entity.Property(x => x.ModificationId)
|
|---|
| 520 | .HasColumnName("modification_id");
|
|---|
| 521 |
|
|---|
| 522 | entity.Property(x => x.ProductId)
|
|---|
| 523 | .HasColumnName("product_id");
|
|---|
| 524 |
|
|---|
| 525 | entity.HasOne(x => x.Modification)
|
|---|
| 526 | .WithMany(x => x.ModificationProducts)
|
|---|
| 527 | .HasForeignKey(x => x.ModificationId)
|
|---|
| 528 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 529 |
|
|---|
| 530 | entity.HasOne(x => x.Product)
|
|---|
| 531 | .WithMany(x => x.ModificationProducts)
|
|---|
| 532 | .HasForeignKey(x => x.ProductId)
|
|---|
| 533 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 534 | });
|
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 | // ==========================================
|
|---|
| 538 | // RELEASE_ARTISTS
|
|---|
| 539 | // ==========================================
|
|---|
| 540 |
|
|---|
| 541 | modelBuilder.Entity<ReleaseArtist>(entity =>
|
|---|
| 542 | {
|
|---|
| 543 | entity.ToTable("release_artists");
|
|---|
| 544 |
|
|---|
| 545 | entity.HasKey(x => new
|
|---|
| 546 | {
|
|---|
| 547 | x.ReleaseId,
|
|---|
| 548 | x.ArtistId
|
|---|
| 549 | });
|
|---|
| 550 |
|
|---|
| 551 | entity.Property(x => x.ReleaseId)
|
|---|
| 552 | .HasColumnName("release_id");
|
|---|
| 553 |
|
|---|
| 554 | entity.Property(x => x.ArtistId)
|
|---|
| 555 | .HasColumnName("artist_id");
|
|---|
| 556 |
|
|---|
| 557 | entity.Property(x => x.ReleaseOrdinal)
|
|---|
| 558 | .HasColumnName("release_ordinal");
|
|---|
| 559 |
|
|---|
| 560 | entity.Property(x => x.Type)
|
|---|
| 561 | .HasColumnName("type")
|
|---|
| 562 | .HasColumnType("project.artist_release_type");
|
|---|
| 563 |
|
|---|
| 564 | entity.HasOne(x => x.Release)
|
|---|
| 565 | .WithMany(x => x.ReleaseArtists)
|
|---|
| 566 | .HasForeignKey(x => x.ReleaseId)
|
|---|
| 567 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 568 |
|
|---|
| 569 | entity.HasOne(x => x.Artist)
|
|---|
| 570 | .WithMany(x => x.ReleaseArtists)
|
|---|
| 571 | .HasForeignKey(x => x.ArtistId)
|
|---|
| 572 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 573 | });
|
|---|
| 574 |
|
|---|
| 575 |
|
|---|
| 576 | // ==========================================
|
|---|
| 577 | // SONG_ARTISTS
|
|---|
| 578 | // ==========================================
|
|---|
| 579 |
|
|---|
| 580 | modelBuilder.Entity<SongArtist>(entity =>
|
|---|
| 581 | {
|
|---|
| 582 | entity.ToTable("song_artists");
|
|---|
| 583 |
|
|---|
| 584 | entity.HasKey(x => new
|
|---|
| 585 | {
|
|---|
| 586 | x.SongId,
|
|---|
| 587 | x.ArtistId
|
|---|
| 588 | });
|
|---|
| 589 |
|
|---|
| 590 | entity.Property(x => x.SongId)
|
|---|
| 591 | .HasColumnName("song_id");
|
|---|
| 592 |
|
|---|
| 593 | entity.Property(x => x.ArtistId)
|
|---|
| 594 | .HasColumnName("artist_id");
|
|---|
| 595 |
|
|---|
| 596 | entity.Property(x => x.SongOrdinal)
|
|---|
| 597 | .HasColumnName("song_ordinal");
|
|---|
| 598 |
|
|---|
| 599 | entity.HasOne(x => x.Song)
|
|---|
| 600 | .WithMany(x => x.SongArtists)
|
|---|
| 601 | .HasForeignKey(x => x.SongId)
|
|---|
| 602 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 603 |
|
|---|
| 604 | entity.HasOne(x => x.Artist)
|
|---|
| 605 | .WithMany(x => x.SongArtists)
|
|---|
| 606 | .HasForeignKey(x => x.ArtistId)
|
|---|
| 607 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 608 | });
|
|---|
| 609 |
|
|---|
| 610 |
|
|---|
| 611 | // ==========================================
|
|---|
| 612 | // ALBUM_SONGS
|
|---|
| 613 | // ==========================================
|
|---|
| 614 |
|
|---|
| 615 | modelBuilder.Entity<AlbumSong>(entity =>
|
|---|
| 616 | {
|
|---|
| 617 | entity.ToTable("album_songs");
|
|---|
| 618 |
|
|---|
| 619 | entity.HasKey(x => new
|
|---|
| 620 | {
|
|---|
| 621 | x.AlbumId,
|
|---|
| 622 | x.SongId
|
|---|
| 623 | });
|
|---|
| 624 |
|
|---|
| 625 | entity.Property(x => x.AlbumId)
|
|---|
| 626 | .HasColumnName("album_id");
|
|---|
| 627 |
|
|---|
| 628 | entity.Property(x => x.SongId)
|
|---|
| 629 | .HasColumnName("song_id");
|
|---|
| 630 |
|
|---|
| 631 | entity.HasOne(x => x.Album)
|
|---|
| 632 | .WithMany(x => x.AlbumSongs)
|
|---|
| 633 | .HasForeignKey(x => x.AlbumId)
|
|---|
| 634 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 635 |
|
|---|
| 636 | entity.HasOne(x => x.Song)
|
|---|
| 637 | .WithMany(x => x.AlbumSongs)
|
|---|
| 638 | .HasForeignKey(x => x.SongId)
|
|---|
| 639 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 640 | });
|
|---|
| 641 |
|
|---|
| 642 |
|
|---|
| 643 | /*// ==========================================
|
|---|
| 644 | // SINGLE_FEATURES
|
|---|
| 645 | // ==========================================
|
|---|
| 646 |
|
|---|
| 647 | modelBuilder.Entity<SingleFeature>(entity =>
|
|---|
| 648 | {
|
|---|
| 649 | entity.ToTable("single_features");
|
|---|
| 650 |
|
|---|
| 651 | entity.HasKey(x => new
|
|---|
| 652 | {
|
|---|
| 653 | x.SingleId,
|
|---|
| 654 | x.SongId
|
|---|
| 655 | });
|
|---|
| 656 |
|
|---|
| 657 | entity.Property(x => x.SingleId)
|
|---|
| 658 | .HasColumnName("single_id");
|
|---|
| 659 |
|
|---|
| 660 | entity.Property(x => x.SongId)
|
|---|
| 661 | .HasColumnName("song_id");
|
|---|
| 662 |
|
|---|
| 663 | entity.HasOne(x => x.Single)
|
|---|
| 664 | .WithMany(x => x.SingleFeatures)
|
|---|
| 665 | .HasForeignKey(x => x.SingleId)
|
|---|
| 666 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 667 |
|
|---|
| 668 | entity.HasOne(x => x.Song)
|
|---|
| 669 | .WithMany(x => x.SingleFeatures)
|
|---|
| 670 | .HasForeignKey(x => x.SongId)
|
|---|
| 671 | .OnDelete(DeleteBehavior.Cascade);
|
|---|
| 672 | });*/
|
|---|
| 673 | }
|
|---|
| 674 | } |
|---|