Dialect-aware child-set aggregation
apps/backend/internal/office/repository/sqlite/wake_receipts.goReturns STRING_AGG with ORDER BY on Postgres and GROUP_CONCAT on SQLite so the SQL key matches the Go key byte for byte.
// childSetKeyAggregate renders the "id:state" concatenation ListStuckParents
// compares against a stored receipt. Its output must match formatChildSetKey
// byte for byte: receipts are written from the Go form and compared against
// this SQL form, so any difference in separator or ordering makes every
// receipt look stale and re-wakes the parent on every tick. Postgres does not
// inherit input ordering from the subquery's ORDER BY, so the ordering is
// restated inside the aggregate.
func childSetKeyAggregate(driver string) string {
if dialect.IsPostgres(driver) {
return `STRING_AGG(c.id || ':' || c.state, ',' ORDER BY c.id)`
}
return `GROUP_CONCAT(c.id || ':' || c.state, ',')`
} COALESCE((
SELECT GROUP_CONCAT(c.id || ':' || c.state, ',')
SELECT `+childSetKeyAggregate(driver)+`
FROM (
SELECT id, state FROM tasks
WHERE parent_id = p.id AND archived_at IS NULL
ORDER BY id
) c
), '') AS child_set_key,