How sysadminmike/couch-to-postgres works
Main Components
a. Core Components:
• CouchDB Instance
• PostgreSQL Instance
• Node.js Synchronization Service
• HTTP Communication Layer (pgsql-http extension)
b. Data Flow Components:
• Changes Feed Stream
• Checkpoint Management
• Trigger System
• Bulk Operations Handler
Top Layer: Client Interaction Layer
• PostgreSQL Client Queries
• CouchDB Client Requests
• HTTP REST Endpoints
Middle Layer: Synchronization Layer
• Node.js Daemon
• Changes Feed Processor
• Checkpoint Manager
• Trigger Functions
Bottom Layer: Storage Layer
• PostgreSQL Tables (docs + checkpoints)
• CouchDB Documents
• JSON/JSONB Data Structures
Key Relationships to Highlight
a. Data Flow Paths:
• CouchDB → Changes Feed → Node.js → PostgreSQL
• PostgreSQL → Triggers → HTTP Extension → CouchDB
• Bulk Operations Path
• Checkpoint Management Flow
b. State Management:
• Since Checkpoints Table
• Document Versioning (_rev handling)
• Synchronization Status
Technical Details
Database Schemas:
PostgreSQL Tables:
• since_checkpoints (pgtable, since, enabled)
• document_tables (id, doc, from_pg)
CouchDB:
• Documents
• Design Documents
• Views
Implementation Notes
Annotations for:
• Configuration options
• Performance considerations
• Bulk operation thresholds
• Checkpoint intervals
• Error handling strategies