feat: move scheduled tasks to separate project
This commit is contained in:
10
PluralKit.Core/Database/Migrations/19.sql
Normal file
10
PluralKit.Core/Database/Migrations/19.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
-- schema version 19: 2021-10-15 --
|
||||
-- add stats to info table
|
||||
|
||||
alter table info add column system_count int;
|
||||
alter table info add column member_count int;
|
||||
alter table info add column group_count int;
|
||||
alter table info add column switch_count int;
|
||||
alter table info add column message_count int;
|
||||
|
||||
update info set schema_version = 18;
|
33
PluralKit.Core/Database/Repository/ModelRepository.Stats.cs
Normal file
33
PluralKit.Core/Database/Repository/ModelRepository.Stats.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Dapper;
|
||||
|
||||
using SqlKata;
|
||||
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public partial class ModelRepository
|
||||
{
|
||||
public async Task UpdateStats()
|
||||
{
|
||||
await _db.Execute(conn => conn.ExecuteAsync("update info set system_count = (select count(*) from systems)"));
|
||||
await _db.Execute(conn => conn.ExecuteAsync("update info set member_count = (select count(*) from members)"));
|
||||
await _db.Execute(conn => conn.ExecuteAsync("update info set group_count = (select count(*) from groups)"));
|
||||
await _db.Execute(conn => conn.ExecuteAsync("update info set switch_count = (select count(*) from switches)"));
|
||||
await _db.Execute(conn => conn.ExecuteAsync("update info set message_count = (select count(*) from messages)"));
|
||||
}
|
||||
|
||||
public Task<Counts> GetStats()
|
||||
=> _db.Execute(conn => conn.QuerySingleAsync<Counts>("select * from info"));
|
||||
|
||||
public class Counts
|
||||
{
|
||||
public int SystemCount { get; }
|
||||
public int MemberCount { get; }
|
||||
public int GroupCount { get; }
|
||||
public int SwitchCount { get; }
|
||||
public int MessageCount { get; }
|
||||
}
|
||||
}
|
||||
}
|
@@ -12,7 +12,7 @@ namespace PluralKit.Core
|
||||
internal class DatabaseMigrator
|
||||
{
|
||||
private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files
|
||||
private const int TargetSchemaVersion = 18;
|
||||
private const int TargetSchemaVersion = 19;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public DatabaseMigrator(ILogger logger)
|
||||
|
Reference in New Issue
Block a user