b4bfe083be
MUL-6407: mint UUIDv7 primary keys for append-heavy tables ( #7230 )
...
* perf(db): mint UUIDv7 primary keys for the append-heavy tables
Random v4 primary keys scatter every insert across the whole primary-key
B-tree, so each row dirties a different page. On the tables that grow
continuously — the task queue, messages, comments, activity and audit rows —
that is pure write amplification. UUIDv7 puts a big-endian millisecond
timestamp in the leading 48 bits, so consecutive inserts share a page.
The 12 tables converted here are the append-only hot paths:
agent_task_queue, activity_log, inbox_item, comment, issue, chat_session,
chat_message, autopilot_run, webhook_delivery, task_token,
channel_inbound_audit, sys_cron_executions
Ids come from the new pkg/dbid, which returns a pgtype.UUID ready to assign to
a sqlc params struct. Upsert-dominated tables (task_usage, agent_runtime, ...)
are deliberately left alone: v7 only buys locality for rows that are actually
inserted. Lease and claim tokens keep gen_random_uuid() — they must stay
unpredictable and carry no timestamp.
No migration, and no backfill. Every converted INSERT binds its id as
COALESCE(sqlc.narg('id')::uuid, gen_random_uuid()), so the column default stays
reachable: a caller that passes no id inserts exactly as it does today. Tables
will hold a mix of v4 and v7 ids permanently, which the uuid type and every
parser in the repo already accept.
Verification: - pkg/dbid: version/variant, uniqueness, and a non-decreasing timestamp
prefix; a shape test asserting every converted query keeps the COALESCE
fallback; and a source scan asserting every production params literal mints
an id, so a call site added later cannot silently fall back to v4.
- internal/handler: round-trips issue, comment, activity_log, inbox_item,
chat_session, chat_message, agent_task_queue, task_token and
channel_inbound_audit against Postgres and asserts the stored id is v7,
plus one case proving an unset id still inserts (as v4).
- internal/scheduler: covers the one hand-written INSERT, asserting the
execution id is v7 while lease_token stays v4.
Co-authored-by: multica-agent <[email protected] >
* fix(db): address UUIDv7 review feedback
Co-authored-by: multica-agent <[email protected] >
* fix(db): cover Telegram audit UUIDv7
Co-authored-by: multica-agent <[email protected] >
---------
Co-authored-by: Sol-Boy <[email protected] >
Co-authored-by: multica-agent <[email protected] >
2026-08-20 13:42:44 +08:00
..
2026-08-19 14:06:59 +08:00
2026-08-19 14:06:59 +08:00
2026-08-18 03:00:21 +08:00
2026-08-13 15:34:17 +08:00
2026-07-15 03:09:56 +08:00
2026-07-15 03:09:56 +08:00
2026-08-14 18:56:40 +08:00
2026-08-19 16:33:48 +08:00
2026-07-29 13:08:48 +08:00
2026-07-29 15:39:18 +08:00
2026-08-18 15:30:48 +08:00
2026-08-20 13:42:44 +08:00
2026-07-03 14:18:43 +08:00
2026-08-12 16:09:16 +08:00
2026-07-29 14:01:09 +08:00
2026-08-20 13:42:44 +08:00
2026-07-03 14:18:43 +08:00
2026-08-18 03:00:21 +08:00
2026-06-13 15:33:28 +08:00
2026-08-03 12:39:27 +08:00
2026-07-22 15:38:38 +08:00
2026-07-29 15:39:18 +08:00
2026-07-29 14:28:44 +08:00
2026-08-13 16:42:47 +08:00
2026-07-29 12:47:14 +08:00
2026-08-20 01:30:58 +08:00
2026-08-20 02:35:29 +08:00
2026-08-19 16:33:48 +08:00
2026-08-12 15:02:03 +08:00
2026-08-12 15:02:03 +08:00
2026-07-29 18:25:14 +08:00
2026-07-15 03:09:56 +08:00
2026-04-21 14:42:52 +08:00
2026-08-16 15:46:00 +08:00
2026-07-15 03:09:56 +08:00
2026-07-17 16:44:31 +08:00
2026-07-17 16:44:31 +08:00
2026-07-07 20:49:42 +08:00
2026-07-16 15:23:56 +08:00
2026-06-30 12:29:11 +08:00
2026-07-15 03:09:56 +08:00
2026-08-19 15:51:26 +08:00
2026-07-07 20:49:42 +08:00
2026-07-15 03:09:56 +08:00
2026-08-18 03:00:21 +08:00
2026-08-18 03:00:21 +08:00
2026-08-20 13:42:44 +08:00
2026-08-19 15:51:26 +08:00
2026-07-29 15:39:18 +08:00
2026-07-29 15:39:18 +08:00
2026-08-19 03:09:59 +08:00
2026-08-10 12:05:58 +08:00
2026-08-10 11:45:31 +08:00
2026-08-20 01:30:58 +08:00
2026-08-12 15:36:39 +08:00
2026-08-20 01:30:58 +08:00
2026-08-11 13:46:48 +08:00
2026-07-15 00:52:27 +08:00
2026-08-03 12:39:27 +08:00
2026-08-12 15:36:39 +08:00
2026-08-12 15:36:39 +08:00
2026-08-20 01:30:58 +08:00
2026-08-05 15:06:42 +08:00
2026-07-08 21:58:16 +08:00
2026-07-24 11:30:27 +08:00
2026-08-05 15:06:42 +08:00
2026-07-09 13:49:07 +08:00
2026-08-04 14:21:25 +08:00
2026-08-20 13:42:44 +08:00
2026-07-22 16:52:34 +08:00
2026-07-22 16:52:34 +08:00
2026-08-13 18:35:00 +08:00
2026-08-13 18:35:00 +08:00
2026-05-27 14:52:03 +08:00
2026-05-27 14:52:03 +08:00
2026-07-31 14:40:16 +08:00
2026-07-14 19:56:17 +08:00
2026-07-15 03:09:56 +08:00
2026-08-18 03:00:21 +08:00
2026-06-24 09:52:18 +08:00
2026-07-31 14:40:16 +08:00
2026-07-27 14:26:23 +08:00
2026-08-19 03:09:59 +08:00
2026-08-03 13:35:04 +08:00
2026-07-10 16:15:10 +08:00
2026-08-18 03:00:21 +08:00
2026-08-19 16:08:40 +08:00
2026-07-15 03:09:56 +08:00
2026-08-19 16:08:40 +08:00
2026-08-20 13:42:44 +08:00
2026-08-18 18:49:01 +08:00
2026-08-18 18:49:01 +08:00
2026-08-18 03:00:21 +08:00
2026-06-03 16:39:06 +08:00
2026-07-14 11:53:42 +08:00
2026-08-16 04:54:32 +08:00
2026-07-27 15:44:39 +08:00
2026-08-19 12:40:04 +08:00
2026-08-20 01:30:58 +08:00
2026-08-11 19:01:34 +08:00
2026-07-27 13:12:06 +08:00
2026-08-14 19:49:37 +08:00
2026-08-19 16:08:40 +08:00
2026-07-10 13:43:45 +08:00
2026-08-05 15:41:15 +08:00
2026-07-14 11:53:42 +08:00
2026-07-14 11:53:42 +08:00
2026-08-19 19:25:05 +08:00
2026-08-19 15:30:19 +08:00
2026-07-14 11:56:30 +08:00
2026-07-14 11:56:30 +08:00
2026-08-20 13:42:44 +08:00
2026-07-29 13:08:48 +08:00
2026-08-19 03:09:59 +08:00
2026-08-06 20:59:32 +08:00
2026-08-18 15:36:10 +08:00
2026-08-19 01:37:51 +08:00
2026-08-19 01:37:51 +08:00
2026-08-19 01:37:51 +08:00
2026-08-17 18:32:02 +08:00
2026-08-12 11:55:53 +08:00
2026-08-12 11:55:53 +08:00
2026-08-12 15:02:03 +08:00
2026-08-19 14:06:59 +08:00
2026-08-19 03:09:59 +08:00
2026-08-18 03:00:21 +08:00
2026-08-19 03:09:59 +08:00
2026-07-07 14:43:19 +08:00
2026-08-19 23:04:26 +08:00
2026-05-07 15:50:27 +08:00
2026-05-07 15:50:27 +08:00
2026-05-06 14:31:33 +08:00
2026-07-30 19:18:36 +08:00
2026-07-13 16:42:46 +08:00
2026-07-03 16:10:19 +08:00
2026-08-17 12:51:39 +08:00
2026-08-17 12:51:39 +08:00
2026-08-17 12:51:39 +08:00
2026-08-18 03:00:21 +08:00
2026-07-15 03:09:56 +08:00
2026-07-02 14:11:10 +08:00
2026-07-10 09:11:29 +08:00
2026-07-13 16:15:58 +08:00
2026-08-07 15:35:59 +08:00
2026-08-18 02:38:18 +08:00
2026-08-20 01:30:58 +08:00
2026-08-20 13:42:44 +08:00
2026-07-22 22:43:34 +08:00
2026-08-19 14:06:59 +08:00
2026-07-16 13:31:06 +08:00
2026-05-28 14:20:20 +08:00
2026-07-13 13:08:04 +08:00
2026-05-19 10:37:38 +08:00
2026-08-19 16:08:40 +08:00
2026-06-02 17:17:41 +08:00
2026-05-21 16:35:45 +08:00
2026-08-19 14:06:59 +08:00
2026-07-23 15:58:25 +08:00
2026-08-19 14:06:59 +08:00
2026-08-19 16:08:40 +08:00
2026-08-19 14:06:59 +08:00
2026-07-06 19:11:47 +08:00
2026-08-19 16:08:40 +08:00
2026-07-13 13:08:04 +08:00
2026-08-19 16:08:40 +08:00
2026-08-18 18:52:11 +08:00
2026-08-18 03:00:21 +08:00
2026-08-18 18:52:11 +08:00
2026-08-19 17:03:06 +08:00
2026-07-17 19:21:27 +08:00
2026-08-18 18:52:11 +08:00
2026-08-19 16:08:40 +08:00
2026-08-18 18:52:11 +08:00
2026-08-19 16:08:40 +08:00
2026-08-18 18:52:11 +08:00
2026-07-31 13:04:42 +08:00
2026-08-04 17:53:03 +08:00
2026-08-14 13:57:09 +08:00
2026-08-11 14:43:45 +08:00
2026-06-16 12:26:44 +08:00
2026-08-10 11:55:05 +08:00
2026-08-10 11:55:05 +08:00
2026-08-18 03:00:21 +08:00
2026-08-10 11:55:05 +08:00
2026-08-19 16:33:48 +08:00
2026-07-31 14:41:05 +08:00
2026-08-19 14:06:59 +08:00
2026-07-08 16:19:41 +08:00
2026-07-08 16:19:41 +08:00
2026-07-03 14:18:43 +08:00
2026-08-03 17:43:03 +08:00
2026-07-15 03:09:56 +08:00
2026-08-06 14:21:02 +08:00
2026-08-20 13:42:44 +08:00
2026-08-07 18:48:07 +08:00
2026-08-07 18:48:07 +08:00
2026-08-07 18:48:07 +08:00
2026-08-07 18:48:07 +08:00
2026-08-07 18:48:07 +08:00
2026-08-06 14:21:02 +08:00
2026-08-06 14:17:19 +08:00
2026-08-06 14:17:19 +08:00
2026-08-20 13:42:44 +08:00
2026-07-23 01:57:44 +08:00
2026-08-06 14:21:02 +08:00
2026-05-21 15:33:47 +08:00
2026-05-27 22:22:26 +08:00
2026-05-27 22:22:26 +08:00
2026-08-10 11:55:05 +08:00
2026-08-19 01:06:25 +08:00
2026-08-20 13:42:44 +08:00
2026-08-20 02:35:29 +08:00
2026-08-19 19:29:15 +08:00
2026-08-20 02:35:29 +08:00
2026-08-19 19:29:15 +08:00
2026-08-19 19:29:15 +08:00
2026-08-20 02:35:29 +08:00
2026-08-20 02:35:29 +08:00
2026-08-20 02:35:29 +08:00
2026-08-19 19:29:15 +08:00
2026-08-19 01:06:25 +08:00
2026-07-13 13:22:02 +08:00
2026-08-18 18:49:01 +08:00
2026-08-18 18:49:01 +08:00
2026-06-21 23:54:58 +08:00
2026-08-18 18:49:01 +08:00
2026-08-19 17:03:06 +08:00
2026-08-19 17:03:06 +08:00
2026-07-30 21:01:48 +08:00
2026-07-30 21:01:48 +08:00
2026-08-20 13:42:44 +08:00
2026-07-17 11:11:52 +08:00
2026-08-19 14:06:59 +08:00
2026-08-06 15:36:02 +08:00
2026-08-11 02:23:11 +08:00
2026-07-02 18:31:45 +08:00
2026-07-08 16:00:17 +08:00
2026-05-06 14:31:33 +08:00
2026-05-06 14:31:33 +08:00
2026-06-11 13:00:56 +08:00
2026-08-19 14:37:08 +08:00
2026-08-19 14:37:08 +08:00
2026-08-03 17:43:03 +08:00
2026-08-03 17:43:03 +08:00
2026-07-30 20:34:01 +08:00
2026-07-29 16:03:26 +08:00
2026-07-30 20:34:01 +08:00
2026-07-30 20:34:01 +08:00
2026-07-30 20:34:01 +08:00
2026-08-19 14:37:08 +08:00
2026-08-19 14:37:08 +08:00
2026-05-03 11:13:34 +08:00
2026-07-30 20:34:01 +08:00
2026-08-03 12:39:27 +08:00
2026-08-03 12:39:27 +08:00
2026-07-02 14:38:05 +08:00
2026-08-03 12:39:27 +08:00
2026-08-03 12:39:27 +08:00
2026-08-13 15:31:49 +08:00
2026-08-03 12:39:27 +08:00
2026-08-20 13:42:44 +08:00
2026-07-16 13:54:01 +08:00
2026-08-03 13:35:04 +08:00
2026-08-19 14:37:08 +08:00
2026-08-19 14:37:08 +08:00
2026-07-16 13:54:01 +08:00
2026-08-03 13:35:04 +08:00
2026-08-13 17:55:09 +08:00
2026-08-17 12:16:21 +08:00
2026-08-07 12:33:47 +08:00
2026-08-07 12:33:47 +08:00
2026-07-06 12:34:51 +08:00
2026-07-06 12:34:51 +08:00
2026-08-17 14:39:32 +08:00
2026-08-18 03:00:21 +08:00
2026-08-13 13:48:18 +08:00
2026-06-30 14:46:46 +08:00
2026-06-30 14:46:46 +08:00
2026-06-11 13:00:56 +08:00
2026-07-22 15:38:38 +08:00
2026-08-13 13:48:18 +08:00
2026-08-13 13:48:18 +08:00
2026-06-01 15:19:42 +08:00
2026-07-22 14:38:31 +08:00
2026-08-18 14:17:14 +08:00
2026-06-29 14:09:34 +08:00
2026-07-09 15:07:11 +08:00
2026-05-13 18:46:20 +08:00
2026-08-06 21:05:21 +08:00
2026-08-06 21:05:21 +08:00
2026-08-20 11:32:17 +08:00
2026-07-15 03:09:56 +08:00
2026-07-08 14:51:54 +08:00
2026-07-03 14:18:43 +08:00
2026-08-07 12:40:12 +08:00
2026-05-14 14:07:26 +08:00
2026-08-20 11:32:17 +08:00
2026-08-19 16:33:48 +08:00
2026-07-15 03:09:56 +08:00
2026-08-20 13:42:44 +08:00
2026-07-31 16:52:17 +08:00
2026-07-31 16:52:17 +08:00
2026-05-11 12:39:45 +08:00
2026-07-31 16:52:17 +08:00
2026-08-04 16:47:17 +08:00
2026-08-20 01:30:58 +08:00
2026-07-14 13:16:50 +08:00
2026-08-05 19:14:33 +08:00
2026-08-19 23:04:26 +08:00
2026-08-19 23:04:26 +08:00
2026-07-31 14:40:16 +08:00
2026-07-16 15:23:56 +08:00
2026-06-02 14:29:29 +08:00
2026-05-21 15:33:47 +08:00
2026-08-20 13:42:44 +08:00
2026-07-24 16:39:22 +08:00
2026-07-24 16:39:22 +08:00
2026-08-17 18:32:02 +08:00
2026-07-24 16:39:22 +08:00
2026-08-19 15:51:26 +08:00
2026-08-19 15:51:26 +08:00
2026-08-20 13:42:44 +08:00
2026-08-17 12:51:39 +08:00
2026-08-17 12:51:39 +08:00
2026-08-08 19:20:38 +08:00
2026-08-08 02:01:43 +08:00
2026-08-08 19:20:38 +08:00
2026-08-12 14:09:48 +08:00
2026-08-11 02:23:11 +08:00
2026-08-19 19:29:15 +08:00
2026-08-12 14:09:48 +08:00
2026-08-14 19:49:37 +08:00
2026-08-14 19:49:37 +08:00
2026-08-14 19:49:37 +08:00
2026-08-14 19:49:37 +08:00
2026-08-14 19:49:37 +08:00
2026-05-08 19:14:12 +08:00
2026-08-11 13:46:48 +08:00
2026-08-19 03:09:59 +08:00
2026-08-19 15:51:26 +08:00
2026-08-20 01:30:58 +08:00