mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-09-08 12:11:26 +02:00
refactor: use actors for db configuration (#1604)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
472fff33ea
commit
2cfbcb4b67
@@ -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';
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user