Skip to content

Commit 353ae8d

Browse files
committed
feat: implement profile backfill for existing databases.
1 parent 049f8ca commit 353ae8d

5 files changed

+348
-0
lines changed

PinkSea/Database/Models/ConfigurationModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ public class ConfigurationModel
3333
/// Have we synchronized the account states?
3434
/// </summary>
3535
public bool? SynchronizedAccountStates { get; set; }
36+
37+
/// <summary>
38+
/// Have we imported profiles?
39+
/// </summary>
40+
public bool? ImportedProfiles { get; set; }
3641
}

PinkSea/Migrations/20250728162337_Add the imported profiles configuration field.Designer.cs

Lines changed: 288 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
namespace PinkSea.Migrations
6+
{
7+
/// <inheritdoc />
8+
public partial class Addtheimportedprofilesconfigurationfield : Migration
9+
{
10+
/// <inheritdoc />
11+
protected override void Up(MigrationBuilder migrationBuilder)
12+
{
13+
migrationBuilder.AddColumn<bool>(
14+
name: "ImportedProfiles",
15+
table: "Configuration",
16+
type: "boolean",
17+
nullable: true);
18+
}
19+
20+
/// <inheritdoc />
21+
protected override void Down(MigrationBuilder migrationBuilder)
22+
{
23+
migrationBuilder.DropColumn(
24+
name: "ImportedProfiles",
25+
table: "Configuration");
26+
}
27+
}
28+
}

PinkSea/Migrations/PinkSeaDbContextModelSnapshot.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
3838
.IsRequired()
3939
.HasColumnType("text");
4040

41+
b.Property<bool?>("ImportedProfiles")
42+
.HasColumnType("boolean");
43+
4144
b.Property<string>("KeyId")
4245
.IsRequired()
4346
.HasColumnType("text");

PinkSea/Services/Hosting/FirstTimeRunAssistantService.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public async Task Run(CancellationToken stoppingToken)
4141
{
4242
await SynchronizeAccountStates();
4343
}
44+
45+
if (config.ImportedProfiles != true)
46+
{
47+
await ImportProfiles();
48+
}
4449

4550
return;
4651
}
@@ -147,6 +152,25 @@ await configurationService.EditConfiguration(cfg =>
147152
});
148153
}
149154

155+
/// <summary>
156+
/// Imports PinkSea profiles. Used after migrating from an earlier version of PinkSea.
157+
/// </summary>
158+
private async Task ImportProfiles()
159+
{
160+
logger.LogInformation(" - Importing profiles for existing users...");
161+
162+
// Start fetching all the accounts.
163+
foreach (var user in await userService.GetAllUsers())
164+
{
165+
await BackfillProfile(user.Did);
166+
}
167+
168+
await configurationService.EditConfiguration(cfg =>
169+
{
170+
cfg.ImportedProfiles = true;
171+
});
172+
}
173+
150174
/// <summary>
151175
/// Backfills posts.
152176
/// </summary>

0 commit comments

Comments
 (0)