From fc7a6357c06aa889b8ae1e69d11c98af12a11b6a Mon Sep 17 00:00:00 2001 From: spiral Date: Wed, 1 Dec 2021 09:16:44 -0500 Subject: [PATCH] refactor: rename config table to system_config --- PluralKit.Core/Database/Functions/functions.sql | 8 ++++---- PluralKit.Core/Database/Migrations/21.sql | 6 +++--- .../Database/Repository/ModelRepository.System.cs | 2 +- ...pository.Config.cs => ModelRepository.SystemConfig.cs} | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) rename PluralKit.Core/Database/Repository/{ModelRepository.Config.cs => ModelRepository.SystemConfig.cs} (76%) diff --git a/PluralKit.Core/Database/Functions/functions.sql b/PluralKit.Core/Database/Functions/functions.sql index 810d0ba1..280c0d8a 100644 --- a/PluralKit.Core/Database/Functions/functions.sql +++ b/PluralKit.Core/Database/Functions/functions.sql @@ -23,9 +23,9 @@ as $$ -- CTEs to query "static" (accessible only through args) data with - system as (select systems.*, config.latch_timeout, system_guild.tag as guild_tag, system_guild.tag_enabled as tag_enabled, allow_autoproxy as account_autoproxy from accounts + system as (select systems.*, system_config.latch_timeout, system_guild.tag as guild_tag, system_guild.tag_enabled as tag_enabled, allow_autoproxy as account_autoproxy from accounts left join systems on systems.id = accounts.system - left join config on config.system = accounts.system + left join system_config on system_config.system = accounts.system left join system_guild on system_guild.system = accounts.system and system_guild.guild = guild_id where accounts.uid = account_id), guild as (select * from servers where id = guild_id), @@ -49,12 +49,12 @@ as $$ coalesce(system.tag_enabled, true) as tag_enabled, system.avatar_url as system_avatar, system.account_autoproxy as allow_autoproxy, - config.latch_timeout as latch_timeout + system_config.latch_timeout as latch_timeout -- We need a "from" clause, so we just use some bogus data that's always present -- This ensure we always have exactly one row going forward, so we can left join afterwards and still get data from (select 1) as _placeholder left join system on true - left join config on true + left join system_config on true left join guild on true left join last_message on true left join system_last_switch on system_last_switch.system = system.id diff --git a/PluralKit.Core/Database/Migrations/21.sql b/PluralKit.Core/Database/Migrations/21.sql index 269c9a7b..e58d4022 100644 --- a/PluralKit.Core/Database/Migrations/21.sql +++ b/PluralKit.Core/Database/Migrations/21.sql @@ -1,7 +1,7 @@ -- schema version 21 --- create `config` table +-- create `system_config` table -create table config ( +create table system_config ( system int primary key references systems(id) on delete cascade, ui_tz text not null default 'UTC', pings_enabled bool not null default true, @@ -10,7 +10,7 @@ create table config ( group_limit_override int ); -insert into config select +insert into system_config select id as system, ui_tz, pings_enabled, diff --git a/PluralKit.Core/Database/Repository/ModelRepository.System.cs b/PluralKit.Core/Database/Repository/ModelRepository.System.cs index d15b6d04..05bb5942 100644 --- a/PluralKit.Core/Database/Repository/ModelRepository.System.cs +++ b/PluralKit.Core/Database/Repository/ModelRepository.System.cs @@ -80,7 +80,7 @@ public partial class ModelRepository var system = await _db.QueryFirst(conn, query, "returning *"); _logger.Information("Created {SystemId}", system.Id); - var (q, pms) = ("insert into config (system) values (@system)", new { system = system.Id }); + var (q, pms) = ("insert into system_config (system) values (@system)", new { system = system.Id }); if (conn == null) await _db.Execute(conn => conn.QueryAsync(q, pms)); diff --git a/PluralKit.Core/Database/Repository/ModelRepository.Config.cs b/PluralKit.Core/Database/Repository/ModelRepository.SystemConfig.cs similarity index 76% rename from PluralKit.Core/Database/Repository/ModelRepository.Config.cs rename to PluralKit.Core/Database/Repository/ModelRepository.SystemConfig.cs index 05bb3541..8cc83333 100644 --- a/PluralKit.Core/Database/Repository/ModelRepository.Config.cs +++ b/PluralKit.Core/Database/Repository/ModelRepository.SystemConfig.cs @@ -5,11 +5,11 @@ namespace PluralKit.Core; public partial class ModelRepository { public Task GetSystemConfig(SystemId system, IPKConnection conn = null) - => _db.QueryFirst(conn, new Query("config").Where("system", system)); + => _db.QueryFirst(conn, new Query("system_config").Where("system", system)); public async Task UpdateSystemConfig(SystemId system, SystemConfigPatch patch, IPKConnection conn = null) { - var query = patch.Apply(new Query("config").Where("system", system)); + var query = patch.Apply(new Query("system_config").Where("system", system)); var config = await _db.QueryFirst(conn, query, "returning *"); _ = _dispatch.Dispatch(system, new UpdateDispatchData