diff --git a/KdyPojedeVlak.Web/Engine/DbStorage/DbModelContext.cs b/KdyPojedeVlak.Web/Engine/DbStorage/DbModelContext.cs index 94daf20..ad3e606 100644 --- a/KdyPojedeVlak.Web/Engine/DbStorage/DbModelContext.cs +++ b/KdyPojedeVlak.Web/Engine/DbStorage/DbModelContext.cs @@ -2,6 +2,7 @@ using System; using System.Collections; +using System.Collections.Frozen; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -12,13 +13,12 @@ using KdyPojedeVlak.Web.Engine.SR70; using KdyPojedeVlak.Web.Models; using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; namespace KdyPojedeVlak.Web.Engine.DbStorage; using static DbModelUtils; -public class DbModelContext : DbContext +public class DbModelContext(DbContextOptions options) : DbContext(options) { public DbSet ImportedFiles { get; set; } public DbSet TimetableYears { get; set; } @@ -29,11 +29,7 @@ public class DbModelContext : DbContext public DbSet CalendarDefinitions { get; set; } public DbSet NeighboringPointTuples { get; set; } public DbSet TrainCancellations { get; set; } - - public DbModelContext(DbContextOptions options) - : base(options) - { - } + public DbSet Texts { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -81,11 +77,14 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity() .HasIndex(o => o.TimetableVariantId); + + modelBuilder.Entity() + .HasIndex(o => o.Str).IsUnique(); } public HashSet GetNeighboringPoints(RoutingPoint point) { - if (point == null) throw new ArgumentNullException(nameof(point)); + ArgumentNullException.ThrowIfNull(point); var pointId = point.Id; var neighbors = NeighboringPointTuples @@ -451,7 +450,7 @@ public class CentralPttNoteForVariant : PttNoteForVariant public class NonCentralPttNoteForVariant : PttNoteForVariant { [Required] - public string Text { get; set; } + public Text Text { get; set; } [Required] public HeaderDisplay ShowInHeader { get; set; } @@ -465,6 +464,8 @@ public class NonCentralPttNoteForVariant : PttNoteForVariant public class NetworkSpecificParameterForPassage { + public static readonly FrozenSet IndirectTypes = new[] { NetworkSpecificParameterPassage.CZPassengerPublicTransportOrderingCoName }.ToFrozenSet(); + public int Id { get; set; } [Required] @@ -476,8 +477,15 @@ public class NetworkSpecificParameterForPassage [Required] public NetworkSpecificParameterPassage Type { get; set; } + [NotMapped] [Required] - public string Value { get; set; } + public string Value => ValueDirect ?? ValueIndirect?.Str; + + [Column("Value")] + public string ValueDirect { get; set; } + + [ForeignKey("ValueRef")] + public Text ValueIndirect { get; set; } } public class TrainCancellation @@ -504,6 +512,24 @@ public class TrainCancellation public ImportedFile ImportedFrom { get; set; } } +public class Text +{ + public int Id { get; set; } + + [Required] + public string Str { get; set; } + + public static Text FindOrCreate(DbModelContext context, string str) + { + var existing = context.Texts.SingleOrDefault(t => t.Str == str); + if (existing != null) return existing; + + var newText = new Text { Str = str }; + context.Add(newText); + return newText; + } +} + public static class DbModelUtils { public static List ParseEnumList(string data) diff --git a/KdyPojedeVlak.Web/Engine/Djr/DjrSchedule.cs b/KdyPojedeVlak.Web/Engine/Djr/DjrSchedule.cs index 461bf0a..6d8bce7 100644 --- a/KdyPojedeVlak.Web/Engine/Djr/DjrSchedule.cs +++ b/KdyPojedeVlak.Web/Engine/Djr/DjrSchedule.cs @@ -484,13 +484,23 @@ private static CZPTTCISMessageBase LoadXmlFile(Stream stream) { foreach (var param in networkSpecificParametersForPassage) { - dbModelContext.Add( - new NetworkSpecificParameterForPassage - { - Passage = passage, - Type = Enum.Parse(param.Key), - Value = String.Join(';', param.Value) - }); + var type = Enum.Parse(param.Key); + var paramValue = String.Join(';', param.Value); + var dbParam = new NetworkSpecificParameterForPassage + { + Passage = passage, + Type = type + }; + + if (NetworkSpecificParameterForPassage.IndirectTypes.Contains(type)) + { + dbParam.ValueIndirect = Text.FindOrCreate(dbModelContext, paramValue); + } + else + { + dbParam.ValueDirect = paramValue; + } + dbModelContext.Add(dbParam); } } } @@ -519,7 +529,7 @@ private static CZPTTCISMessageBase LoadXmlFile(Stream stream) } if (networkSpecificParameters.TryGetValue(NetworkSpecificParameterGlobal.CZNonCentralPTTNote.ToString(), out var nonCentralPttNoteDefinitions)) { - dbModelContext.AddRange(nonCentralPttNoteDefinitions.Select(def => ParseNonCentralPttNoteDefinition(def, passages, pttNoteCalendars, trainTimetableVariant))); + dbModelContext.AddRange(nonCentralPttNoteDefinitions.Select(def => ParseNonCentralPttNoteDefinition(dbModelContext, def, passages, pttNoteCalendars, trainTimetableVariant))); } dbModelContext.SaveChanges(); } @@ -697,7 +707,7 @@ private static CentralPttNoteForVariant ParseCentralPttNoteDefinition(string def }; } - private static NonCentralPttNoteForVariant ParseNonCentralPttNoteDefinition(string definition, Dictionary> passages, IDictionary? calendarDefinitions, TrainTimetableVariant trainTimetableVariant) + private static NonCentralPttNoteForVariant ParseNonCentralPttNoteDefinition(DbModelContext dbModelContext, string definition, Dictionary> passages, IDictionary? calendarDefinitions, TrainTimetableVariant trainTimetableVariant) { var pieces = definition.Split('|'); @@ -717,7 +727,7 @@ private static NonCentralPttNoteForVariant ParseNonCentralPttNoteDefinition(stri return new NonCentralPttNoteForVariant { TrainTimetableVariant = trainTimetableVariant, - Text = pieces[4], + Text = Text.FindOrCreate(dbModelContext, pieces[4]), From = from, To = to, ShowInHeader = defShowInHeader[pieces[5]], diff --git a/KdyPojedeVlak.Web/Migrations/20240917132455_IndirectTexts.Designer.cs b/KdyPojedeVlak.Web/Migrations/20240917132455_IndirectTexts.Designer.cs new file mode 100644 index 0000000..25116a8 --- /dev/null +++ b/KdyPojedeVlak.Web/Migrations/20240917132455_IndirectTexts.Designer.cs @@ -0,0 +1,641 @@ +// +using System; +using KdyPojedeVlak.Web.Engine.DbStorage; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace KdyPojedeVlak.Web.Migrations +{ + [DbContext(typeof(DbModelContext))] + [Migration("20240917132455_IndirectTexts")] + partial class IndirectTexts + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.8"); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.CalendarDefinition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("BitmapEncoded") + .IsRequired() + .HasMaxLength(70) + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("EndDate") + .HasColumnType("TEXT"); + + b.Property("Guid") + .HasColumnType("TEXT"); + + b.Property("StartDate") + .HasColumnType("TEXT"); + + b.Property("TimetableYearYear") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("TimetableYearYear"); + + b.ToTable("CalendarDefinitions"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.ImportedFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationDate") + .HasColumnType("TEXT"); + + b.Property("FileName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("FileSize") + .HasColumnType("INTEGER"); + + b.Property("ImportTime") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("CreationDate"); + + b.HasIndex("FileName") + .IsUnique(); + + b.ToTable("ImportedFiles"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.NeighboringPoints", b => + { + b.Property("PointAId") + .HasColumnType("INTEGER"); + + b.Property("PointBId") + .HasColumnType("INTEGER"); + + b.HasKey("PointAId", "PointBId"); + + b.HasIndex("PointBId", "PointAId"); + + b.ToTable("NeighboringPointTuples"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.NetworkSpecificParameterForPassage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("PassageId") + .HasColumnType("INTEGER"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.Property("Value") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("PassageId"); + + b.ToTable("NetworkSpecificParameterForPassage"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.Passage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ArrivalDay") + .HasColumnType("INTEGER"); + + b.Property("ArrivalTime") + .HasColumnType("TEXT"); + + b.Property("DepartureDay") + .HasColumnType("INTEGER"); + + b.Property("DepartureTime") + .HasColumnType("TEXT"); + + b.Property("DwellTime") + .HasColumnType("TEXT"); + + b.Property("Order") + .HasColumnType("INTEGER"); + + b.Property("PointId") + .HasColumnType("INTEGER"); + + b.Property("SubsidiaryLocation") + .HasColumnType("TEXT"); + + b.Property("SubsidiaryLocationName") + .HasColumnType("TEXT"); + + b.Property("SubsidiaryLocationType") + .HasColumnType("INTEGER"); + + b.Property("TrainId") + .HasColumnType("INTEGER"); + + b.Property("TrainOperationsStr") + .HasColumnType("TEXT") + .HasColumnName("TrainOperations"); + + b.Property("YearId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("TrainId", "Order") + .IsUnique(); + + b.HasIndex("PointId", "TrainId", "Order") + .IsUnique(); + + b.HasIndex("YearId", "PointId", "ArrivalTime"); + + b.ToTable("Passage"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.PttNoteForVariant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CalendarId") + .HasColumnType("INTEGER"); + + b.Property("FromId") + .HasColumnType("INTEGER"); + + b.Property("Kind") + .HasColumnType("INTEGER"); + + b.Property("OnArrival") + .HasColumnType("INTEGER"); + + b.Property("ToId") + .HasColumnType("INTEGER"); + + b.Property("TrainId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("CalendarId"); + + b.HasIndex("FromId"); + + b.HasIndex("ToId"); + + b.HasIndex("TrainId"); + + b.ToTable("PttNoteForVariant"); + + b.HasDiscriminator("Kind"); + + b.UseTphMappingStrategy(); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.RoutingPoint", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.Property("Latitude") + .HasColumnType("REAL"); + + b.Property("Longitude") + .HasColumnType("REAL"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Code") + .IsUnique(); + + b.HasIndex("Name"); + + b.HasIndex("Latitude", "Longitude"); + + b.ToTable("RoutingPoints"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TimetableYear", b => + { + b.Property("Year") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MaxDate") + .HasColumnType("TEXT"); + + b.Property("MinDate") + .HasColumnType("TEXT"); + + b.HasKey("Year"); + + b.ToTable("TimetableYears"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.Train", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Number") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Number") + .IsUnique(); + + b.ToTable("Trains"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainCancellation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CalendarId") + .HasColumnType("INTEGER"); + + b.Property("ImportedFromId") + .HasColumnType("INTEGER"); + + b.Property("PathVariantId") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("TEXT"); + + b.Property("TimetableVariantId") + .HasColumnType("INTEGER"); + + b.Property("TrainVariantId") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("CalendarId"); + + b.HasIndex("ImportedFromId"); + + b.HasIndex("TimetableVariantId"); + + b.ToTable("TrainCancellations"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("TrafficType") + .HasColumnType("INTEGER"); + + b.Property("TrainCategory") + .HasColumnType("INTEGER"); + + b.Property("TrainId") + .HasColumnType("INTEGER"); + + b.Property("YearId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.HasIndex("YearId"); + + b.HasIndex("TrainId", "YearId") + .IsUnique(); + + b.ToTable("TrainTimetables"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetableVariant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CalendarId") + .HasColumnType("INTEGER"); + + b.Property("ImportedFromId") + .HasColumnType("INTEGER"); + + b.Property("PathVariantId") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("TEXT"); + + b.Property("TimetableId") + .HasColumnType("INTEGER"); + + b.Property("TrainVariantId") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("TEXT"); + + b.Property("YearId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("CalendarId"); + + b.HasIndex("ImportedFromId"); + + b.HasIndex("TimetableId"); + + b.HasIndex("YearId", "TrainVariantId", "PathVariantId") + .IsUnique(); + + b.ToTable("TrainTimetableVariants"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.CentralPttNoteForVariant", b => + { + b.HasBaseType("KdyPojedeVlak.Web.Engine.DbStorage.PttNoteForVariant"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasDiscriminator().HasValue(1); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.NonCentralPttNoteForVariant", b => + { + b.HasBaseType("KdyPojedeVlak.Web.Engine.DbStorage.PttNoteForVariant"); + + b.Property("IsTariff") + .HasColumnType("INTEGER"); + + b.Property("ShowInFooter") + .HasColumnType("INTEGER"); + + b.Property("ShowInHeader") + .HasColumnType("INTEGER"); + + b.Property("Text") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasDiscriminator().HasValue(2); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.CalendarDefinition", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TimetableYear", "TimetableYear") + .WithMany() + .HasForeignKey("TimetableYearYear") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("TimetableYear"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.NeighboringPoints", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.RoutingPoint", "PointA") + .WithMany() + .HasForeignKey("PointAId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.RoutingPoint", "PointB") + .WithMany() + .HasForeignKey("PointBId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PointA"); + + b.Navigation("PointB"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.NetworkSpecificParameterForPassage", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.Passage", "Passage") + .WithMany("NetworkSpecificParameters") + .HasForeignKey("PassageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Passage"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.Passage", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.RoutingPoint", "Point") + .WithMany("PassingTrains") + .HasForeignKey("PointId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetableVariant", "TrainTimetableVariant") + .WithMany("Points") + .HasForeignKey("TrainId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TimetableYear", "Year") + .WithMany() + .HasForeignKey("YearId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Point"); + + b.Navigation("TrainTimetableVariant"); + + b.Navigation("Year"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.PttNoteForVariant", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.CalendarDefinition", "Calendar") + .WithMany() + .HasForeignKey("CalendarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.Passage", "From") + .WithMany() + .HasForeignKey("FromId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.Passage", "To") + .WithMany() + .HasForeignKey("ToId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetableVariant", "TrainTimetableVariant") + .WithMany("PttNotes") + .HasForeignKey("TrainId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Calendar"); + + b.Navigation("From"); + + b.Navigation("To"); + + b.Navigation("TrainTimetableVariant"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainCancellation", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.CalendarDefinition", "Calendar") + .WithMany() + .HasForeignKey("CalendarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.ImportedFile", "ImportedFrom") + .WithMany() + .HasForeignKey("ImportedFromId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetableVariant", "TrainTimetableVariant") + .WithMany("Cancellations") + .HasForeignKey("TimetableVariantId"); + + b.Navigation("Calendar"); + + b.Navigation("ImportedFrom"); + + b.Navigation("TrainTimetableVariant"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetable", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.Train", "Train") + .WithMany() + .HasForeignKey("TrainId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TimetableYear", "TimetableYear") + .WithMany() + .HasForeignKey("YearId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("TimetableYear"); + + b.Navigation("Train"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetableVariant", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.CalendarDefinition", "Calendar") + .WithMany() + .HasForeignKey("CalendarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.ImportedFile", "ImportedFrom") + .WithMany() + .HasForeignKey("ImportedFromId"); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetable", "Timetable") + .WithMany("Variants") + .HasForeignKey("TimetableId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TimetableYear", "TimetableYear") + .WithMany() + .HasForeignKey("YearId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Calendar"); + + b.Navigation("ImportedFrom"); + + b.Navigation("Timetable"); + + b.Navigation("TimetableYear"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.Passage", b => + { + b.Navigation("NetworkSpecificParameters"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.RoutingPoint", b => + { + b.Navigation("PassingTrains"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetable", b => + { + b.Navigation("Variants"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetableVariant", b => + { + b.Navigation("Cancellations"); + + b.Navigation("Points"); + + b.Navigation("PttNotes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/KdyPojedeVlak.Web/Migrations/20240917132455_IndirectTexts.cs b/KdyPojedeVlak.Web/Migrations/20240917132455_IndirectTexts.cs new file mode 100644 index 0000000..e77c773 --- /dev/null +++ b/KdyPojedeVlak.Web/Migrations/20240917132455_IndirectTexts.cs @@ -0,0 +1,339 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace KdyPojedeVlak.Web.Migrations +{ + /// + public partial class IndirectTexts : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Texts", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Str = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Texts", x => x.Id); + }); + + migrationBuilder.Sql( + """ + INSERT INTO Texts(Str) + SELECT DISTINCT Value + FROM NetworkSpecificParameterForPassage + WHERE Type=4 + """ + ); + + migrationBuilder.CreateIndex( + name: "IX_Texts_Str", + table: "Texts", + column: "Str", + unique: true); + + migrationBuilder.DropIndex( + "IX_NetworkSpecificParameterForPassage_PassageId", + "NetworkSpecificParameterForPassage" + ); + + migrationBuilder.CreateTable( + name: "TmpNetworkSpecificParameterForPassage", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + PassageId = table.Column(type: "INTEGER", nullable: false), + Type = table.Column(type: "INTEGER", nullable: false), + Value = table.Column(type: "TEXT", nullable: true), + ValueRef = table.Column(type: "INTEGER", nullable: true), + }, + constraints: table => + { + table.PrimaryKey("PK_NetworkSpecificParameterForPassage", x => x.Id); + table.ForeignKey( + name: "FK_NetworkSpecificParameterForPassage_Passage_PassageId", + column: x => x.PassageId, + principalTable: "Passage", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_NetworkSpecificParameterForPassage_Texts_ValueRef", + column: x => x.ValueRef, + principalTable: "Texts", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.CheckConstraint("CHK_NetworkSpecificParameterForPassage_Ref_ValueRef", "Value IS NULL OR ValueRef IS NULL"); + }); + + migrationBuilder.Sql(""" + INSERT INTO TmpNetworkSpecificParameterForPassage(PassageId, Type, Value, ValueRef) + SELECT PassageId, Type, iif(Type=4, NULL, Value), iif(Type=4, (SELECT t.ID FROM Texts t WHERE t.Str=Value), NULL) + FROM NetworkSpecificParameterForPassage + """); + + migrationBuilder.DropTable("NetworkSpecificParameterForPassage"); + + migrationBuilder.RenameTable("TmpNetworkSpecificParameterForPassage", null, "NetworkSpecificParameterForPassage", null); + + migrationBuilder.CreateIndex( + name: "IX_NetworkSpecificParameterForPassage_PassageId", + table: "NetworkSpecificParameterForPassage", + column: "PassageId"); + + + migrationBuilder.Sql(""" + INSERT OR IGNORE INTO Texts(Str) SELECT DISTINCT Text FROM PttNoteForVariant WHERE Kind=2 + """); + + migrationBuilder.DropIndex( + name: "IX_PttNoteForVariant_CalendarId", + table: "PttNoteForVariant"); + + migrationBuilder.DropIndex( + name: "IX_PttNoteForVariant_FromId", + table: "PttNoteForVariant"); + + migrationBuilder.DropIndex( + name: "IX_PttNoteForVariant_ToId", + table: "PttNoteForVariant"); + + migrationBuilder.DropIndex( + name: "IX_PttNoteForVariant_TrainId", + table: "PttNoteForVariant"); + + + migrationBuilder.CreateTable( + name: "TmpPttNoteForVariant", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + TrainId = table.Column(type: "INTEGER", nullable: false), + FromId = table.Column(type: "INTEGER", nullable: true), + ToId = table.Column(type: "INTEGER", nullable: true), + OnArrival = table.Column(type: "INTEGER", nullable: false), + CalendarId = table.Column(type: "INTEGER", nullable: true), + Kind = table.Column(type: "INTEGER", nullable: false), + Type = table.Column(type: "INTEGER", nullable: true), + TextId = table.Column(type: "INTEGER", nullable: true), + ShowInHeader = table.Column(type: "INTEGER", nullable: true), + ShowInFooter = table.Column(type: "INTEGER", nullable: true), + IsTariff = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_PttNoteForVariant", x => x.Id); + table.ForeignKey( + name: "FK_PttNoteForVariant_CalendarDefinitions_CalendarId", + column: x => x.CalendarId, + principalTable: "CalendarDefinitions", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_PttNoteForVariant_Passage_FromId", + column: x => x.FromId, + principalTable: "Passage", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_PttNoteForVariant_Passage_ToId", + column: x => x.ToId, + principalTable: "Passage", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_PttNoteForVariant_TrainTimetableVariant_TrainId", + column: x => x.TrainId, + principalTable: "TrainTimetableVariants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PttNoteForVariant_Texts_Text", + column: x => x.TextId, + principalTable: "Texts", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.Sql(""" + INSERT INTO TmpPttNoteForVariant(CalendarId, FromId, IsTariff, Kind, OnArrival, ShowInFooter, ShowInHeader, TextId, ToId, TrainId, Type) + SELECT CalendarId, FromId, IsTariff, Kind, OnArrival, ShowInFooter, ShowInHeader, iif(Kind=2, (SELECT Id FROM Texts t WHERE t.Str=Text), NULL), ToId, TrainId, Type + FROM PttNoteForVariant + """); + + migrationBuilder.DropTable("PttNoteForVariant"); + + migrationBuilder.RenameTable("TmpPttNoteForVariant", null, "PttNoteForVariant", null); + + migrationBuilder.CreateIndex( + name: "IX_PttNoteForVariant_CalendarId", + table: "PttNoteForVariant", + column: "CalendarId"); + + migrationBuilder.CreateIndex( + name: "IX_PttNoteForVariant_FromId", + table: "PttNoteForVariant", + column: "FromId"); + + migrationBuilder.CreateIndex( + name: "IX_PttNoteForVariant_ToId", + table: "PttNoteForVariant", + column: "ToId"); + + migrationBuilder.CreateIndex( + name: "IX_PttNoteForVariant_TrainId", + table: "PttNoteForVariant", + column: "TrainId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_PttNoteForVariant_CalendarId", + table: "PttNoteForVariant"); + + migrationBuilder.DropIndex( + name: "IX_PttNoteForVariant_FromId", + table: "PttNoteForVariant"); + + migrationBuilder.DropIndex( + name: "IX_PttNoteForVariant_ToId", + table: "PttNoteForVariant"); + + migrationBuilder.DropIndex( + name: "IX_PttNoteForVariant_TrainId", + table: "PttNoteForVariant"); + + migrationBuilder.CreateTable( + name: "TmpPttNoteForVariant", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + TrainId = table.Column(type: "INTEGER", nullable: false), + FromId = table.Column(type: "INTEGER", nullable: true), + ToId = table.Column(type: "INTEGER", nullable: true), + OnArrival = table.Column(type: "INTEGER", nullable: false), + CalendarId = table.Column(type: "INTEGER", nullable: true), + Kind = table.Column(type: "INTEGER", nullable: false), + Type = table.Column(type: "INTEGER", nullable: true), + Text = table.Column(type: "TEXT", nullable: true), + ShowInHeader = table.Column(type: "INTEGER", nullable: true), + ShowInFooter = table.Column(type: "INTEGER", nullable: true), + IsTariff = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_PttNoteForVariant", x => x.Id); + table.ForeignKey( + name: "FK_PttNoteForVariant_CalendarDefinitions_CalendarId", + column: x => x.CalendarId, + principalTable: "CalendarDefinitions", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_PttNoteForVariant_Passage_FromId", + column: x => x.FromId, + principalTable: "Passage", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_PttNoteForVariant_Passage_ToId", + column: x => x.ToId, + principalTable: "Passage", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_PttNoteForVariant_TrainTimetableVariant_TrainId", + column: x => x.TrainId, + principalTable: "TrainTimetableVariants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.Sql(""" + INSERT INTO TmpPttNoteForVariant(CalendarId, FromId, IsTariff, Kind, OnArrival, ShowInFooter, ShowInHeader, Text, ToId, TrainId, Type) + SELECT CalendarId, FromId, IsTariff, Kind, OnArrival, ShowInFooter, ShowInHeader, iif(Kind=2, (SELECT Str FROM Texts t WHERE t.Id=TextId), NULL), ToId, TrainId, Type + FROM PttNoteForVariant + """); + + migrationBuilder.DropTable("PttNoteForVariant"); + + migrationBuilder.RenameTable("TmpPttNoteForVariant", null, "PttNoteForVariant", null); + + migrationBuilder.CreateIndex( + name: "IX_PttNoteForVariant_CalendarId", + table: "PttNoteForVariant", + column: "CalendarId"); + + migrationBuilder.CreateIndex( + name: "IX_PttNoteForVariant_FromId", + table: "PttNoteForVariant", + column: "FromId"); + + migrationBuilder.CreateIndex( + name: "IX_PttNoteForVariant_ToId", + table: "PttNoteForVariant", + column: "ToId"); + + migrationBuilder.CreateIndex( + name: "IX_PttNoteForVariant_TrainId", + table: "PttNoteForVariant", + column: "TrainId"); + + + migrationBuilder.DropIndex( + "IX_NetworkSpecificParameterForPassage_PassageId", + "NetworkSpecificParameterForPassage" + ); + + migrationBuilder.CreateTable( + name: "TmpNetworkSpecificParameterForPassage", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + PassageId = table.Column(type: "INTEGER", nullable: false), + Type = table.Column(type: "INTEGER", nullable: false), + Value = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_NetworkSpecificParameterForPassage", x => x.Id); + table.ForeignKey( + name: "FK_NetworkSpecificParameterForPassage_Passage_PassageId", + column: x => x.PassageId, + principalTable: "Passage", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.Sql(""" + INSERT INTO TmpNetworkSpecificParameterForPassage(PassageId, Type, Value) + SELECT PassageId, Type, iif(ValueRef IS NOT NULL, (SELECT t.Str FROM Texts t WHERE t.ID=ValueRef), Value) + FROM NetworkSpecificParameterForPassage + """); + + migrationBuilder.DropTable("NetworkSpecificParameterForPassage"); + + migrationBuilder.RenameTable("TmpNetworkSpecificParameterForPassage", null, "NetworkSpecificParameterForPassage", null); + + migrationBuilder.CreateIndex( + name: "IX_NetworkSpecificParameterForPassage_PassageId", + table: "NetworkSpecificParameterForPassage", + column: "PassageId"); + + + migrationBuilder.DropTable( + name: "Texts"); + } + } +} diff --git a/KdyPojedeVlak.Web/Migrations/20240918101022_VacuumAfterIndirectTexts.Designer.cs b/KdyPojedeVlak.Web/Migrations/20240918101022_VacuumAfterIndirectTexts.Designer.cs new file mode 100644 index 0000000..54345ae --- /dev/null +++ b/KdyPojedeVlak.Web/Migrations/20240918101022_VacuumAfterIndirectTexts.Designer.cs @@ -0,0 +1,682 @@ +// +using System; +using KdyPojedeVlak.Web.Engine.DbStorage; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace KdyPojedeVlak.Web.Migrations +{ + [DbContext(typeof(DbModelContext))] + [Migration("20240918101022_VacuumAfterIndirectTexts")] + partial class VacuumAfterIndirectTexts + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.8"); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.CalendarDefinition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("BitmapEncoded") + .IsRequired() + .HasMaxLength(70) + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("EndDate") + .HasColumnType("TEXT"); + + b.Property("Guid") + .HasColumnType("TEXT"); + + b.Property("StartDate") + .HasColumnType("TEXT"); + + b.Property("TimetableYearYear") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("TimetableYearYear"); + + b.ToTable("CalendarDefinitions"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.ImportedFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationDate") + .HasColumnType("TEXT"); + + b.Property("FileName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("FileSize") + .HasColumnType("INTEGER"); + + b.Property("ImportTime") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("CreationDate"); + + b.HasIndex("FileName") + .IsUnique(); + + b.ToTable("ImportedFiles"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.NeighboringPoints", b => + { + b.Property("PointAId") + .HasColumnType("INTEGER"); + + b.Property("PointBId") + .HasColumnType("INTEGER"); + + b.HasKey("PointAId", "PointBId"); + + b.HasIndex("PointBId", "PointAId"); + + b.ToTable("NeighboringPointTuples"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.NetworkSpecificParameterForPassage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("PassageId") + .HasColumnType("INTEGER"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.Property("ValueDirect") + .HasColumnType("TEXT") + .HasColumnName("Value"); + + b.Property("ValueRef") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("PassageId"); + + b.HasIndex("ValueRef"); + + b.ToTable("NetworkSpecificParameterForPassage"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.Passage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ArrivalDay") + .HasColumnType("INTEGER"); + + b.Property("ArrivalTime") + .HasColumnType("TEXT"); + + b.Property("DepartureDay") + .HasColumnType("INTEGER"); + + b.Property("DepartureTime") + .HasColumnType("TEXT"); + + b.Property("DwellTime") + .HasColumnType("TEXT"); + + b.Property("Order") + .HasColumnType("INTEGER"); + + b.Property("PointId") + .HasColumnType("INTEGER"); + + b.Property("SubsidiaryLocation") + .HasColumnType("TEXT"); + + b.Property("SubsidiaryLocationName") + .HasColumnType("TEXT"); + + b.Property("SubsidiaryLocationType") + .HasColumnType("INTEGER"); + + b.Property("TrainId") + .HasColumnType("INTEGER"); + + b.Property("TrainOperationsStr") + .HasColumnType("TEXT") + .HasColumnName("TrainOperations"); + + b.Property("YearId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("TrainId", "Order") + .IsUnique(); + + b.HasIndex("PointId", "TrainId", "Order") + .IsUnique(); + + b.HasIndex("YearId", "PointId", "ArrivalTime"); + + b.ToTable("Passage"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.PttNoteForVariant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CalendarId") + .HasColumnType("INTEGER"); + + b.Property("FromId") + .HasColumnType("INTEGER"); + + b.Property("Kind") + .HasColumnType("INTEGER"); + + b.Property("OnArrival") + .HasColumnType("INTEGER"); + + b.Property("ToId") + .HasColumnType("INTEGER"); + + b.Property("TrainId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("CalendarId"); + + b.HasIndex("FromId"); + + b.HasIndex("ToId"); + + b.HasIndex("TrainId"); + + b.ToTable("PttNoteForVariant"); + + b.HasDiscriminator("Kind"); + + b.UseTphMappingStrategy(); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.RoutingPoint", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.Property("Latitude") + .HasColumnType("REAL"); + + b.Property("Longitude") + .HasColumnType("REAL"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Code") + .IsUnique(); + + b.HasIndex("Name"); + + b.HasIndex("Latitude", "Longitude"); + + b.ToTable("RoutingPoints"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.Text", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Str") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Str") + .IsUnique(); + + b.ToTable("Texts"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TimetableYear", b => + { + b.Property("Year") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MaxDate") + .HasColumnType("TEXT"); + + b.Property("MinDate") + .HasColumnType("TEXT"); + + b.HasKey("Year"); + + b.ToTable("TimetableYears"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.Train", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Number") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Number") + .IsUnique(); + + b.ToTable("Trains"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainCancellation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CalendarId") + .HasColumnType("INTEGER"); + + b.Property("ImportedFromId") + .HasColumnType("INTEGER"); + + b.Property("PathVariantId") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("TEXT"); + + b.Property("TimetableVariantId") + .HasColumnType("INTEGER"); + + b.Property("TrainVariantId") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("CalendarId"); + + b.HasIndex("ImportedFromId"); + + b.HasIndex("TimetableVariantId"); + + b.ToTable("TrainCancellations"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("TrafficType") + .HasColumnType("INTEGER"); + + b.Property("TrainCategory") + .HasColumnType("INTEGER"); + + b.Property("TrainId") + .HasColumnType("INTEGER"); + + b.Property("YearId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.HasIndex("YearId"); + + b.HasIndex("TrainId", "YearId") + .IsUnique(); + + b.ToTable("TrainTimetables"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetableVariant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CalendarId") + .HasColumnType("INTEGER"); + + b.Property("ImportedFromId") + .HasColumnType("INTEGER"); + + b.Property("PathVariantId") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("TEXT"); + + b.Property("TimetableId") + .HasColumnType("INTEGER"); + + b.Property("TrainVariantId") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("TEXT"); + + b.Property("YearId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("CalendarId"); + + b.HasIndex("ImportedFromId"); + + b.HasIndex("TimetableId"); + + b.HasIndex("YearId", "TrainVariantId", "PathVariantId") + .IsUnique(); + + b.ToTable("TrainTimetableVariants"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.CentralPttNoteForVariant", b => + { + b.HasBaseType("KdyPojedeVlak.Web.Engine.DbStorage.PttNoteForVariant"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasDiscriminator().HasValue(1); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.NonCentralPttNoteForVariant", b => + { + b.HasBaseType("KdyPojedeVlak.Web.Engine.DbStorage.PttNoteForVariant"); + + b.Property("IsTariff") + .HasColumnType("INTEGER"); + + b.Property("ShowInFooter") + .HasColumnType("INTEGER"); + + b.Property("ShowInHeader") + .HasColumnType("INTEGER"); + + b.Property("TextId") + .HasColumnType("INTEGER"); + + b.HasIndex("TextId"); + + b.HasDiscriminator().HasValue(2); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.CalendarDefinition", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TimetableYear", "TimetableYear") + .WithMany() + .HasForeignKey("TimetableYearYear") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("TimetableYear"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.NeighboringPoints", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.RoutingPoint", "PointA") + .WithMany() + .HasForeignKey("PointAId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.RoutingPoint", "PointB") + .WithMany() + .HasForeignKey("PointBId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PointA"); + + b.Navigation("PointB"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.NetworkSpecificParameterForPassage", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.Passage", "Passage") + .WithMany("NetworkSpecificParameters") + .HasForeignKey("PassageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.Text", "ValueIndirect") + .WithMany() + .HasForeignKey("ValueRef"); + + b.Navigation("Passage"); + + b.Navigation("ValueIndirect"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.Passage", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.RoutingPoint", "Point") + .WithMany("PassingTrains") + .HasForeignKey("PointId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetableVariant", "TrainTimetableVariant") + .WithMany("Points") + .HasForeignKey("TrainId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TimetableYear", "Year") + .WithMany() + .HasForeignKey("YearId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Point"); + + b.Navigation("TrainTimetableVariant"); + + b.Navigation("Year"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.PttNoteForVariant", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.CalendarDefinition", "Calendar") + .WithMany() + .HasForeignKey("CalendarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.Passage", "From") + .WithMany() + .HasForeignKey("FromId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.Passage", "To") + .WithMany() + .HasForeignKey("ToId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetableVariant", "TrainTimetableVariant") + .WithMany("PttNotes") + .HasForeignKey("TrainId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Calendar"); + + b.Navigation("From"); + + b.Navigation("To"); + + b.Navigation("TrainTimetableVariant"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainCancellation", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.CalendarDefinition", "Calendar") + .WithMany() + .HasForeignKey("CalendarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.ImportedFile", "ImportedFrom") + .WithMany() + .HasForeignKey("ImportedFromId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetableVariant", "TrainTimetableVariant") + .WithMany("Cancellations") + .HasForeignKey("TimetableVariantId"); + + b.Navigation("Calendar"); + + b.Navigation("ImportedFrom"); + + b.Navigation("TrainTimetableVariant"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetable", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.Train", "Train") + .WithMany() + .HasForeignKey("TrainId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TimetableYear", "TimetableYear") + .WithMany() + .HasForeignKey("YearId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("TimetableYear"); + + b.Navigation("Train"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetableVariant", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.CalendarDefinition", "Calendar") + .WithMany() + .HasForeignKey("CalendarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.ImportedFile", "ImportedFrom") + .WithMany() + .HasForeignKey("ImportedFromId"); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetable", "Timetable") + .WithMany("Variants") + .HasForeignKey("TimetableId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.TimetableYear", "TimetableYear") + .WithMany() + .HasForeignKey("YearId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Calendar"); + + b.Navigation("ImportedFrom"); + + b.Navigation("Timetable"); + + b.Navigation("TimetableYear"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.NonCentralPttNoteForVariant", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.Text", "Text") + .WithMany() + .HasForeignKey("TextId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Text"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.Passage", b => + { + b.Navigation("NetworkSpecificParameters"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.RoutingPoint", b => + { + b.Navigation("PassingTrains"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetable", b => + { + b.Navigation("Variants"); + }); + + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TrainTimetableVariant", b => + { + b.Navigation("Cancellations"); + + b.Navigation("Points"); + + b.Navigation("PttNotes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/KdyPojedeVlak.Web/Migrations/20240918101022_VacuumAfterIndirectTexts.cs b/KdyPojedeVlak.Web/Migrations/20240918101022_VacuumAfterIndirectTexts.cs new file mode 100644 index 0000000..b23e57c --- /dev/null +++ b/KdyPojedeVlak.Web/Migrations/20240918101022_VacuumAfterIndirectTexts.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace KdyPojedeVlak.Web.Migrations +{ + /// + public partial class VacuumAfterIndirectTexts : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("VACUUM", true); + migrationBuilder.Sql("PRAGMA optimize", true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + } + } +} diff --git a/KdyPojedeVlak.Web/Migrations/DbModelContextModelSnapshot.cs b/KdyPojedeVlak.Web/Migrations/DbModelContextModelSnapshot.cs index a6e9461..fdf8bea 100644 --- a/KdyPojedeVlak.Web/Migrations/DbModelContextModelSnapshot.cs +++ b/KdyPojedeVlak.Web/Migrations/DbModelContextModelSnapshot.cs @@ -108,14 +108,19 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Type") .HasColumnType("INTEGER"); - b.Property("Value") - .IsRequired() - .HasColumnType("TEXT"); + b.Property("ValueDirect") + .HasColumnType("TEXT") + .HasColumnName("Value"); + + b.Property("ValueRef") + .HasColumnType("INTEGER"); b.HasKey("Id"); b.HasIndex("PassageId"); + b.HasIndex("ValueRef"); + b.ToTable("NetworkSpecificParameterForPassage"); }); @@ -252,6 +257,24 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("RoutingPoints"); }); + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.Text", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Str") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Str") + .IsUnique(); + + b.ToTable("Texts"); + }); + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.TimetableYear", b => { b.Property("Year") @@ -422,9 +445,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("ShowInHeader") .HasColumnType("INTEGER"); - b.Property("Text") - .IsRequired() - .HasColumnType("TEXT"); + b.Property("TextId") + .HasColumnType("INTEGER"); + + b.HasIndex("TextId"); b.HasDiscriminator().HasValue(2); }); @@ -467,7 +491,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.Text", "ValueIndirect") + .WithMany() + .HasForeignKey("ValueRef"); + b.Navigation("Passage"); + + b.Navigation("ValueIndirect"); }); modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.Passage", b => @@ -609,6 +639,17 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("TimetableYear"); }); + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.NonCentralPttNoteForVariant", b => + { + b.HasOne("KdyPojedeVlak.Web.Engine.DbStorage.Text", "Text") + .WithMany() + .HasForeignKey("TextId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Text"); + }); + modelBuilder.Entity("KdyPojedeVlak.Web.Engine.DbStorage.Passage", b => { b.Navigation("NetworkSpecificParameters"); diff --git a/KdyPojedeVlak.Web/Views/Train/Details.cshtml b/KdyPojedeVlak.Web/Views/Train/Details.cshtml index 83dbf07..2b3faf0 100644 --- a/KdyPojedeVlak.Web/Views/Train/Details.cshtml +++ b/KdyPojedeVlak.Web/Views/Train/Details.cshtml @@ -152,7 +152,7 @@ } @foreach (var note in pttNotes.OfType()) { - 🛈 + 🛈 } }