feat: import messages from go version
This commit is contained in:
parent
b56a71e105
commit
a50a8567dd
15 changed files with 503 additions and 769 deletions
|
|
@ -1,10 +1,10 @@
|
|||
// See https://aka.ms/new-console-template for more information
|
||||
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Catalogger.Backend;
|
||||
using Catalogger.Backend.Database;
|
||||
using Catalogger.Backend.Extensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NodaTime;
|
||||
using NodaTime.Serialization.SystemTextJson;
|
||||
|
|
@ -17,13 +17,15 @@ namespace Catalogger.GoImporter;
|
|||
|
||||
internal class Program
|
||||
{
|
||||
public static JsonSerializerOptions JsonOptions =
|
||||
new JsonSerializerOptions().ConfigureForNodaTime(
|
||||
new NodaJsonSettings
|
||||
{
|
||||
InstantConverter = new NodaPatternConverter<Instant>(InstantPattern.ExtendedIso),
|
||||
}
|
||||
);
|
||||
public static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions
|
||||
{
|
||||
NumberHandling = JsonNumberHandling.AllowReadingFromString,
|
||||
}.ConfigureForNodaTime(
|
||||
new NodaJsonSettings
|
||||
{
|
||||
InstantConverter = new NodaPatternConverter<Instant>(InstantPattern.ExtendedIso),
|
||||
}
|
||||
);
|
||||
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
|
|
@ -41,8 +43,18 @@ internal class Program
|
|||
return;
|
||||
}
|
||||
|
||||
var db = new DatabaseContext(config, null);
|
||||
await db.Database.MigrateAsync();
|
||||
var db = new DatabasePool(config, Log.Logger, null);
|
||||
DatabasePool.ConfigureDapper();
|
||||
if (Environment.GetEnvironmentVariable("MIGRATE") == "true")
|
||||
{
|
||||
var migrator = new DatabaseMigrator(
|
||||
Log.Logger,
|
||||
SystemClock.Instance,
|
||||
await db.AcquireAsync()
|
||||
);
|
||||
|
||||
await migrator.MigrateUp();
|
||||
}
|
||||
|
||||
var type = args[0].ToLowerInvariant();
|
||||
var file = args[1];
|
||||
|
|
@ -50,7 +62,12 @@ internal class Program
|
|||
if (type == "guilds")
|
||||
{
|
||||
Log.Information("Importing guilds from {File}", file);
|
||||
await GuildImport.DoImportAsync(db, file);
|
||||
await GuildImport.DoImportAsync(await db.AcquireAsync(), file);
|
||||
}
|
||||
else if (type == "messages")
|
||||
{
|
||||
Log.Information("Importing messages from {Path}", file);
|
||||
await MessageImport.DoImportAsync(config, await db.AcquireAsync(), file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue