starbasedb icon indicating copy to clipboard operation
starbasedb copied to clipboard

feat: add data sync replication planner

Open Treasure520520 opened this issue 6 months ago • 1 comments

/claim #72

Summary

This adds a focused Data Sync plugin foundation for the external-source to internal SQLite replication flow requested in #72.

The PR intentionally keeps the first slice reviewable and reusable:

  • adds DataSyncPlugin under plugins/data-sync
  • plans bounded cursor-based pulls from PostgreSQL/MySQL/SQLite-style external sources
  • supports table allowlists, column mapping, primary-key conflict handling, and batch-size clamping
  • defaults to SELECT * when no explicit column allowlist is configured
  • writes internal SQLite insert/upsert plans
  • stores checkpoints in tmp_data_sync_checkpoints
  • records sync runs in tmp_data_sync_runs
  • exposes an authenticated admin run endpoint at /data-sync/run
  • exports the plugin from @outerbase/starbasedb/plugins
  • documents the plugin usage and checkpoint behavior

Why this slice

Issue #72 needs a pull-based replication mechanism with selectable tables, intervals/checkpoints, and append/incremental polling. This PR lands the core replication planner and checkpointed runner so provider-specific scheduling and UI polish can build on a tested base instead of re-implementing query/upsert planning each time.

Validation

  • ./node_modules/.bin/prettier --check plugins/data-sync/index.ts plugins/data-sync/index.test.ts plugins/data-sync/README.md dist/plugins.ts
  • ./node_modules/.bin/vitest run plugins/data-sync/index.test.ts src/plugin.test.ts (17 tests)
  • git diff --check

The repo-wide ./node_modules/.bin/tsc --noEmit is still blocked by pre-existing type errors outside this PR (src/do.ts, src/operation.ts, existing tests). The focused plugin tests and formatting checks pass.

Treasure520520 avatar May 13 '26 12:05 Treasure520520

Adding a short demo GIF for the Algora bounty review guideline:

StarbaseDB #72 data sync demo

It summarizes the focused flow in this PR: configure table allowlist, plan bounded external pulls, upsert into internal SQLite, and persist checkpoints/run history.

Treasure520520 avatar May 13 '26 12:05 Treasure520520