Skip to content

Commit 10bf38e

Browse files
committed
Update db schema
1 parent c7e69ca commit 10bf38e

File tree

38 files changed

+502
-156
lines changed

38 files changed

+502
-156
lines changed

src/Bible.Alarm.Shared/Database/Migrations/Schedule/20260111001000_UpdateToNextRelease.Designer.cs

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Bible.Alarm.Shared/Database/Migrations/Schedule/20260111001000_UpdateToNextRelease.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ protected override void Up(MigrationBuilder migrationBuilder)
1515
name: "BibleReadingSchedules",
1616
newName: "BiblePublicationSchedules");
1717

18-
// Rename BookNumber to SectionNumber and make it nullable
18+
// Rename BookNumber to SectionCode and change type to string to match media index db
1919
migrationBuilder.RenameColumn(
2020
name: "BookNumber",
2121
table: "BiblePublicationSchedules",
22-
newName: "SectionNumber");
22+
newName: "SectionCode");
2323

24-
migrationBuilder.AlterColumn<int>(
25-
name: "SectionNumber",
24+
migrationBuilder.AlterColumn<string>(
25+
name: "SectionCode",
2626
table: "BiblePublicationSchedules",
27-
type: "INTEGER",
27+
type: "TEXT",
28+
maxLength: 50,
2829
nullable: true,
2930
oldClrType: typeof(int),
3031
oldType: "INTEGER");
@@ -251,17 +252,18 @@ protected override void Down(MigrationBuilder migrationBuilder)
251252
newName: "ChapterNumber");
252253

253254
migrationBuilder.AlterColumn<int>(
254-
name: "SectionNumber",
255+
name: "SectionCode",
255256
table: "BiblePublicationSchedules",
256257
type: "INTEGER",
257258
nullable: false,
258259
defaultValue: 0,
259-
oldClrType: typeof(int),
260-
oldType: "INTEGER",
260+
oldClrType: typeof(string),
261+
oldType: "TEXT",
262+
oldMaxLength: 50,
261263
oldNullable: true);
262264

263265
migrationBuilder.RenameColumn(
264-
name: "SectionNumber",
266+
name: "SectionCode",
265267
table: "BiblePublicationSchedules",
266268
newName: "BookNumber");
267269

src/Bible.Alarm.Shared/Database/Migrations/Schedule/ScheduleDbContextModelSnapshot.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
176176
b.Property<int>("AlarmScheduleId")
177177
.HasColumnType("INTEGER");
178178

179-
b.Property<int?>("SectionNumber")
180-
.HasColumnType("INTEGER");
179+
b.Property<string>("SectionCode")
180+
.HasMaxLength(50)
181+
.HasColumnType("TEXT");
181182

182183
b.Property<int>("TrackNumber")
183184
.HasColumnType("INTEGER");

src/Bible.Alarm.Shared/Models/Media/BiblePublications/BiblePublicationSection.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,29 @@ public int CompareTo(object obj)
6666
return 1;
6767
}
6868

69-
// For Bible sections, try to compare by BookNum (from UrlParams) for proper ordering
70-
// Otherwise compare by SectionCode
71-
var thisBookNum = BookNum;
72-
var otherBookNum = other.BookNum;
69+
// Natural sort: if SectionCode is numeric, sort as int; otherwise sort as string
70+
var thisIsNumeric = int.TryParse(SectionCode, out var thisNum);
71+
var otherIsNumeric = int.TryParse(other.SectionCode, out var otherNum);
7372

74-
if (thisBookNum.HasValue && otherBookNum.HasValue)
73+
if (thisIsNumeric && otherIsNumeric)
7574
{
76-
return thisBookNum.Value.CompareTo(otherBookNum.Value);
75+
// Both are numeric - compare as integers
76+
return thisNum.CompareTo(otherNum);
7777
}
7878

79-
// Fallback to string comparison of SectionCode
79+
if (thisIsNumeric && !otherIsNumeric)
80+
{
81+
// This is numeric, other is not - numeric comes first
82+
return -1;
83+
}
84+
85+
if (!thisIsNumeric && otherIsNumeric)
86+
{
87+
// This is not numeric, other is - numeric comes first
88+
return 1;
89+
}
90+
91+
// Both are non-numeric - compare as strings
8092
return string.Compare(SectionCode, other.SectionCode, StringComparison.OrdinalIgnoreCase);
8193
}
8294
}

src/Bible.Alarm.Shared/Models/Schedule/AlarmSchedule.cs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ int GetPublicationSortPriority(string code)
280280
TrackNumber = 1,
281281
LanguageCode = bibleLanguageCode,
282282
PublicationCode = biblePublicationCode,
283-
SectionNumber = 1 // Will be updated below with a random section
283+
SectionCode = "1" // Will be updated below with a random section
284284
}
285285
};
286286

@@ -309,24 +309,8 @@ int GetPublicationSortPriority(string code)
309309
throw new InvalidOperationException("BiblePublicationSchedule is null in sample schedule");
310310
}
311311

312-
// Try to parse SectionCode to int for SectionNumber, or use BookNum
313-
if (int.TryParse(section.SectionCode, out var sectionNumberInt))
314-
{
315-
sample.BiblePublicationSchedule.SectionNumber = sectionNumberInt;
316-
}
317-
else if (section.BookNum.HasValue)
318-
{
319-
sample.BiblePublicationSchedule.SectionNumber = section.BookNum.Value;
320-
}
321-
else
322-
{
323-
// Fallback: try to get from UrlParams
324-
var booknumParam = section.UrlParams.FirstOrDefault(p => p.Key.Equals("booknum", StringComparison.OrdinalIgnoreCase));
325-
if (booknumParam != null && int.TryParse(booknumParam.Value, out var booknum))
326-
{
327-
sample.BiblePublicationSchedule.SectionNumber = booknum;
328-
}
329-
}
312+
// Use SectionCode directly to match media index db
313+
sample.BiblePublicationSchedule.SectionCode = section.SectionCode;
330314

331315
if (sample.Music == null)
332316
{

src/Bible.Alarm.Shared/Models/Schedule/BiblePublicationSchedule.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ public class BiblePublicationSchedule
2323
public string PublicationCode { get; set; } = string.Empty;
2424

2525
/// <summary>
26-
/// Section number for publications with sections.
26+
/// Section code for publications with sections (e.g., "1" for book 1, "gen" for Genesis, section code for dramas).
2727
/// Null for publications without sections (e.g., dramas, videos).
28+
/// Matches BiblePublicationSection.SectionCode for consistency.
2829
/// </summary>
29-
[Range(1, 500)]
30-
public int? SectionNumber { get; set; }
30+
[MaxLength(50)]
31+
public string? SectionCode { get; set; }
3132

3233
/// <summary>
3334
/// Track number for traditional Bible readings, or track/part number for dramas.

src/Bible.Alarm.Shared/Services/Media/LanguageContentService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ public async Task<bool> FetchPublicationTracksAsync(
132132
var isVideo = categoryName.Equals("Dramas", StringComparison.OrdinalIgnoreCase) &&
133133
PublicationTypeHelper.IsVideo(normalizedPublicationCode);
134134

135-
switch (publicationLanguage.HarvestType)
135+
var harvestType = publicationLanguage.HarvestType ?? PublicationTypeHelper.GetHarvestType(normalizedPublicationCode);
136+
switch (harvestType)
136137
{
137138
case Models.Enums.HarvestType.MediatorSectioned:
138139
// Drama publications use Mediator API
@@ -1223,7 +1224,7 @@ public async Task<bool> SeedEnglishPublicationAsync(
12231224
else
12241225
{
12251226
category = publicationLanguage.Category;
1226-
harvestType = publicationLanguage.HarvestType;
1227+
harvestType = publicationLanguage.HarvestType ?? PublicationTypeHelper.GetHarvestType(normalizedPublicationCode);
12271228
}
12281229

12291230
var categoryName = category.CategoryName;

src/Bible.Alarm/Common/Helpers/ServiceRegistrationHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
using Serilog;
7070
using Bible.Alarm.ViewModels.ScheduleViewModelHelpers;
7171
using Bible.Alarm.ViewModels.BiblePublications;
72+
using Bible.Alarm.ViewModels.Categories;
7273
#if WINDOWS
7374
using Bible.Alarm.Platforms.Windows.Services.UI;
7475
using Bible.Alarm.Platforms.Windows.Services.Handlers;

src/Bible.Alarm/Services/Bootstrap/ScheduleStatePopulatorHelpers/BiblePublicationDisplayNamePopulator.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,19 @@ private static void SetSectionName(
8989
BiblePublicationSchedule biblePublication,
9090
LookupDataLoader.LookupData lookupData)
9191
{
92-
if (biblePublication.SectionNumber.HasValue && biblePublication.SectionNumber.Value > 0 &&
92+
// Convert SectionCode to int for lookup key
93+
if (!string.IsNullOrEmpty(biblePublication.SectionCode) &&
94+
int.TryParse(biblePublication.SectionCode, out var sectionNum) &&
95+
sectionNum > 0 &&
9396
!string.IsNullOrWhiteSpace(biblePublication.LanguageCode) &&
9497
!string.IsNullOrWhiteSpace(biblePublication.PublicationCode))
9598
{
96-
var sectionKey = (biblePublication.LanguageCode, biblePublication.PublicationCode, biblePublication.SectionNumber.Value);
99+
var sectionKey = (biblePublication.LanguageCode, biblePublication.PublicationCode, sectionNum);
97100
if (lookupData.Sections.TryGetValue(sectionKey, out var sectionName))
98101
{
99102
scheduleStateItem.BiblePublicationSectionName = sectionName;
100-
Log.Logger.Debug("Set BiblePublicationSectionName '{BiblePublicationSectionName}' for schedule {ScheduleId} (SectionNumber: {SectionNumber})",
101-
sectionName, schedule.Id, biblePublication.SectionNumber);
103+
Log.Logger.Debug("Set BiblePublicationSectionName '{BiblePublicationSectionName}' for schedule {ScheduleId} (SectionCode: {SectionCode})",
104+
sectionName, schedule.Id, biblePublication.SectionCode);
102105
}
103106
}
104107
}

src/Bible.Alarm/Services/Bootstrap/ScheduleStatePopulatorHelpers/LookupKeys.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ public LookupKeys CollectKeys(List<AlarmSchedule> alarmSchedules)
2727
if (!string.IsNullOrWhiteSpace(br.LanguageCode) && !string.IsNullOrWhiteSpace(br.PublicationCode))
2828
{
2929
publicationKeys.Add((br.LanguageCode, br.PublicationCode));
30-
if (br.SectionNumber.HasValue && br.SectionNumber.Value > 0)
30+
// Convert SectionCode to int for lookup key
31+
if (!string.IsNullOrEmpty(br.SectionCode) && int.TryParse(br.SectionCode, out var sectionNum) && sectionNum > 0)
3132
{
32-
sectionKeys.Add((br.LanguageCode, br.PublicationCode, br.SectionNumber.Value));
33+
sectionKeys.Add((br.LanguageCode, br.PublicationCode, sectionNum));
3334
}
3435
}
3536
}

0 commit comments

Comments
 (0)