Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@tailwindcss/vite": "^4.0.6",
"@types/pg": "^8.11.10",
"@vitest/coverage-istanbul": "2.1.8",
"fast-check": "^4.7.0",
"husky": "^9.1.7",
"lint-staged": "^15.2.11",
"postcss": "^8",
Expand Down
66 changes: 66 additions & 0 deletions plugins/data-replication/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Data Replication Plugin

The Data Replication Plugin for StarbaseDB pulls data from external databases (PostgreSQL, MySQL, SQLite/Turso/D1) into the internal Durable Object SQLite store, creating a close-to-edge replica for fast local queries.

## Usage

Add the DataReplicationPlugin to your Starbase configuration:

```typescript
import { DataReplicationPlugin } from './plugins/data-replication'

const replicationPlugin = new DataReplicationPlugin({ stub })

const plugins = [
// ... other plugins
replicationPlugin,
] satisfies StarbasePlugin[]
```

## Configuration Options

| Option | Type | Default | Description |
| ------ | ------------------- | ------- | ----------------------------------------------- |
| `stub` | `DurableObjectStub` | `null` | Reference to the Durable Object stub for alarms |

## Sync Modes

- **Incremental (cursor-based)**: Set a `cursor_column` (e.g. `id`, `created_at`) to only fetch new rows since the last sync.
- **Full replacement**: Omit `cursor_column` to delete and re-insert all rows on each cycle.

## API Endpoints

| Method | Path | Description |
| ------ | -------------------------- | ------------------------------------ |
| POST | `/replication/configs` | Create a replication config |
| GET | `/replication/configs` | List all replication configs |
| GET | `/replication/configs/:id` | Get a specific config |
| PUT | `/replication/configs/:id` | Update a config |
| DELETE | `/replication/configs/:id` | Delete a config and its sync state |
| GET | `/replication/status` | Get sync state for all configs |
| GET | `/replication/status/:id` | Get sync state for a specific config |
| POST | `/replication/sync/:id` | Manually trigger sync for a config |
| POST | `/replication/callback` | Internal callback from DO alarm |

## Creating a Replication Config

```bash
curl -X POST https://your-endpoint/replication/configs \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"source_table": "users",
"target_table": "users_replica",
"cursor_column": "id",
"interval_seconds": 300,
"enabled": true,
"callback_host": "https://your-endpoint"
}'
```

## Manual Sync

```bash
curl -X POST https://your-endpoint/replication/sync/1 \
-H "Authorization: Bearer YOUR_TOKEN"
```
Loading