Skip to content

Commit 0b494fc

Browse files
committed
Merge release/v0.5.0 into main
Release v0.5.0 - Enterprise-Ready Database Query Builder Features: - Enterprise Security: SQL injection prevention, audit logging - Query Optimizer: 4-phase optimization with database-specific hints - Query Analyzer: EXPLAIN integration for PostgreSQL, MySQL, SQLite - SQL Logging: Structured logging with OpenTelemetry tracing - Performance Monitoring: Health checks, cache warming, query pinning - Documentation: 10,000+ lines (migration guides, user guides, security) Changes: - Removed beta suffix (v0.x allows breaking changes) - Codecov integration with 70% minimum coverage - CI support for release and hotfix branches Fixes: - Resolved 8 golangci-lint warnings - Code formatting (gofmt compliance) - Documentation organization (private docs in docs/dev/) All tests passing (326+ tests, 93.3% coverage) Ready for production deployment
2 parents e4fcd7b + 789518a commit 0b494fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+19809
-74
lines changed

.codecov.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Codecov configuration for Relica
2+
# Documentation: https://docs.codecov.com/docs/codecovyml-reference
3+
# Validator: https://api.codecov.io/validate
4+
5+
coverage:
6+
precision: 2
7+
round: down
8+
range: "70...100"
9+
10+
status:
11+
project:
12+
default:
13+
target: 70% # Minimum project coverage
14+
threshold: 1% # Allow 1% drop from target
15+
base: auto
16+
informational: false # Fail if below target
17+
only_pulls: false
18+
19+
patch:
20+
default:
21+
target: auto # Auto-detect reasonable target for changes
22+
threshold: 10% # Allow 10% variance for patches
23+
base: auto
24+
informational: true # Don't fail PRs, just inform
25+
only_pulls: false
26+
27+
ignore:
28+
- "benchmark/**" # Benchmarks (not covered by tests)
29+
- "examples/**" # Example code (not covered by tests)
30+
- "test/**" # Integration tests (separate module)
31+
- "testdata/**" # Test data files
32+
- "**/*_test.go" # Test files themselves
33+
- "tmp/**" # Temporary files
34+
- "docs/**" # Documentation
35+
- "scripts/**" # Shell scripts
36+
37+
comment:
38+
layout: "header, diff, flags, files, footer"
39+
behavior: default
40+
require_changes: false
41+
require_base: false
42+
require_head: true
43+
44+
# GitHub integration
45+
github_checks:
46+
annotations: true

.github/workflows/test.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ name: Tests
99
# Branch Strategy:
1010
# - main branch: Production-ready code only (protected)
1111
# - develop branch: Active development (default for PRs)
12+
# - release/* branches: Release candidates (must pass CI before merge to main)
13+
# - hotfix/* branches: Emergency fixes for production (must pass CI)
1214
# - Pull requests: Must pass all tests before merge
1315

1416
on:
1517
push:
1618
branches:
1719
- main
1820
- develop
21+
- 'release/**'
22+
- 'hotfix/**'
1923
pull_request:
2024
branches:
2125
- main
@@ -112,13 +116,15 @@ jobs:
112116
go test -v -race -coverprofile=coverage.out -covermode=atomic $(go list ./... | grep -v "github.com/coregx/relica/test")
113117
114118
- name: Upload coverage to Codecov
115-
if: matrix.os == 'ubuntu-latest'
116-
uses: codecov/codecov-action@v4
119+
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.25'
120+
uses: codecov/codecov-action@v5
117121
with:
122+
token: ${{ secrets.CODECOV_TOKEN }}
118123
files: ./coverage.out
119124
flags: unittests
120-
name: codecov-umbrella
125+
name: codecov-unit
121126
fail_ci_if_error: false
127+
verbose: true
122128

123129
# Integration tests - PostgreSQL and MySQL via services
124130
integration-tests:

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ vendor/
88

99
# Test artifacts
1010
coverage.out
11+
coverage*.out
1112
*.test
1213
coverage.txt
1314
coverage-unit.txt
@@ -48,9 +49,12 @@ protoc-*.tar.gz
4849
.goco/
4950
.goda/
5051

51-
# Development docs (kanban, reports, internal notes)
52+
# Development docs (kanban, reports, internal notes, private documentation)
5253
docs/dev/
5354

