Repository navigation
Conversation
…erbase#72) - Implement ReplicationPlugin extending StarbasePlugin - Support pull-based synchronization from external data sources (Postgres, Supabase, MySQL) to internal Durable Object SQLite - Cursor tracking via configurable cursorColumn (id, updated_at, sequence) for incremental sync - Idempotent upserts with INSERT OR REPLACE INTO keyed by primaryKey - Schema-aware auto-provisioning of destination tables with type inference and identifier escaping - Concurrency lock guard per table to prevent overlapping sync tasks - REST API under /replication (GET /status, POST /sync, POST /configure, POST /reset) - Cron/Alarm integration support via handleCron() and syncAll() - Comprehensive Vitest unit & integration test coverage (17/17 tests passing) - Complete technical documentation in README.md and meta.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Resolves #72
This PR introduces the Replication Plugin (
starbasedb:replication) for StarbaseDB, providing pull-based data synchronization from external data sources (e.g. Supabase/PostgreSQL, MySQL) directly into the internal Durable Object SQLite instance. This enables StarbaseDB instances to act as high-speed, close-to-the-edge read replicas of central databases.Key Capabilities
Incremental Cursor-Based Pull:
cursorColumn(e.g.,id,updated_at,timestamp).WHERE cursorColumn > previousCursor ORDER BY cursorColumn ASC LIMIT batchSize).forceFullmode to bypass cursors when a full re-sync is needed.Idempotent Upserts:
INSERT OR REPLACE INTOkeyed onprimaryKey(defaults toid), preventing duplicates and handling updates seamlessly.Schema-Aware Auto Table Provisioning:
INTEGER,REAL,TEXT) andPRIMARY KEY.public.usersreplicates cleanly into target tableusers).State Persistence & Observability:
_starbase_replication_state:table_name: Primary keycursor_value: Last processed cursorlast_sync_at: Epoch timestamp of last successful synctotal_rows_synced: Cumulative sync counterstatus:'idle' | 'syncing' | 'synced' | 'error'last_error: Diagnostic message on failuresConcurrency Lock Guard:
REST API Interface (
/replication/*):GET /replication/status: Reports sync states, table count, and active synchronizations.POST /replication/sync: Triggers immediate synchronization for a single table or all configured tables.POST /replication/configure: Dynamically registers new table configurations at runtime.POST /replication/reset: Resets replication state and cursors.Scheduled Alarm / Cron Integration:
syncAll()andhandleCron()for invocation via Cloudflare Workerscheduledevents orCronPlugin.Testing & Verification
plugins/replication/index.test.ts(17 tests covering initialization, REST routes, incremental cursors, lock guards, error states, and cron handling)./claim #72