Column Ordering Standards & UUIDv7 Keys
To maximize developer ergonomics in C# while enforcing deterministic, professional database schemas:
- In C# Domain Entities: All properties MUST be declared in Alphabetical Order (A-Z).
- In Physical PostgreSQL Tables: Metadata columns are enforced at positions 0 to 10 via EF Core
.HasColumnOrder(), while business columns begin sequentially at position 11+ in logical domain order:
| Column Position | Column Name | Type | Description |
|---|---|---|---|
| 0 | id |
uuid |
Primary Key (Guid v7) |
| 1 | tenant_id |
uuid |
Tenant isolation key (if entity implements IMustHaveTenant) |
| 2 | branch_id |
uuid |
Branch isolation key (if entity implements IMustHaveBranch) |
| 3 | created_at |
timestamptz |
Audit creation timestamp |
| 4 | created_by |
uuid |
User ID who created the record |
| 5 | last_modified_at |
timestamptz |
Audit last update timestamp |
| 6 | last_modified_by |
uuid |
User ID who last updated the record |
| 7 | is_deleted |
boolean |
Soft-delete flag |
| 8 | deleted_at |
timestamptz |
Audit soft-deletion timestamp |
| 9 | deleted_by |
uuid |
User ID who soft-deleted the record |
| 10 | version |
integer |
Optimistic concurrency control version |
| 11+ | Business columns | varies | Specific business domain attributes in logical order |
2. Guid v7 (UUIDv7) as Standard Primary Key
Section titled “2. Guid v7 (UUIDv7) as Standard Primary Key”100% of domain entities and aggregates use Guid.CreateVersion7() as their primary key.
Why UUIDv7?
Section titled “Why UUIDv7?”- Temporal Sorting: The first 48 bits encode a Unix timestamp with millisecond precision, ensuring records naturally sort in chronological order.
- B-Tree Index Performance: Eliminates the random insertion fragmentation caused by UUIDv4, maintaining high-throughput B-Tree indexing inside PostgreSQL.