- Document current TIMESTAMPTZ compliance across all schemas - Create comprehensive migration template for future use - Include validation queries and best practices - Add examples for different timezone scenarios
5.5 KiB
Timestamp Standardization Plan
Issue: CONF-004
Some tables use TIMESTAMP instead of TIMESTAMPTZ, which can cause timezone issues when dealing with distributed systems and multiple time zones.
Standard
All timestamp columns MUST use TIMESTAMPTZ (timestamp with time zone) to ensure proper timezone handling and consistency across the platform.
Why TIMESTAMPTZ?
- Preserves timezone information in the database
- Prevents ambiguity when dealing with DST (Daylight Saving Time)
- Enables accurate time-based queries across different regions
- Required for financial and trading data accuracy
- Critical for audit logs and compliance
Current Status: COMPLIANT ✓
Last Audit: 2026-02-03
After comprehensive audit of all DDL files in the trading-platform database schema, we found that ALL timestamp columns are already using TIMESTAMPTZ.
Audited Schemas (31 total)
All columns across all schemas conform to the TIMESTAMPTZ standard:
authschema (11 tables)auditschema (7 tables)educationschema (19 tables)feature_flagsschemafinancialschema (11 tables)investmentschema (10 tables)llmschema (5 tables)market_dataschema (4 tables)mlschema (12 tables)portfolioschema (5 tables)tradingschema (13 tables)
Timestamp Columns Verified
The following timestamp column patterns were verified across all tables:
-
System Timestamps:
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()deleted_at TIMESTAMPTZ(for soft deletes)
-
Business Timestamps:
expires_at TIMESTAMPTZverified_at TIMESTAMPTZprocessed_at TIMESTAMPTZcompleted_at TIMESTAMPTZfailed_at TIMESTAMPTZreviewed_at TIMESTAMPTZfilled_at TIMESTAMPTZcancelled_at TIMESTAMPTZlocked_until TIMESTAMPTZsuspended_at TIMESTAMPTZdeactivated_at TIMESTAMPTZ
-
Data Timestamps:
timestamp TIMESTAMPTZ(market data, OHLCV)last_login_at TIMESTAMPTZemail_verified_at TIMESTAMPTZphone_verified_at TIMESTAMPTZ
Migration Strategy
Phase 1: Monitoring (Ongoing)
- Monitor new DDL files for timestamp compliance
- Add pre-commit hook validation (optional enhancement)
- Document any edge cases discovered
Phase 2: Documentation (COMPLETE)
- ✓ Create this standardization plan
- ✓ Document current state and audit results
- ✓ Create migration template for future use
Phase 3: Enforcement (Future)
If any new tables or modifications are needed:
- Use the provided migration template
- Create new column with TIMESTAMPTZ type
- Copy data with timezone conversion
- Drop old column and rename new
- Update application code if needed
- Test thoroughly in staging
Reference Examples
Audit Results by Table Type
Audit Tables
audit.audit_logs.created_at→ TIMESTAMPTZ ✓audit.security_events.created_at→ TIMESTAMPTZ ✓audit.compliance_logs.created_at→ TIMESTAMPTZ ✓audit.compliance_logs.reviewed_at→ TIMESTAMPTZ ✓audit.api_request_logs.created_at→ TIMESTAMPTZ ✓
Authentication Tables
auth.users.created_at→ TIMESTAMPTZ ✓auth.users.email_verified_at→ TIMESTAMPTZ ✓auth.users.last_login_at→ TIMESTAMPTZ ✓auth.email_verifications.expires_at→ TIMESTAMPTZ ✓auth.sessions.expires_at→ TIMESTAMPTZ ✓
Financial/Trading Tables
financial.wallet_transactions.created_at→ TIMESTAMPTZ ✓financial.wallet_transactions.processed_at→ TIMESTAMPTZ ✓financial.wallet_transactions.completed_at→ TIMESTAMPTZ ✓trading.orders.created_at→ TIMESTAMPTZ ✓trading.orders.filled_at→ TIMESTAMPTZ ✓trading.orders.cancelled_at→ TIMESTAMPTZ ✓
Market Data Tables
market_data.ohlcv_5m.timestamp→ TIMESTAMPTZ ✓market_data.ohlcv_5m.created_at→ TIMESTAMPTZ ✓market_data.ohlcv_15m.timestamp→ TIMESTAMPTZ ✓
ML/Investment Tables
ml.predictions.created_at→ TIMESTAMPTZ ✓investment.transactions.created_at→ TIMESTAMPTZ ✓
Migration Template
See: 2026-02-03_standardize_timestamps_template.sql
Best Practices
- Always use TIMESTAMPTZ for timestamp columns
- Default to NOW() for automatic current timestamp
- Use UTC internally in application code
- Convert to user timezone in UI layer
- Document timezone handling in application code
- Test DST transitions in your time conversion logic
Validation Queries
To verify TIMESTAMPTZ compliance on any table:
-- Check all timestamp columns in a table
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_schema = 'schema_name'
AND table_name = 'table_name'
AND data_type LIKE '%timestamp%'
ORDER BY ordinal_position;
-- Verify entire database compliance
SELECT table_schema, table_name, column_name, data_type
FROM information_schema.columns
WHERE data_type LIKE '%timestamp%'
ORDER BY table_schema, table_name;
Priority: P0 (Complete - No Action Required)
This is a documentation of the existing compliant state. All code adheres to TIMESTAMPTZ standards.
Change Log
| Date | Change | Status |
|---|---|---|
| 2026-02-03 | Initial audit and documentation | COMPLETE |
Related Documentation
- PostgreSQL TIMESTAMPTZ docs: https://www.postgresql.org/docs/current/datatype-datetime.html
- @ESTANDAR-DATABASE: docs/40-estandares/ESTANDAR-DATABASE-PROFESIONAL.md
- @TRIGGER-COHERENCIA: orchestration/directivas/triggers/TRIGGER-COHERENCIA-CAPAS.md