refactor: use actors for db configuration (#1604)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Alessandro (Ale) Segala
2026-07-19 20:48:05 -10:00
committed by GitHub
parent 472fff33ea
commit 2cfbcb4b67
53 changed files with 2061 additions and 1714 deletions

View File

@@ -0,0 +1,16 @@
-- Recreate the standalone config table with the same schema it had before it was frozen
CREATE TABLE app_config_variables
(
key VARCHAR(100) NOT NULL PRIMARY KEY,
value TEXT NOT NULL
);
-- Populate it from the frozen JSON document stored in the "kv" table
-- json_each expands the JSON object back into one row per key/value pair.
INSERT INTO app_config_variables (key, value)
SELECT je.key, je.value
FROM kv, json_each_text(kv."value"::json) AS je(key, value)
WHERE kv."key" = 'config_migrated';
-- Remove the frozen config from the "kv" table
DELETE FROM kv WHERE "key" = 'config_migrated';

View File

@@ -0,0 +1,12 @@
-- Freeze the app configuration
-- Encode every row of the standalone config table as a single JSON object (mapping key -> value) and store it in the "kv" table under the "config_migrated" key
--
-- json_object_agg aggregates all rows into a JSON object
-- The "HAVING count(*) > 0" clause ensures that nothing is written to the "kv" table when the config table is empty
INSERT INTO kv ("key", "value")
SELECT 'config_migrated', json_object_agg("key", "value")::text
FROM app_config_variables
HAVING count(*) > 0;
-- Drop the now-frozen standalone config table
DROP TABLE app_config_variables;

View File

@@ -0,0 +1,22 @@
PRAGMA foreign_keys=OFF;
BEGIN;
-- Recreate the standalone config table with the same schema it had before it was frozen
CREATE TABLE app_config_variables
(
"key" TEXT NOT NULL PRIMARY KEY,
"value" TEXT NOT NULL
);
-- Populate it from the frozen JSON document stored in the "kv" table
-- json_each expands the JSON object back into one row per key/value pair.
INSERT INTO app_config_variables ("key", "value")
SELECT je.key, je.value
FROM kv, json_each(kv."value") AS je
WHERE kv."key" = 'config_migrated';
-- Remove the frozen config from the "kv" table
DELETE FROM kv WHERE "key" = 'config_migrated';
COMMIT;
PRAGMA foreign_keys=ON;

View File

@@ -0,0 +1,18 @@
PRAGMA foreign_keys=OFF;
BEGIN;
-- Freeze the app configuration
-- Encode every row of the standalone config table as a single JSON object (mapping key -> value) and store it in the "kv" table under the "config_migrated" key
--
-- json_group_object aggregates all rows into a JSON object
-- The "HAVING count(*) > 0" clause ensures that nothing is written to the "kv" table when the config table is empty
INSERT INTO kv ("key", "value")
SELECT 'config_migrated', json_group_object("key", "value")
FROM app_config_variables
HAVING count(*) > 0;
-- Drop the now-frozen standalone config table
DROP TABLE app_config_variables;
COMMIT;
PRAGMA foreign_keys=ON;