Skip to content

Adopt what Auditing 1.0.0-preview.3 makes possible - #7

Merged
sadeqabuhattem merged 2 commits into
mainfrom
explore/auditing-preview.3
Nov 15, 2026
Merged

sadeqabuhattem merged 2 commits into
mainfrom
explore/auditing-preview.3

Conversation

@sadeqabuhattem

Copy link
Copy Markdown
Member

Auditing 1.0.0-preview.3 (with MultiLingual 1.0.0-preview.3) makes three things safe that this sample used to avoid. This PR adopts all three, and fixes an upgrade bug that running the sample through Aspire on a real data volume turned up.

What changes

HiLo keys dropped. Category and Product are identity columns again. A creation's Created entry is now written in Auditing's nested save, after the INSERT generates the id, in the same transaction.

  • DatabaseInitialiser.RestoreIdentityKeysAsync upgrades a volume from the HiLo builds. It adds the identity where a key column has none, then moves the counter past the highest row and past the last block each HiLo sequence handed out.
  • That second part matters: a row created and deleted during the HiLo builds leaves no row, but its audit trail remains, addressed by its id. The first version aligned only to the surviving rows. On a real volume it handed a deleted product's id out again, and the new product's trail began with the old one's history.
  • The old CategoryIds / ProductIds sequences are left in place and unused. Stop an older build before the new one first boots.

EnableRetryOnFailure() on the Npgsql options. A save MultiLingual replays under the retrying strategy is now recorded once. The interceptor registration order is unchanged; the suite also passes with UseAuditing(sp) registered first.

OnLostAtomicity is read from the Auditing:OnLostAtomicity setting (default Report). The test host sets it to Throw.

Tests

172 tests pass against the published packages (-p:UseLocalDotNetBoost=false), up from 163.

  • SchemaUpgradeTests covers both kinds of HiLo-era database (key created without identity, or identity kept), each with a deleted HiLo block. Both tests fail without the restore, and failed before the HiLo-block fix.
  • AuditTrailTests, in both modes:
    • A trigger fails a creation's translation write, and nothing is left behind. Against Auditing preview.2, with Auditing registered first and no retrying strategy, this fails.
    • A trigger raises one transient failure; the retried creation is recorded once and the trigger is seen to run twice. With the strategy off it fails.
    • Two checks that the suite really runs under the retrying strategy and Throw.

Checked by hand

Through aspire run, built against the published packages:

  • On an existing HiLo-era volume: the API life cycle (create, update, delete, refused write, image upload, settings save) passed 29/29 checks; the dashboard created and edited a category in two languages; the Audit page showed the entries.
  • A database created from scratch by main (HiLo), then booted with this branch: the identity was added, new ids started after the HiLo block, and a product deleted under HiLo kept its own trail.

Not covered

  • An empty volume through aspire run (covered by the test suite's fresh databases).
  • The test projects run on net10.0 only.

🤖 Generated with Claude Code

sadeqabuhattem and others added 2 commits November 14, 2026 23:27
Three optional changes that preview.3 of Auditing and MultiLingual make safe:

- Drop the HiLo keys. Category and Product are identity columns again, so a
  creation's Created entry is written in Auditing's nested save.
  DatabaseInitialiser.RestoreIdentityKeysAsync replaces the sequence upgrade:
  it gives a HiLo-era volume's key columns their identity back and moves the
  counter past the existing rows, forward only. SchemaUpgradeTests now covers
  both kinds of older volume (created with HiLo keys, or kept its identity
  through the HiLo builds); both fail with the restore disabled. Stop an older
  build before the new one first boots: it keeps handing out HiLo ids.
- EnableRetryOnFailure() on the Npgsql options. A replayed save is now
  recorded once. The suite also passes with UseAuditing(sp) registered before
  UseMultiLingual(sp); the shipped order is unchanged.
- OnLostAtomicity through the Auditing:OnLostAtomicity setting (default
  Report). The test host sets it to Throw, so a non-atomic composition fails
  a test instead of logging an error.

Two tests check the retrying strategy and the Throw setting are in force.
README section 6, the test counts and the comments that gave HiLo as the
reason for one save per creation are updated.

168 tests pass against the published packages (UseLocalDotNetBoost=false).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Running the sample through Aspire on a real data volume from the HiLo builds
found that RestoreIdentityKeysAsync moved the identity counter only past the
highest surviving row. A product created and deleted during those builds left
no row but kept its audit trail, so its id was handed out again and the new
product's trail began with the old one's history. The counter now also goes
past the last block each HiLo sequence handed out (its last value plus the
increment, less one). SchemaUpgradeTests leaves a deleted block in both kinds
of older database; both tests failed before the fix.

Two tests in AuditTrailTests, in both modes, for the save path the identity
keys bring in:
- A trigger fails a creation's translation write: no product, text or
  Created entry is left. Against Auditing preview.2 with Auditing registered
  first and no retrying strategy it fails, in both modes.
- A trigger raises one transient serialization failure: EF's retrying
  strategy replays the save, the trigger is seen to run twice, and the
  product and its Created entry exist once. With the strategy off it fails.

Also checked by hand through Aspire against the published packages: the API
life cycle and the dashboard on the real volume, and a database created from
scratch by the HiLo build on main, upgraded by this build.

172 tests pass against the published packages (UseLocalDotNetBoost=false).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sadeqabuhattem
sadeqabuhattem merged commit e551946 into main Nov 15, 2026
2 checks passed
@sadeqabuhattem
sadeqabuhattem deleted the explore/auditing-preview.3 branch November 15, 2026 19:38
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