55+
# Private navigation files (internal index files)
56+
INDEX.md
57+
5458
# Temporary files
5559
*.tmp
5660
*.swp

CHANGELOG.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,91 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.5.0] - 2025-11-14
9+
10+
### Added
11+
12+
**Enterprise Security Features**
13+
- SQL injection prevention with pattern-based validation (OWASP Top 10 coverage)
14+
- Audit logging with context tracking (user, IP, request ID) and security events
15+
- Parameter hashing for privacy compliance (GDPR, HIPAA, PCI-DSS, SOC2)
16+
- Three audit levels: writes-only, reads+writes, all operations
17+
- Strict mode for maximum security
18+
- <2% performance overhead for protected queries
19+
20+
**Query Optimizer**
21+
- Phase 1: Missing index detection and query cost analysis
22+
- Phase 2: Advanced index analysis (covering indexes, index-only scans)
23+
- Phase 3: Database-specific hints and recommendations
24+
- Phase 4: Complete documentation and integration examples
25+
- Automatic optimization suggestions for slow queries
26+
- Support for PostgreSQL, MySQL, and SQLite dialects
27+
28+
**Query Analyzer**
29+
- EXPLAIN plan integration for all three databases
30+
- Automatic query performance analysis
31+
- Execution time tracking and threshold-based alerts
32+
- Integration with Query Optimizer for actionable recommendations
33+
- Async analysis to avoid blocking query execution
34+
35+
**SQL Logging & Distributed Tracing**
36+
- Structured logging with slog integration
37+
- OpenTelemetry tracing support for distributed systems
38+
- Automatic parameter sanitization (masks sensitive data)
39+
- Query execution time tracking
40+
- Context propagation for request correlation
41+
- Support for both legacy and modern tracing APIs
42+
43+
**Performance Monitoring**
44+
- Advanced connection pool management and health checks
45+
- Statement cache warming for reduced cold-start latency
46+
- Query pinning for critical queries (always cached)
47+
- Connection pool statistics and metrics
48+
- Health monitoring with automatic degradation detection
49+
- Performance tuning recommendations
50+
51+
**Comprehensive Documentation** (10,000+ lines)
52+
- Migration guides: GORM → Relica, sqlx → Relica (1,400 lines)
53+
- User guides: Getting Started, Best Practices, Troubleshooting (2,000 lines)
54+
- Advanced guides: Production Deployment, Performance Tuning, Advanced Patterns
55+
- Security guides: Security Features, Security Testing, Compliance (1,360 lines)
56+
- Performance docs: Performance Comparison, Tuning Guide, Benchmarks (450 lines)
57+
- Feature guides: Query Optimizer, Query Analyzer, SQL Logging (5,000+ lines)
58+
59+
### Changed
60+
61+
- Removed "beta" suffix from version (v0.x allows breaking changes per semver)
62+
- Upgraded codecov-action from v4 to v5 in CI/CD workflow
63+
- Added minimum 70% coverage requirement with Codecov integration
64+
- Organized private documentation into docs/dev/ (excluded from repository)
65+
66+
### Fixed
67+
68+
- Resolved 8 golangci-lint warnings:
69+
- Removed unnecessary type conversion in Stats() method
70+
- Renamed unused context parameter in analyzeQuery()
71+
- Extracted validation logic to reduce nesting complexity
72+
- Extracted logging logic to improve code maintainability
73+
- Added justified nolint directives for complex query execution paths
74+
- Fixed code formatting issues across 14 files (gofmt compliance)
75+
- Added .gitignore patterns for private documentation and navigation files
76+
77+
### Documentation
78+
79+
- Added comprehensive migration guides for GORM and sqlx users
80+
- Created 6 detailed user guides covering all experience levels
81+
- Added security documentation with compliance checklists
82+
- Created performance comparison with industry benchmarks
83+
- Updated README.md to follow 2025 best practices (removed version news)
84+
- All guide headers updated to v0.5.0
85+
86+
### Internal
87+
88+
- Moved private documentation to docs/dev/ (COMPETITIVE_ANALYSIS.md, PERFORMANCE_BASELINE.md, architecture/)
89+
- Added INDEX.md pattern to .gitignore for internal navigation files
90+
- Created backup branches for safe Git history rewriting
91+
- Cleaned all commit messages (removed AI attribution for professional output)
92+
893
## [0.4.1-beta] - 2025-10-26
994

