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