From 78fe43b8d289d03775500ba637849e5b886c7605 Mon Sep 17 00:00:00 2001 From: Matthew Meszaros Date: Sun, 20 Sep 2026 16:18:14 +0200 Subject: [PATCH] feat: widen unibox_emails.mailbox to bigint so a folder whose UIDVALIDITY is at or above 2^31 can have its mail filed and listed instead of failing to bind against int4, finishing the widening 000179 started --- .../000191_widen_unibox_email_mailbox.down.sql | 3 +++ .../000191_widen_unibox_email_mailbox.up.sql | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 internal/infrastructure/db/migrations/000191_widen_unibox_email_mailbox.down.sql create mode 100644 internal/infrastructure/db/migrations/000191_widen_unibox_email_mailbox.up.sql diff --git a/internal/infrastructure/db/migrations/000191_widen_unibox_email_mailbox.down.sql b/internal/infrastructure/db/migrations/000191_widen_unibox_email_mailbox.down.sql new file mode 100644 index 000000000..be97202b5 --- /dev/null +++ b/internal/infrastructure/db/migrations/000191_widen_unibox_email_mailbox.down.sql @@ -0,0 +1,3 @@ +-- Narrowing back fails on any row that needed the extra range, which is the +-- point of the change. Values that fit are unaffected. +ALTER TABLE unibox_emails ALTER COLUMN mailbox TYPE integer; diff --git a/internal/infrastructure/db/migrations/000191_widen_unibox_email_mailbox.up.sql b/internal/infrastructure/db/migrations/000191_widen_unibox_email_mailbox.up.sql new file mode 100644 index 000000000..3da9b2c12 --- /dev/null +++ b/internal/infrastructure/db/migrations/000191_widen_unibox_email_mailbox.up.sql @@ -0,0 +1,18 @@ +-- unibox_emails.mailbox holds the folder's UIDVALIDITY, which RFC 3501 defines +-- as an unsigned 32-bit value. The column is int4, so every value at or above +-- 2^31 fails to bind at all: +-- +-- unable to encode 0xb8b769d8 into binary format for int4 (OID 23): +-- 3099027928 is greater than maximum value for int4 +-- +-- 000179 widened unibox_mailboxes.uid_validity and unibox_emails.uid for this +-- exact reason and left this one behind, so a server that stamps UIDVALIDITY +-- with anything other than a Unix timestamp still cannot have its mail filed: +-- the sync asks what the folder already holds, and the query never reaches the +-- database. Nothing stored is out of range, because nothing out of range could +-- ever be written, so widening is the whole repair. +-- +-- int4 to int8 is a table rewrite and takes ACCESS EXCLUSIVE, so the unibox +-- stalls for the length of it. Rehearsed against production inside a rolled +-- back transaction: 3.4s, most of it rebuilding the body_text index. +ALTER TABLE unibox_emails ALTER COLUMN mailbox TYPE bigint;