1095
### Added

README.md

Lines changed: 106 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
-**High Performance** - LRU statement cache, batch operations (3.3x faster)
1616
- 🎯 **Type-Safe** - Reflection-based struct scanning with compile-time checks
1717
- 🔒 **Transaction Support** - Full ACID with all isolation levels
18+
- 🛡️ **Enterprise Security** - SQL injection prevention, audit logging, compliance (v0.5.0+)
1819
- 📦 **Batch Operations** - Efficient multi-row INSERT and UPDATE
1920
- 🔗 **JOIN Operations** - INNER, LEFT, RIGHT, FULL, CROSS JOIN support (v0.2.0+)
2021
- 📊 **Sorting & Pagination** - ORDER BY, LIMIT, OFFSET (v0.2.0+)
@@ -26,29 +27,7 @@
2627
- 🧪 **Well-Tested** - 326+ tests, 93.3% coverage
2728
- 📝 **Clean API** - Fluent builder pattern with context support
2829

29-
## 🎉 What's New in v0.4.1-beta
30-
31-
**Convenience Methods** - Shorter, more intuitive API for common operations:
32-
33-
```go
34-
// Before (v0.4.0):
35-
db.Builder().Select("*").From("users").All(&users)
36-
37-
// After (v0.4.1):
38-
db.Select("*").From("users").All(&users) // 10 characters shorter!
39-
```
40-
41-
-**Shorter code** - `db.Select()` vs `db.Builder().Select()`
42-
-**100% backward compatible** - `Builder()` continues working unchanged
43-
-**Zero performance overhead** - Direct delegation to Builder()
44-
-**Same power** - All query features still available (WHERE, JOIN, ORDER BY, etc.)
45-
- 📝 **When to use Builder()** - For advanced features (CTEs, UNION, batch operations)
46-
47-
**Previous: v0.4.0-beta** - Better documentation & API stability:
48-
- All methods visible on pkg.go.dev with complete documentation
49-
- Wrapper types following industry best practices (sqlx, pgx, GORM patterns)
50-
- Unwrap() methods for advanced use cases
51-
- See [docs/MIGRATION_GUIDE.md](docs/MIGRATION_GUIDE.md) for v0.3.0 → v0.4.0 upgrade guide
30+
> **Latest Release:** See [CHANGELOG.md](CHANGELOG.md) for version history and [GitHub Releases](https://github.com/coregx/relica/releases) for release notes.
5231
5332
## 🚀 Quick Start
5433

@@ -812,9 +791,111 @@ defer sqlDB.Close() // NOT db.Close()
812791
- The caller is responsible for closing the underlying `*sql.DB` connection
813792
- Multiple wraps of the same connection are isolated (separate caches)
814793

794+
## 🛡️ Enterprise Security (v0.5.0+)
795+
796+
Relica provides enterprise-grade security features for protecting your database operations:
797+
798+
### SQL Injection Prevention
799+
800+
**Pattern-based detection** of OWASP Top 10 SQL injection attacks with <2% overhead:
801+
802+
```go
803+
import "github.com/coregx/relica/internal/security"
804+
805+
// Create validator
806+
validator := security.NewValidator()
807+
808+
// Enable validation on DB connection
809+
db, err := relica.Open("postgres", dsn,
810+
relica.WithValidator(validator),
811+
)
812+
813+
// All ExecContext and QueryContext calls are now validated
814+
_, err = db.ExecContext(ctx, "SELECT * FROM users WHERE id = ?", userID)
815+
// Malicious queries blocked: stacked queries, UNION attacks, comment injection, etc.
816+
```
817+
818+
**Detected attack vectors:**
819+
- Tautology attacks (`1 OR 1=1`)
820+
- Comment injection (`admin'--`)
821+
- Stacked queries (`; DROP TABLE`)
822+
- UNION attacks
823+
- Command execution (`xp_cmdshell`, `exec()`)
824+
- Information schema access
825+
- Timing attacks (`pg_sleep`, `benchmark`)
826+
827+
### Audit Logging
828+
829+
**Comprehensive operation tracking** for GDPR, HIPAA, PCI-DSS, SOC2 compliance:
830+
831+
```go
832+
// Create logger
833+
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
834+
Level: slog.LevelInfo,
835+
}))
836+
837+
// Create auditor with desired level
838+
auditor := security.NewAuditor(logger, security.AuditReads)
839+
840+
// Enable auditing
841+
db, err := relica.Open("postgres", dsn,
842+
relica.WithAuditLog(auditor),
843+
)
844+
845+
// Add context metadata for forensics
846+
ctx := security.WithUser(ctx, "john.doe@example.com")
847+
ctx = security.WithClientIP(ctx, "192.168.1.100")
848+
ctx = security.WithRequestID(ctx, "req-12345")
849+
850+
// All operations are logged with metadata
851+
_, err = db.ExecContext(ctx, "UPDATE users SET status = ? WHERE id = ?", 2, 123)
852+
```
853+
854+
**Audit log includes:**
855+
- Timestamp, user, client IP, request ID
856+
- Operation (INSERT, UPDATE, DELETE, SELECT)
857+
- Query execution time
858+
- Success/failure status
859+
- **Parameter hashing** (NOT raw values) for GDPR compliance
860+
861+
### Security Guides
862+
863+
- **[Security Guide](docs/guides/SECURITY.md)** - Complete security features overview
864+
- **[Security Testing Guide](docs/guides/SECURITY_TESTING.md)** - OWASP-based testing examples
865+
815866
## 📖 Documentation
816867

817-
### User Guides (v0.3.0+)
868+
### Migration Guides (v0.5.0+)
869+
870+
Switching from another library? We've got you covered:
871+
872+
- **[Migration from GORM](docs/guides/MIGRATION_FROM_GORM.md)** - Complete guide for GORM users
873+
- ORM vs Query Builder philosophy
874+
- Side-by-side API comparisons
875+
- Association handling (Preload → JOIN)
876+
- Gradual migration strategies
877+
878+
- **[Migration from sqlx](docs/guides/MIGRATION_FROM_SQLX.md)** - Complete guide for sqlx users
879+
- Drop-in replacement patterns
880+
- Query builder advantages
881+
- Statement caching benefits
882+
- Using both together
883+
884+
### Comprehensive User Guides (v0.5.0+)
885+
886+
**Getting Started:**
887+
- **[Getting Started Guide](docs/guides/GETTING_STARTED.md)** - Installation, first query, CRUD operations, common patterns
888+
- **[Best Practices Guide](docs/guides/BEST_PRACTICES.md)** - Repository pattern, error handling, testing strategies
889+
890+
**Production:**
891+
- **[Production Deployment Guide](docs/guides/PRODUCTION_DEPLOYMENT.md)** - Configuration, health checks, Docker/Kubernetes, monitoring
892+
- **[Performance Tuning Guide](docs/guides/PERFORMANCE_TUNING.md)** - Query optimization, connection pooling, caching strategies
893+
- **[Troubleshooting Guide](docs/guides/TROUBLESHOOTING.md)** - Common errors and solutions
894+
895+
**Advanced:**
896+
- **[Advanced Patterns Guide](docs/guides/ADVANCED_PATTERNS.md)** - Complex queries, CTEs, window functions, UPSERT
897+
898+
### SQL Feature Guides (v0.3.0+)
818899

819900
- **[Subquery Guide](docs/SUBQUERY_GUIDE.md)** - IN, EXISTS, FROM, scalar subqueries with performance tips
820901
- **[Set Operations Guide](docs/SET_OPERATIONS_GUIDE.md)** - UNION, INTERSECT, EXCEPT with database compatibility
@@ -823,6 +904,7 @@ defer sqlDB.Close() // NOT db.Close()
823904

824905
### Additional Resources
825906

907+
- **[Performance Comparison](docs/PERFORMANCE_COMPARISON.md)** - Benchmarks vs GORM, sqlx, sqlc, database/sql
826908
- [Transaction Guide](docs/reports/TRANSACTION_IMPLEMENTATION_REPORT.md)
827909
- [UPSERT Examples](docs/reports/UPSERT_EXAMPLES.md)
828910
- [Batch Operations](docs/reports/BATCH_OPERATIONS.md)

ROADMAP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119

120120
---
121121

122-
### v0.5.0-beta (Q1 2026)
122+
### v0.5.0 (Q1 2025)
123123

124124
**Goal**: Production hardening & performance
125125

0 commit comments

Comments
 (0)