Files
archie/internal/infrastructure/postgres/clip.go
T
sam c833081544 feat(postgres): port events/identities/status surfaces, fix shipped defects
CHECKPOINT -- the full State Store port is in progress; this lands the
compile-clean core so the review pass has a diff to work against. Remaining:
advisory-lock ownership, event-insert serialization, maintenance, and the
ported test battery.

Two corrections to behaviour that already shipped, not new features:
- UpdateTask wrote park_reason raw where SQLite applies clip(park_reason,
  4000); the PostgreSQL adapter now clips before binding (clip.go).
- tasks.review_cursor existed on the protobuf wire and in workflow.Task but
  not in the PostgreSQL schema; 0004 adds it as a NEW migration rather than
  amending 0001 because a dev database may already have applied 0001 and
  goose tracks version numbers, not checksums.

Also moves the control-plane Resource/ResourceWrite types and their sentinels
into storecontract so the postgres package can stop importing internal/store
(they stay aliased there for daemon callers).
2026-09-24 02:17:44 +10:00

37 lines
966 B
Go

package postgres
import (
"errors"
"unicode/utf8"
"github.com/jackc/pgx/v5/pgconn"
)
// clip limits s to n bytes without splitting a UTF-8 rune. It is the exact
// write-side normalisation the SQLite store applied before inserting event
// detail, transition detail, park reasons and review payloads: a generated
// query that drops it lets an oversized value through where the old store
// truncated it.
func clip(s string, n int) string {
if len(s) <= n {
return s
}
pos := 0
for pos < len(s) {
_, size := utf8.DecodeRuneInString(s[pos:])
if pos+size > n {
break
}
pos += size
}
return s[:pos]
}
// isUniqueViolation reports whether err is a PostgreSQL unique-constraint
// violation (SQLSTATE 23505), matching the SQLite store's "UNIQUE constraint
// failed" string test rather than grepping driver error text.
func isUniqueViolation(err error) bool {
var pgErr *pgconn.PgError
return errors.As(err, &pgErr) && pgErr.Code == "23505"
}