Skip to content

feat(repositories): base record columns for mutable and append-only tables (XWING-2363) - #9

Merged
smith-xyz merged 2 commits into
mainfrom
feat/base-record-columns
Oct 20, 2026
Merged

smith-xyz merged 2 commits into
mainfrom
feat/base-record-columns

Conversation

@smith-xyz

Copy link
Copy Markdown
Contributor

What

The two table shapes from the target data model, ready to use as bases:

  • Mutable tables: record_columns() — UUIDv4 id + created_at + updated_at; model base Entity
  • Append-only tables (ledger events, decision, sbom, …): append_only_columns() — UUIDv4 id + created_at only; model base AppendOnly

The database owns identity and time

  • id: gen_random_uuid() on Postgres; uuid() on SQLite, driver-registered by create_database_engine (matching contracts' DEFAULT (uuid()))
  • created_at / updated_at: DB defaults — now() on Postgres, contracts' millisecond-Z strftime on SQLite (_DbNow)
  • updated_at on update is kept by the contracts <table>_touch trigger — the SQLAlchemy onupdate is gone; _update_record re-reads it on SQLite (AFTER triggers are invisible to RETURNING there)
  • New RecordUuid column type: native UUID on Postgres, hyphenated text on SQLite so lookups match the stored form
  • UtcTimestamp binds the same text format so ordering survives mixed writers

The app supplies only domain times (occurred_at, observed_at, …) via Clock; id is None = not saved, add/update return the saved record via RETURNING.

Tests

Contract tests over sqlite + Postgres in tests/v1/repositories/test_sql.py, including a contracts-shaped touch trigger on the test table and a raw-SQL update test proving updated_at is maintained for writers outside the app. Lint, 649 unit tests, coverage 92%.

Note: local make test-integration can fail with column "severity" does not exist when the shared traust_test container holds the in-flight one-owner DDL — environmental, unrelated to this change (CI uses its own container).

Tracker: XWING-2363

@smith-xyz
smith-xyz merged commit cf0d614 into main Oct 20, 2026
5 checks passed
@smith-xyz
smith-xyz deleted the feat/base-record-columns branch October 20, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant