AshArcadic. Replicant. Verifiers. ValidatePrimaryKeyNotSkipped
(AshArcadic v0.2.0)
Copy Markdown
View Source
Compile-verifier for a replicant CDC mirror target's primary key
(build-blocking under --warnings-as-errors).
The mirror's primary key is the identity the sink MATCHes on (the upsert?: true
MERGE identity and the by-PK destroy). The sink builds the write inputs with
Resolver.attrs_for_upsert/2, which DROPS every replicant-skip source column.
The upsert's separate reject_empty_identity! guard checks only the RAW source
record, so a skip-listed primary-key column passes that check yet is dropped
from the write inputs — Ash.create!(upsert?: true) then runs WITHOUT the
identity: a UUID primary key gets a fresh random value on every apply (duplicate
vertices; a later by-PK destroy can never find them), silently breaking
effect-once.
The replicant skip list names SOURCE (Postgres) columns, which map 1:1 to the
target attribute of the same name (there is no rename DSL), so "a primary-key
attribute's source column is skipped" is statically decidable at compile time:
no primary-key attribute's name may appear in the replicant skip list. The
remedy is to remove the primary key from skip (a mirror identity must be
written to be matchable), mirroring ValidatePrimaryKeyNotSensitive — the other
compile guard on the plaintext mirror identity.