Closes #72 /claim #72

Purpose

Implement a comprehensive data replication plugin for StarbaseDB that enables users to pull data from external databases (PostgreSQL, MySQL, etc.) into the internal SQLite database with configurable sync intervals and incremental updates.

This addresses the request for creating a β€œpull mechanism” to replicate data from external sources like Supabase PostgreSQL into StarbaseDB’s edge-close SQLite replica.

https://github.com/user-attachments/assets/b44e78c6-0e76-4cde-a489-e4ab87e23a96

Tasks

  • Create DataReplicationPlugin following StarbaseDB plugin architecture
  • Implement external database connection support (PostgreSQL, MySQL, Hyperdrive)
  • Add incremental sync mechanism using tracking columns (id, created_at, updated_at)
  • Create configurable sync intervals per replication configuration
  • Build comprehensive REST API for replication management
  • Add real-time logging and monitoring system
  • Implement event callback system for external integrations
  • Create internal database tables for configuration and logs storage
  • Add proper error handling and graceful degradation
  • Write unit tests and comprehensive documentation
  • Register plugin in main application with event handling
  • Deploy and test on live Cloudflare Workers environment

Verify

πŸ” Code Review Checklist

  • Plugin Architecture: Verify adherence to StarbaseDB plugin patterns in plugins/data-replication/index.ts
  • External Database Security: Review credential handling and SQL injection prevention
  • API Endpoints: Test all 7 REST endpoints with proper authentication
  • TypeScript Types: Validate type safety and interface compliance
  • Error Handling: Ensure graceful degradation and comprehensive logging

πŸ§ͺ Testing Steps

  1. Build & Deploy: npm run build && npx wrangler deploy
  2. Configure Replication:
    curl -X POST https://starbasedb.mavrickrishi.workers.dev/data-replication/configure \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer ABC123" \
    -d '{"name":"test","sourceConfig":{"dialect":"postgresql","host":"demo.supabase.co","port":5432,"user":"postgres","password":"demo-pass","database":"postgres"},"targetTable":"users","sourceTable":"users","syncIntervalMinutes":30,"trackingColumn":"updated_at"}'
  3. Check Status: curl -X GET https://starbasedb.mavrickrishi.workers.dev/data-replication/status -H "Authorization: Bearer ABC123"
  4. Monitor Logs: View Cloudflare Workers dashboard for real-time sync events

πŸ“Š Performance Verification

  • Memory: Plugin reuses existing connection infrastructure (minimal overhead)
  • Scalability: Supports multiple concurrent replication configurations
  • Efficiency: Incremental sync with WHERE clause filtering

Before

GitHub Issue #72 Request:

  • No data replication functionality
  • No external database sync capability
  • Manual data management required
  • No edge-close replica creation

StarbaseDB Plugin Ecosystem:

plugins/
β”œβ”€β”€ cdc/ # Change Data Capture
β”œβ”€β”€ cron/ # Scheduled tasks
β”œβ”€β”€ query-log/ # Query logging
β”œβ”€β”€ stats/ # System statistics
└── [missing data replication]

After

βœ… Complete Data Replication System:

πŸ”Œ New Plugin Added

plugins/data-replication/
β”œβ”€β”€ index.ts # Main plugin (475+ lines)
β”œβ”€β”€ index.test.ts # Unit tests (3 passing)
β”œβ”€β”€ meta.json # Plugin metadata
└── README.md # Comprehensive docs

πŸš€ Live Deployment

πŸ“‘ 7 New API Endpoints

  • POST /data-replication/configure - Set up replication
  • POST /data-replication/start/:name - Start specific replication
  • POST /data-replication/stop/:name - Stop specific replication
  • POST /data-replication/sync/:name - Manual sync trigger
  • GET /data-replication/status - View all configurations
  • GET /data-replication/logs - Sync operation logs
  • DELETE /data-replication/configure/:name - Remove config

πŸ’Ύ Database Schema

Two new internal tables created:

  • tmp_replication_configs - Store replication settings
  • tmp_replication_logs - Track sync operations and performance

πŸ”„ Working Demo

# βœ… TESTED: Configuration successful
{"result":{"success":true,"message":"Replication configured successfully"}}
# βœ… TESTED: Status shows active replication
{"result":{"configs":[{"name":"supabase-users","is_running":true,"sync_interval_minutes":30}]}}

🎯 Issue Requirements Met

βœ… Pull mechanism for external databases
βœ… Configurable sync intervals
βœ… Table-specific replication
βœ… Incremental updates via tracking columns
βœ… Supabase PostgreSQL support
βœ… Edge-close SQLite replica creation
βœ… wrangler.toml configuration support

Claim

Total prize pool $250
Total paid $0
Status Pending
Submitted July 23, 2025
Last updated July 23, 2025

Contributors

RI

Rishi Mondal

@MAVRICK-1

100%

Sponsors

OU

Outerbase (YC W23)

@outerbase

$250