Skip to content

Conversation

@allisson
Copy link
Owner

Replace auto-incrementing integer primary keys with UUIDv7 across the entire application for improved scalability, global uniqueness, and time-ordered sorting capabilities.

Changes:

Database Migrations:

  • PostgreSQL: Change SERIAL to UUID type for all primary keys
  • MySQL: Change BIGINT AUTO_INCREMENT to BINARY(16) for all primary keys
  • Update both users and outbox_events table migrations

Domain Models:

  • user.User: Change ID field from int64 to uuid.UUID
  • outbox.OutboxEvent: Change ID field from int64 to uuid.UUID
  • user/http/dto.UserResponse: Update ID field to uuid.UUID

Application Code:

  • Generate UUIDs in application using uuid.NewV7() instead of database auto-increment
  • User creation: Generate UUID before database insertion
  • OutboxEvent creation: Generate UUID before database insertion
  • Update all repository method signatures to accept uuid.UUID

Repository Layer:

  • user/repository: GetByID() now accepts uuid.UUID parameter
  • All repository implementations compatible with UUID storage

Use Case Layer:

  • user/usecase: Update interfaces and implementations to use uuid.UUID
  • GetUserByID() signature changed to accept uuid.UUID

Tests:

  • Update all test files to use uuid.Must(uuid.NewV7())
  • Update mock implementations for UUID compatibility
  • worker/event_worker_test: Use UUIDs in test fixtures
  • user/repository_test: Use UUIDs in test cases
  • user/usecase_test: Update mock methods and assertions
  • http/http_test: Update handler tests for UUID responses

Dependencies:

  • Add github.com/google/uuid v1.6.0

Documentation:

  • Add comprehensive UUIDv7 section to README.md
  • Document benefits: time-ordering, global uniqueness, scalability
  • Provide implementation examples for new domains
  • Update code examples throughout README

Benefits:

  • Time-ordered IDs maintain temporal sorting
  • Globally unique across distributed systems
  • Better database index performance than random UUIDs
  • No centralized ID generation required
  • Merge-friendly for database consolidation scenarios

Breaking Changes:

  • All ID fields changed from int64 to uuid.UUID
  • API responses now return UUIDs as strings
  • Database schema requires migration

Replace auto-incrementing integer primary keys with UUIDv7 across the
entire application for improved scalability, global uniqueness, and
time-ordered sorting capabilities.

Changes:

Database Migrations:
- PostgreSQL: Change SERIAL to UUID type for all primary keys
- MySQL: Change BIGINT AUTO_INCREMENT to BINARY(16) for all primary keys
- Update both users and outbox_events table migrations

Domain Models:
- user.User: Change ID field from int64 to uuid.UUID
- outbox.OutboxEvent: Change ID field from int64 to uuid.UUID
- user/http/dto.UserResponse: Update ID field to uuid.UUID

Application Code:
- Generate UUIDs in application using uuid.NewV7() instead of database
  auto-increment
- User creation: Generate UUID before database insertion
- OutboxEvent creation: Generate UUID before database insertion
- Update all repository method signatures to accept uuid.UUID

Repository Layer:
- user/repository: GetByID() now accepts uuid.UUID parameter
- All repository implementations compatible with UUID storage

Use Case Layer:
- user/usecase: Update interfaces and implementations to use uuid.UUID
- GetUserByID() signature changed to accept uuid.UUID

Tests:
- Update all test files to use uuid.Must(uuid.NewV7())
- Update mock implementations for UUID compatibility
- worker/event_worker_test: Use UUIDs in test fixtures
- user/repository_test: Use UUIDs in test cases
- user/usecase_test: Update mock methods and assertions
- http/http_test: Update handler tests for UUID responses

Dependencies:
- Add github.com/google/uuid v1.6.0

Documentation:
- Add comprehensive UUIDv7 section to README.md
- Document benefits: time-ordering, global uniqueness, scalability
- Provide implementation examples for new domains
- Update code examples throughout README

Benefits:
- Time-ordered IDs maintain temporal sorting
- Globally unique across distributed systems
- Better database index performance than random UUIDs
- No centralized ID generation required
- Merge-friendly for database consolidation scenarios

Breaking Changes:
- All ID fields changed from int64 to uuid.UUID
- API responses now return UUIDs as strings
- Database schema requires migration
@allisson allisson merged commit 02cba34 into main Jan 24, 2026
1 check passed
@allisson allisson deleted the integration-tests branch January 24, 2026 17:17
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