Task: Design AuditLog Database Schema and Create Migration Deliverables: - AuditLog entity with multi-tenant support - EF Core configuration with JSONB columns - Database migration with composite indexes - Multi-tenant query filter Status: completed (actual: 2 hours, estimated: 4 hours) All acceptance criteria met. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2.1 KiB
2.1 KiB
task_id, story, status, estimated_hours, actual_hours, created_date, start_date, completion_date, assignee
| task_id | story | status | estimated_hours | actual_hours | created_date | start_date | completion_date | assignee |
|---|---|---|---|---|---|---|---|---|
| sprint_2_story_1_task_1 | sprint_2_story_1 | completed | 4 | 2 | 2025-11-05 | 2025-11-05 | 2025-11-05 | Backend Team |
Task 1: Design AuditLog Database Schema and Create Migration
Story: Story 1 - Audit Log Foundation (Phase 1) Estimated: 4 hours
Description
Design and implement the AuditLog database table schema with proper columns, data types, and indexes to support efficient audit querying and multi-tenant isolation.
Acceptance Criteria
- Database migration created with AuditLog table
- All required columns defined with correct data types
- Composite indexes created for query optimization
- Multi-tenant isolation enforced (TenantId column)
- Migration applied successfully
Implementation Details
Table Schema:
CREATE TABLE AuditLogs (
Id UUID PRIMARY KEY,
TenantId UUID NOT NULL,
EntityType VARCHAR(100) NOT NULL,
EntityId UUID NOT NULL,
Action VARCHAR(20) NOT NULL, -- 'Create', 'Update', 'Delete'
UserId UUID NULL,
Timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW(),
OldValues JSONB NULL,
NewValues JSONB NULL,
CONSTRAINT FK_AuditLogs_Tenants FOREIGN KEY (TenantId) REFERENCES Tenants(Id) ON DELETE CASCADE
);
-- Indexes for query performance
CREATE INDEX IX_AuditLogs_TenantId_EntityType_EntityId ON AuditLogs(TenantId, EntityType, EntityId);
CREATE INDEX IX_AuditLogs_Timestamp ON AuditLogs(Timestamp DESC);
CREATE INDEX IX_AuditLogs_UserId ON AuditLogs(UserId);
Files to Modify:
- Create:
colaflow-api/src/ColaFlow.Infrastructure/Data/Migrations/{timestamp}_AddAuditLogTable.cs
Technical Notes
- Use PostgreSQL JSONB for
OldValues/NewValues(flexible schema, indexed queries) - Composite index on
(TenantId, EntityType, EntityId)for efficient entity history queries Timestampindex with DESC order for recent logs queries- Consider table partitioning for future scalability (Phase 4)
Testing
- Verify migration runs without errors
- Check indexes are created
- Verify foreign key constraints work
Created: 2025-11-05 by Backend Agent