Move logs from array to dedicated table
All checks were successful
/ release (push) Successful in 1m23s

This avoids the append problem which bloats the database to 200+ gb in a
month and shrinks again to 5g with a full vacuum
This commit is contained in:
Samuel Lorch 2025-05-18 19:18:52 +02:00
parent 15a960da19
commit f52f517dc1
9 changed files with 99 additions and 11 deletions

View file

@ -0,0 +1 @@
DROP TABLE IF EXISTS logs;

View file

@ -0,0 +1,5 @@
CREATE TABLE IF NOT EXISTS logs(
id bigserial PRIMARY KEY,
task_id bigint REFERENCES tasks(id) NOT NULL,
message text
);

View file

@ -0,0 +1 @@
DROP INDEX logs_task_id;

View file

@ -0,0 +1 @@
CREATE INDEX logs_task_id on logs(task_id);

View file

@ -0,0 +1 @@
/* migration is irreversable */

View file

@ -0,0 +1,3 @@
INSERT INTO logs (task_id, message)
SELECT id as task_id, l as message
FROM tasks, unnest(log) l ORDER BY task_id ASC;