Skip to content

Commit dfd3d72

Browse files
davidortinauCopilot
andcommitted
Fix BackfillUserProfileIdsAsync crash on fresh mobile DB
On fresh installs, the UserProfileId columns may not exist yet (migrations only run during sync, not at app startup). Added a column existence check before attempting the backfill SQL to prevent SQLite Error 1: 'no such column: UserProfileId'. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a2dbbae commit dfd3d72

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/SentenceStudio.Shared/Data/UserProfileRepository.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ public async Task<UserProfile> GetAsync()
7979

8080
private static async Task BackfillUserProfileIdsAsync(ApplicationDbContext db)
8181
{
82+
// Check if UserProfileId column exists before attempting backfill.
83+
// On fresh installs, the column may not exist until MigrateAsync() runs.
84+
var cols = await db.Database.SqlQueryRaw<string>(
85+
"SELECT name FROM pragma_table_info('SkillProfile') WHERE name = 'UserProfileId'").ToListAsync();
86+
if (cols.Count == 0)
87+
return; // Column doesn't exist yet — skip backfill
88+
8289
// Assign unowned SkillProfiles by matching Language → UserProfile.TargetLanguage
8390
await db.Database.ExecuteSqlRawAsync(@"
8491
UPDATE SkillProfile SET UserProfileId = (

0 commit comments

Comments
 (0)