Skip to content

Conversation

@CBenoit
Copy link
Member

@CBenoit CBenoit commented Dec 2, 2025

Replace INTEGER PRIMARY KEY with 16-byte BLOB (ULID) for traffic audit event IDs to avoid overflow issues with persisted, ever-increasing IDs.

  • Auto-detect old INTEGER schema via PRAGMA table_info and reset database
  • Store ULIDs as 16-byte BLOBs (lexicographically sortable)

Issue: DGW-321
BREAKING CHANGE: The traffic audit HTTP endpoints are now expecting ULIDs instead of integers.

Replace INTEGER PRIMARY KEY with 16-byte BLOB (ULID) for traffic audit
event IDs to avoid overflow issues with persisted, ever-increasing IDs.

- Auto-detect old INTEGER schema via PRAGMA table_info and reset database
- Store ULIDs as 16-byte BLOBs (lexicographically sortable)

Issue: DGW-321
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the traffic audit database from using auto-incrementing INTEGER PRIMARY KEYs to ULIDs (Universally Unique Lexicographically Sortable Identifiers) stored as 16-byte BLOBs to prevent ID overflow issues with persisted, ever-increasing integer values.

Key Changes:

  • Replaced INTEGER PRIMARY KEY with BLOB PRIMARY KEY (16-byte ULID) in the database schema
  • Implemented automatic detection of old INTEGER schema with database reset on first startup
  • Updated API endpoints to use ULID string format instead of i64 integers

Reviewed changes

Copilot reviewed 27 out of 28 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
crates/traffic-audit-libsql/migrations/01_traffic_events.sql Changed id column from INTEGER to BLOB with 16-byte length constraint
crates/traffic-audit-libsql/src/lib.rs Added ULID generator, old schema detection logic, database reset functionality, and ULID/BLOB conversion utilities
crates/traffic-audit-libsql/Cargo.toml Added ulid crate dependency
crates/traffic-audit/src/lib.rs Updated ClaimedEvent struct and TrafficAuditRepo trait to use Ulid instead of i64
crates/traffic-audit/Cargo.toml Added ulid crate dependency
crates/traffic-audit-libsql/tests/integration.rs Updated all integration tests to use Ulid instead of i64 for event IDs
devolutions-gateway/src/traffic_audit.rs Updated TrafficAuditMessage enum and handle methods to use Ulid
devolutions-gateway/src/api/traffic.rs Changed AckRequest and ClaimedTrafficEvent to use Ulid type with OpenAPI schema annotations
devolutions-gateway/Cargo.toml Added ulid crate with serde feature
devolutions-gateway/tests/traffic.rs Updated all API tests to use Ulid instead of i64
testsuite/tests/cli/dgw/traffic_audit.rs Added new test for old schema detection and automatic migration
testsuite/tests/cli/dgw/mod.rs Added traffic_audit test module
testsuite/Cargo.toml Added libsql dependency for test schema verification
devolutions-gateway/openapi/gateway-api.yaml Updated OpenAPI spec to use string type for IDs instead of int64
devolutions-gateway/openapi/ts-angular-client/model/*.ts Updated TypeScript client types from number to string for IDs
devolutions-gateway/openapi/dotnet-client/src/Devolutions.Gateway.Client/Model/*.cs Updated .NET client types from long to string for IDs
devolutions-gateway/openapi/dotnet-client/Devolutions.Gateway.Client.csproj Bumped version to 2025.12.2
devolutions-gateway/openapi/dotnet-client/config.json Updated package version
devolutions-gateway/openapi/dotnet-client/Client/Configuration.cs Updated version constants
devolutions-gateway/openapi/dotnet-client/docs/*.md Updated documentation to reflect string IDs
devolutions-gateway/openapi/doc/index.adoc Updated API documentation with ULID format
docs/COOKBOOK.md Updated example event IDs to ULID format and added ULID documentation notes
devolutions-gateway/src/openapi.rs Consolidated imports (stylistic cleanup, no functional change)
Cargo.lock Added ulid dependency with serde support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@pacmancoder pacmancoder disabled auto-merge December 2, 2025 11:23
Copy link
Contributor

@pacmancoder pacmancoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, disabled auto-merge due to Copilot comments

@CBenoit CBenoit changed the title fix(dgw): switch traffic audit IDs from INTEGER to ULID fix(dgw)!: switch traffic audit IDs from INTEGER to ULID Dec 2, 2025
Comment on lines +19 to +32
thread_local! {
/// Per-thread monotonic ULID generator.
///
/// Using a thread-local generator provides several benefits:
/// - **Strict monotonicity within a thread**: ULIDs generated in sequence on the same
/// thread are guaranteed to be strictly increasing, even when generated within the
/// same millisecond. This ensures predictable ordering in tests and deterministic
/// FIFO behavior for events pushed from the same thread.
/// - **No contention**: Each thread has its own generator instance, eliminating mutex
/// overhead that would occur with a shared generator.
/// - **Lock-free push operations**: The `push` method can generate IDs without acquiring
/// any locks beyond the thread-local cell borrow.
static MONOTONIC_ULID_GENERATOR: std::cell::RefCell<ulid::Generator> = const { std::cell::RefCell::new(ulid::Generator::new()) };
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pacmancoder Here is a likely better approach 👍

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 27 out of 28 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@CBenoit CBenoit enabled auto-merge (squash) December 2, 2025 13:16
@CBenoit CBenoit disabled auto-merge December 2, 2025 13:16
@CBenoit CBenoit enabled auto-merge (squash) December 2, 2025 13:16
@CBenoit CBenoit merged commit b443f93 into master Dec 2, 2025
40 checks passed
@CBenoit CBenoit deleted the fix/traffic-audit-use-ulid-instead-of-integer-ids branch December 2, 2025 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants