Skip to content

feat(plugins): implement external data replication plugin (#72) - #295

Open
mini0n-ai wants to merge 1 commit into
outerbase:mainfrom
mini0n-ai:feat/external-replication-plugin
Open

feat(plugins): implement external data replication plugin (#72)#295
mini0n-ai wants to merge 1 commit into
outerbase:mainfrom
mini0n-ai:feat/external-replication-plugin

Conversation

@mini0n-ai

Copy link
Copy Markdown

Summary

Resolves #72 by implementing a full pull-based external replication plugin (plugins/replication) that replicates data from an external data source into the internal Durable Object SQLite instance.

/claim #72
Resolves #72

Architecture & Key Features

  1. Pull-based & Append-only Engine (ReplicationPlugin):

    • For each configured table, tracks a monotonically increasing checkpoint column (id, created_at, or custom key).
    • On each pull, fetches rows newer than the highest value seen and persists the checkpoint in tmp_replication_checkpoints.
    • Preserves typed checkpoint comparisons (numeric id vs timestamp string) using JSON serialization.
    • Writes rows using INSERT OR REPLACE for idempotent re-pulls and retry safety.
  2. Automatic Destination Table Provisioning:

    • If the destination table does not already exist in the internal SQLite database, the plugin automatically provisions it with CREATE TABLE IF NOT EXISTS using the source schema column definitions and sets PRIMARY KEY on the tracked key.
  3. Transparent Querying (beforeQuery Hook):

    • When querying the internal DO SQLite database, the plugin inspects incoming SQL statements and automatically rewrites qualified Postgres schema prefixes (e.g. SELECT * FROM public.users) to the corresponding internal SQLite table name (users), providing seamless compatibility without requiring client-side SQL alterations.
  4. Cadence & Monitoring Endpoints:

    • Supports automated lazy polling via intervalSeconds (evaluating elapsed intervals and executing via waitUntil to prevent request blocking).
    • Exposes authenticated admin endpoints:
      • POST /replication/pull: triggers an immediate manual replication run.
      • GET /replication/status: returns current checkpoint positions, record counts, and timestamp of the last pull.
    • Integrates cleanly with @outerbase/starbasedb/plugins and the Cron plugin (cronPlugin.onEvent).

Automated Test Suite

  • Comprehensive unit and integration test coverage in plugins/replication/index.test.ts and plugins/replication/utils.test.ts:
    • 39 passed vitest tests (100% green, 0 failures, 0 warnings).
    • Validated identifier injection protection, batch pagination, multi-table replication, schema rewriting, and route registration.

Bounty Sovereign Wallet (Base L2 USDC):
0x46D5318E4397cFcBED06a235c1604E473682Ea1F

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replicate data from external source to internal source with a Plugin

1 participant