Releases: andrei-polukhin/pgdbtemplate
🚀 v1.0.0: Lightning-Fast PostgreSQL Test Databases Go Stable!
pgdbtemplate v1.0.0 - First Stable Release
We're thrilled to announce the first stable release of pgdbtemplate, a high-performance Go library that revolutionizes PostgreSQL testing by leveraging template databases for lightning-fast test execution.
🎯 What is pgdbtemplate?
pgdbtemplate provides a production-ready solution for creating isolated PostgreSQL test databases using PostgreSQL's native template database functionality. Instead of running expensive migrations for each test, it creates databases from a pre-migrated template, delivering significant performance improvements.
✨ Key Highlights
🚀 Performance That Scales
- 1.2-1.6x faster than traditional database creation approaches
- Consistent performance regardless of schema complexity
- 17% less memory usage per operation
- Thread-safe concurrent test database management
- Scales to 500+ databases with ease
🔧 Production-Ready Features
- Multiple driver support: Works with both
pgx/v5anddatabase/sql+lib/pq - Testcontainers integration for containerized testing environments
- Flexible migration runners with automatic file ordering
- Connection string validation and PostgreSQL-specific optimizations
- Comprehensive cleanup with automatic resource management
🛡️ Stability & Reliability
- Fully thread-safe with mutex-protected operations
- Unique database naming with collision-free generation
- Proper resource cleanup prevents connection leaks
- Extensive test coverage with real-world scenarios
- Go 1.20+ compatibility
📊 Real-World Performance
Based on benchmarks with Apple M4 Pro:
| Schema Complexity | Traditional | pgdbtemplate | Performance Gain |
|---|---|---|---|
| 1 Table | ~28.9ms | ~28.2ms | 1.03x faster |
| 3 Tables | ~39.5ms | ~27.6ms | 1.43x faster |
| 5 Tables | ~43.1ms | ~28.8ms | 1.50x faster |
Scaling Benefits:
- 20 databases: 32% faster (906.8ms → 613.8ms)
- 500 databases: 34% faster (22.31s → 14.82s)
🚀 Getting Started
Install with: go get github.com/andrei-polukhin/pgdbtemplate
Choose your PostgreSQL driver:
pgdbtemplate-pgx- Forpgx/v5with native connection poolingpgdbtemplate-pq- Fordatabase/sqlwithlib/pq
See the README.md for comprehensive usage examples and quick start guides.
🔄 Migration Guide
From Development Versions
If you've been using development versions (pre-v1.0.0), the API is now stable and ready for production use. The core interfaces and functionality remain the same, with improvements to:
- Error handling and resource cleanup
- Documentation and examples
- Performance optimizations
- Thread safety guarantees
Breaking Changes
None. This is the first stable release establishing the baseline API.
📚 Documentation & Examples
- README.md: Comprehensive usage examples and best practices
- docs/ADVANCED.md: Custom providers and migration runners
- docs/COMPARISON.md: Detailed comparison with other solutions
- docs/BENCHMARKS.md: Performance methodology and results
🙏 Acknowledgments
Special thanks to:
- The PostgreSQL community for template database functionality
- Contributors who helped shape the API and functionality
- Early adopters who provided valuable feedback
📦 What's Included
- Core library with template database management
- Two driver implementations (pgx and pq)
- Comprehensive test suite with 95%+ coverage
- Extensive documentation and examples
- Docker-based testing infrastructure
Ready to supercharge your PostgreSQL testing? Get started with go get github.com/andrei-polukhin/pgdbtemplate and experience the future of fast, reliable database testing!
For questions, issues, or contributions, visit github.com/andrei-polukhin/pgdbtemplate.
🚀 v0.7.0 - Driver-Agnostic Architecture
What's New
Major Refactoring: Made pgdbtemplate fully driver-agnostic with unified architecture
Key Changes
- ✅ Unified API: Single
pgdbtemplatepackage now supports bothpgxandlib/pqdrivers - 🗑️ Removed Duplication: Eliminated separate
pgdbtemplate-pgxandpgdbtemplate-pqpackages - 📚 Better Documentation: Added contributors file and improved README structure
- 🧪 Enhanced Testing: Consolidated test infrastructure with improved coverage
Migration Guide
- Replace
pgdbtemplate.NewPgxConnectionProviderimports withpgdbtemplate-pgx - Replace
pgdbtemplate.NewStandardConnectionProviderimports withpgdbtemplate-pq - Breaking changes
Breaking Changes
- Removed separate driver packages (now integrated)
- Updated import paths required
Full Changelog: v0.6.1...v0.7.0
🚀 v0.6.0 - Major Architectural Refactoring for Enterprise Flexibility
🚀 v0.6.0 - Major Architectural Refactoring for Enterprise Flexibility
This release introduces significant architectural improvements focused on enterprise-grade flexibility, reduced dependencies, and better driver abstraction.
✨ Features
- Driver-Agnostic Error Handling: Added
GetNoRowsSentinel()interface method for consistent error handling across PostgreSQL drivers - Zero-Runtime Dependencies: Extracted SQL formatting into
internal/formatterspackage, eliminating runtime dependency onlib/pq - Enhanced Architecture: Core
template_manager.gois now fully driver-agnostic for SQL formatting and error handling - Future-Proof Design: Easier to add support for additional PostgreSQL drivers
🔧 Improvements
- SQL Safety: Copied
pq.QuoteIdentifierandpq.QuoteLiteralimplementations to avoid runtime dependencies - Comprehensive Testing: Added full test coverage for the new
formatterspackage - License Compliance: Updated LICENSE with proper attribution for copied code
- Code Quality: Improved architectural cleanliness and separation of concerns
⚠️ Breaking Changes
- Connection String Validation Removed: Users must ensure valid PostgreSQL connections are provided
- Interface Changes: Removed
GetConnectionString()method fromConnectionProviderinterface
📚 Migration Guide
For Custom Connection Providers:
- Remove
GetConnectionString()method implementations (no longer needed) - Ensure your connection strings are valid PostgreSQL URIs
🧪 Testing
- All existing tests pass
- Added comprehensive tests for
internal/formatterspackage - Race condition tests included
- Integration tests with PostgreSQL 15
🙏 Acknowledgements
Thanks to Allan Vidal for his architectural feedback on this project.
🚀 v0.5.0: Performance Optimizations & Comprehensive Cleanup Tracking
🎉 Major Performance & Reliability Release
This release delivers substantial performance improvements and comprehensive cleanup tracking with zero breaking changes.
🚀 Performance Improvements
- 56% faster database creation (28.3ms vs 44.0ms)
- ~30% faster query performance with
pq.QuoteLiteraloptimization - ~6-10% faster database drops by removing unnecessary
IF EXISTSclauses - 17% less memory usage per operation
- Superior concurrent performance: 78 ops/sec vs 69 ops/sec traditional
🔒 Enhanced Thread Safety & Cleanup
- Comprehensive test database tracking with
sync.Mapfor automatic cleanup - Global atomic counters to prevent database name collisions across instances
- Batched connection termination for efficient bulk cleanup operations
- Enhanced error resilience in cleanup operations
- Production-ready cleanup management for large test suites
📊 Validated Performance Gains
- 1.56x faster overall database creation
- Scales better with complexity: 1.09x → 1.20x → 1.59x faster as schema grows
- Consistent ~28ms performance regardless of schema complexity
- Memory efficient: 17% reduction in per-operation memory usage
🧪 Testing & Quality
- 93.0% test coverage maintained with comprehensive new test suites
- New cleanup tracking tests ensuring reliable database management
- Enhanced benchmark suite with realistic test scenarios
- All tests passing with improved concurrent safety
📚 Documentation Updates
- Accurate performance metrics updated throughout documentation
- Current benchmark results reflecting actual measured performance
- Comprehensive BENCHMARKS.md with detailed analysis and methodology
🔄 Upgrade Path
Zero breaking changes - existing code works unchanged. Simply update your dependency:
go get github.com/andrei-polukhin/pgdbtemplate@v0.5.0🚀 v0.4.0: Dual Driver Support with pgx Integration and 93.7% Test Coverage
🚀 v0.4.0: Dual Driver Support with pgx Integration
This major release introduces dual PostgreSQL driver support, allowing users to choose between the standard database/sql interface with lib/pq or the high-performance pgx driver with advanced features like connection pooling.
✨ What's New
🔥 Dual Driver Architecture
- pgx Driver Support: Full integration with
pgx v5.6.0for advanced PostgreSQL features - Connection Pooling: Built-in
pgxpoolsupport for high-performance applications - Backward Compatibility: Existing
database/sqlcode continues to work unchanged - Unified Interface: Clean abstraction layer supporting both driver types
📈 Enhanced Test Coverage
- 93.7% Coverage: Comprehensive test suite exceeding 90% target
- Dual Driver Testing: Full test coverage for both
lib/pqandpgxdrivers - Integration Tests: Real database testing scenarios with proper cleanup
- Performance Tests: Thread-safe benchmarks with atomic counters
🏗️ Improved Architecture
- Organized Providers: Clean separation with
connection_provider_pq.goandconnection_provider_pgx.go - Connection Utilities: Robust
ReplaceDatabaseInConnectionStringfunction - Enhanced Error Handling: Support for both
sql.ErrNoRowsandpgx.ErrNoRows - Better Resource Management: Proper cleanup patterns and connection lifecycle
📚 Complete Documentation
- Driver Comparison Guide: Help users choose the right driver
- Connection Pooling Examples: Advanced pgx configuration patterns
- Migration Guide: Easy transition from single to dual driver setup
- Performance Best Practices: Optimization recommendations
🛠️ Usage Examples
Standard database/sql (lib/pq)
provider := &pgdbtemplate.StandardConnectionProvider{
ConnectionString: "postgres://user:pass@localhost/db?sslmode=disable",
}Advanced pgx with Connection Pooling:
provider := &pgdbtemplate.PgxConnectionProvider{
ConnectionString: "postgres://user:pass@localhost/db?sslmode=disable",
Options: &pgdbtemplate.PgxOptions{
MaxConns: 30,
MinConns: 5,
MaxConnLifetime: 30 * time.Minute,
},
}📊 Performance & Reliability
- Thread-Safe Benchmarks: Atomic counters for accurate performance measurements
- Connection Pooling: Significant performance improvements for high-load scenarios
- Robust Error Handling: Comprehensive error scenarios and recovery patterns
- Resource Cleanup: Automatic cleanup prevents connection leaks
🔧 Technical Improvements
New Files Added:
connection_provider_pgx.go- pgx driver implementationconnection_provider_pgx_options.go- pgx configuration optionsconnection_string.go- connection string utilities- Comprehensive test files for all new functionality
Dependencies Added:
github.com/jackc/pgx/v5 v5.6.0github.com/jackc/pgxpool/v5 v5.2.0
🚨 Breaking Changes
- None! This release maintains full backward compatibility
- Existing code using
NewStandardConnectionProviderworks unchanged - New
pgxfeatures are opt-in additions
📈 Metrics
- Test Coverage: 93.7% (up from 68.8%)
- New Test Cases: 150+ additional test scenarios
- Performance: Up to 40% faster with pgx connection pooling
- Memory Usage: Reduced allocation overhead with pgx
🙏 Migration Guide
For Existing Users
No changes required! Your existing code continues to work as before.
To Use New pgx Features
Simply replace your connection provider with the new pgx version for enhanced performance and connection pooling capabilities.
🔗 Full Changelog
- feat: add pgx driver support with connection pooling
- refactor: reorganize connection providers and add utilities
- test: enhance test coverage to 93.7% with comprehensive test suite
- perf: improve benchmark stability and accuracy
- docs: comprehensive README update with dual driver examples
- test: complete test infrastructure migration and cleanup
Full Changelog: v0.3.0...v0.4.0
v0.3.0: Enhanced Performance, Comprehensive Testing, and Documentation Overhaul
🚀 pgdbtemplate v0.3.0 - Enhanced Performance, Comprehensive Testing, and Documentation Overhaul
This major release brings significant improvements to code quality, testing coverage, performance infrastructure, and documentation organization. The library maintains its core performance characteristics while adding robust error handling and comprehensive benchmarking capabilities.
🎯 Key Highlights
- 📊 Comprehensive Benchmarking Infrastructure - Complete performance testing suite with automation
- 🔒 Enhanced Connection Management - Functional options pattern with connection pooling controls
- 🧪 Improved Test Coverage - From 90% to 90.6% with comprehensive error path testing
- 📚 Documentation Restructure - Professional docs/ organization with advanced scenarios
- 🐛 Critical Bug Fixes - Resolved concurrent testing race conditions
- ⚡ Performance Validated - 1.3-1.5x faster than traditional approaches confirmed
✨ New Features
📊 Benchmarking Infrastructure
- NEW:
benchmark_test.go- Comprehensive performance testing suite- Traditional vs template database creation comparisons
- Concurrent and sequential scaling benchmarks
- Template initialization cost measurements
- NEW:
docs/BENCHMARKS.md- Detailed performance analysis and methodology - NEW:
scripts/run_benchmarks.sh- Automated benchmark execution - NEW:
.gitignore- Clean repository management
🔧 Connection Provider Enhancements
- NEW:
connection_providers_options.go- Functional options patternWithMaxOpenConns()- Configure maximum open connectionsWithMaxIdleConns()- Configure maximum idle connectionsWithConnMaxLifetime()- Configure connection maximum lifetimeWithConnMaxIdleTime()- Configure connection maximum idle time
- REMOVED:
PingContext()method - Simplified DatabaseConnection interface
📚 Documentation Overhaul
- NEW:
docs/ADVANCED.md- Advanced scenarios and complex use cases - MOVED:
CONTRIBUTING.md→docs/CONTRIBUTING.md- Better organization - ENHANCED:
README.md- Improved structure and navigation - NEW: Professional docs/ directory structure
🐛 Critical Bug Fixes
🏃 Concurrency Issues
- FIXED: Channel reuse race condition in concurrent testing
- FIXED: Proper channel synchronization for parallel database operations
- ENHANCED: Thread-safe template database management
🔧 Error Handling
- IMPROVED: Comprehensive error checking across all operations
- STANDARDIZED: Quicktest assertion patterns throughout test suite
- ENHANCED: Inline error checks for cleaner, maintainable code
📈 Performance & Quality Improvements
🧪 Test Coverage Enhancements
- INCREASED: Test coverage from 90.0% to 90.6%
- ADDED: Comprehensive error path testing
- IMPROVED: Migration runner edge case coverage
- ENHANCED: Cleanup scenarios test readability
📝 Code Quality
- STANDARDIZED: Comment formatting with proper punctuation
- REPLACED: Error assertion antipatterns with
qt.ErrorMatches - INLINED: Error checks for improved readability
- REMOVED: Repetitive test code and redundant scenarios
⚡ Performance Validation
- CONFIRMED: 1.3-1.5x performance improvement over traditional approaches
- VALIDATED: Consistent ~29ms template database creation
- VERIFIED: Superior concurrent performance and thread safety
🔄 Breaking Changes
⚠️ Interface Changes
- REMOVED:
PingContext()method fromDatabaseConnectioninterface- Migration: Remove any
PingContext()calls - no replacement needed - Reason: Simplified interface, ping functionality not essential for template operations
- Migration: Remove any
📁 File Reorganization
- MOVED:
CONTRIBUTING.md→docs/CONTRIBUTING.md- Migration: Update any links to contribution guidelines
- NEW:
docs/directory structure - existing links may need updates
📊 Performance Benchmarks
Current benchmark results on Apple M4 Pro:
| Schema Size | Traditional | Template | Performance Gain |
|---|---|---|---|
| 1 Table | 31.5ms | 28.7ms | 1.10x faster |
| 3 Tables | 40.2ms | 28.5ms | 1.41x faster |
| 5 Tables | 45.2ms | 31.9ms | 1.42x faster |
Concurrent Performance: Template approach 23% faster with superior thread safety.
See docs/BENCHMARKS.md for comprehensive analysis and methodology.
🛠️ Development Experience
🚀 New Tooling
# Run comprehensive benchmarks
./scripts/run_benchmarks.sh
# Set custom connection string
export POSTGRES_CONNECTION_STRING="postgres://user:pass@localhost:5432/postgres"