using Microsoft.EntityFrameworkCore; using RMuseum.Models.Artifact; using RMuseum.Models.Bookmark; using RMuseum.Models.GanjoorAudio; using RMuseum.Models.UploadSession; using RMuseum.Models.GanjoorIntegration; using RMuseum.Models.ImportJob; using RMuseum.Models.Note; using RSecurityBackend.DbContext; using RSecurityBackend.Models.Auth.Db; using System; using RMuseum.Models.Ganjoor; using RMuseum.Models.MusicCatalogue; using RMuseum.Models.Accounting; using Microsoft.Extensions.Configuration; using System.IO; namespace RMuseum.DbContext { /// /// Museum Database Context /// public class RMuseumDbContext : RSecurityDbContext { public RMuseumDbContext(DbContextOptions options) : base(options) { IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json") .Build(); if (bool.Parse(configuration["DatabaseMigrate"])) { Database.Migrate(); } } /// /// /// /// protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); builder.Entity() .HasIndex(m => m.FriendlyUrl) .IsUnique(); builder.Entity() .HasIndex(i => new { i.RArtifactMasterRecordId, i.FriendlyUrl }) .IsUnique(); builder.Entity() .HasIndex(i => new { i.RArtifactMasterRecordId, i.Order }) .IsUnique(); builder.Entity() .HasIndex(t => t.FriendlyUrl); builder.Entity() .HasIndex(t => t.FriendlyUrl); builder.Entity() .HasIndex(p => p.GanjoorPostId); builder.Entity() .HasIndex(c => c.FullUrl); builder.Entity() .HasIndex(c => c.FullUrl); builder.Entity() .HasIndex(c => c.FullUrl); builder.Entity() .HasIndex(c => c.Name); builder.Entity() .HasIndex(c => c.Name); builder.Entity() .HasIndex(c => c.CommentDate); builder.Entity() .Property(c => c.ProgressPercent) .HasColumnType("decimal(18,2)"); builder.Entity() .HasIndex(c => c.Status); builder.Entity() .HasIndex(c => c.Id); builder.Entity() .HasIndex(c => c.GanjoorAudioId); builder.Entity() .HasIndex(c => new { c.ReviewStatus, c.GanjoorPostId }); builder.Entity() .HasIndex(c => c.LastModified); builder.Entity() .HasIndex(c => new { c.Published, c.Id }) .IncludeProperties(c => new { c.Name, c.Nickname, c.RImageId }); builder.Entity() .HasIndex(c => new { c.ParentId, c.PoetId }) .IncludeProperties(c => c.Id); builder.Entity() .HasIndex(c => new { c.Approved, c.Rejected }); builder.Entity() .HasIndex(c => new { c.CoverItemIndex, c.Status }); builder.Entity() .HasIndex(m => m.Name) .IsUnique(); builder.Entity() .HasIndex(b => new { b.UserId, b.PoemId, b.CoupletIndex }); builder.Entity() .HasIndex(n => new { n.NumberingId, n.PoemId, n.CoupletIndex }) .IsUnique(); builder.Entity() .HasIndex(n => new { n.PoemId, n.CoupletIndex }); builder.Entity() .HasIndex(v => v.PoemId);//the next statement causes a drop index in the migration which this line prevents it builder.Entity() .HasIndex(v => new { v.PoemId, v.CoupletIndex }); builder.Entity() .HasIndex(c => new { c.PoemId }); builder.Entity() .HasIndex(c => new { c.FullUrl }); builder.Entity() .Property(c => c.Amount) .HasColumnType("decimal(18,2)"); builder.Entity() .Property(c => c.Remaining) .HasColumnType("decimal(18,2)"); builder.Entity() .Property(c => c.Amount) .HasColumnType("decimal(18,2)"); builder.Entity() .Property(c => c.Amount) .HasColumnType("decimal(18,2)"); builder.Entity() .Property(c => c.Latitude) .HasColumnType("decimal(12,9)"); builder.Entity() .Property(c => c.Longitude) .HasColumnType("decimal(12,9)"); } /// /// Picture Files /// public DbSet PictureFiles { get; set; } /// /// Item Attributes /// public DbSet Tags { get; set; } /// /// Artifacts /// public DbSet Artifacts { get; set; } /// /// Items /// public DbSet Items { get; set; } /// /// Import Jobs /// public DbSet ImportJobs { get; set; } /// /// Tags /// public DbSet TagValues { get; set; } /// /// User Bookmarks /// public DbSet UserBookmarks { get; set; } /// /// User Notes /// public DbSet UserNotes { get; set; } /// /// Ganjoor Links /// public DbSet GanjoorLinks { get; set; } /// /// Pinterest Links /// public DbSet PinterestLinks { get; set; } /// /// Ganjoor Audio Files /// public DbSet Recitations { get; set; } /// /// Upload Sessions /// public DbSet UploadSessions { get; set; } /// /// Uploaded files /// public DbSet UploadedFiles { get; set; } /// /// User Recitation Profiles /// public DbSet UserRecitationProfiles { get; set; } /// /// Ganjoor Poets /// public DbSet GanjoorPoets { get; set; } /// /// Ganjoor Categories /// public DbSet GanjoorCategories { get; set; } /// /// Ganjoor Poems /// public DbSet GanjoorPoems { get; set; } /// /// Ganjoor Verses /// public DbSet GanjoorVerses { get; set; } /// /// Narration Publishing Tracker /// public DbSet RecitationPublishingTrackers { get; set; } /// /// Ganjoor Pages /// public DbSet GanjoorPages { get; set; } /// /// Ganjoor Metres /// public DbSet GanjoorMetres { get; set; } /// /// singers /// public DbSet GanjoorSingers { get; set; } /// /// music tracks /// public DbSet GanjoorMusicCatalogueTracks { get; set; } /// /// golha tracks /// public DbSet GolhaTracks { get; set; } /// /// GolhaCollection /// public DbSet GolhaCollections { get; set; } /// /// GolhaPrograms /// public DbSet GolhaPrograms { get; set; } /// /// PoemMusicTracks /// public DbSet GanjoorPoemMusicTracks { get; set; } /// /// Ganjoor Comments /// public DbSet GanjoorComments { get; set; } /// /// Ganjoor Reported Comments /// public DbSet GanjoorReportedComments { get; set; } /// /// Ganjoor Page Snapshots /// public DbSet GanjoorPageSnapshots { get; set; } /// /// Ganjoor Site Bannaers /// public DbSet GanjoorSiteBanners { get; set; } /// /// Ganjoor Health Check Errors /// public DbSet GanjoorHealthCheckErrors { get; set; } /// /// donations /// public DbSet GanjoorDonations { get; set; } /// /// expenses /// public DbSet GanjoorExpenses { get; set; } /// /// donation expenditures /// public DbSet DonationExpenditure { get; set; } /// /// poem corrections /// public DbSet GanjoorPoemCorrections { get; set; } /// /// languages for translation /// public DbSet GanjoorLanguages { get; set; } /// /// poem translations /// public DbSet GanjoorPoemTranslations { get; set; } /// /// ganjoor bookmarks /// public DbSet GanjoorUserBookmarks { get; set; } /// /// ganjoor numbering schemas /// public DbSet GanjoorNumberings { get; set; } /// /// ganjoor verse numbers /// public DbSet GanjoorVerseNumbers { get; set; } /// /// ganjoor half centuries /// public DbSet GanjoorCenturies { get; set; } /// /// ganjoor cities /// public DbSet GanjoorGeoLocations { get; set; } /// /// related poems to each poem (having same rhyme letters and prosody metre) /// public DbSet GanjoorCachedRelatedPoems { get; set; } /// /// Reported User Notes /// public DbSet ReportedUserNotes { get; set; } } }