Thanks to visit codestin.com
Credit goes to github.com

Skip to content

High-performant, easy-to-use data replication tool. Replicate data from any source to any destination with ease.

License

Notifications You must be signed in to change notification settings

sagadana/migrator

Repository files navigation

Migrator

Release%20by%20tag Release%20by%20date Report Code%20Quality CodeQL Tests

High-performant, easy-to-use data replication tool. Replicate data from any source to any destination with ease (Homogeneous or Heterogeneous).

Features

  • Source transformation: Modify, rename, delete fields
  • Auto Resuming: Resume from the last successful position - if failed
  • Batch Migration: Process migration in batches
  • Parallel Migration: Break data into chunks and load in parallel
  • Continuous Replication: Watch for new changes and replicate them; A.K.A Change Data Capture (CDC)
  • Import & Export: Load or Save data from/to CSV & Parquet file

Datasources

Datasource Status Read Write Stream (CDC)
Memory
MongoDB ✅ (with change streams)
Redis ✅ (with keyspace notifications)
Postgres ✅ (with logical replication)
MySQL ✅ (with binlog replication)
MariaDB ✅ (with binlog replication)
<More> Soon TBC TBC TBC

State Stores

Store Status
Memory
File
Redis

Install

go get github.com/sagadana/migrator

Usage

Migration

package main

import (
 "github.com/sagadana/migrator/datasources"
 "github.com/sagadana/migrator/pipelines"
 "github.com/sagadana/migrator/states"
)

func main() {

    ctx, cancel := context.WithCancel(context.TODO())
    defer cancel()

    // Create the `From` datasource _(Memory Data Source in this example)_
    fromDs := datasources.NewMemoryDatasource("test-from", "id")
    // Load data from a CSV if needed
    err := fromDs.Import(&ctx, datasources.DatasourceImportRequest{
        Type:      datasources.DatasourceImportTypeCSV,
        Source:    datasources.DatasourceImportSourceFile,
        Location:  "./tests/sample-100.csv",
        BatchSize: 10,
    })
    if err != nil {
        panic(err)
    }

    // Create the `To` datasource _(Memory Data Source in this example)_
    toDs := datasources.NewMemoryDatasource("test-to", "id")

    // Initialize Pipeline
    pipeline := pipelines.Pipeline{
        ID:    "test-pipeline-1",
        From:  fromDs,
        To:    toDs,
        Store: states.NewFileStateStore("./tests", "state"),
    }

    // Start Migration Only
    err = pipeline.Start(&ctx, pipelines.PipelineConfig{
        MigrationParallelWorkers:    5,
        MigrationBatchSize:          10,

        OnMigrationStart:       func(state states.State) { /* Add your logic. E.g extra logs */ },
        OnMigrationProgress:    func(state states.State, count pipelines.DatasourcePushCount) { /* Add your logic. E.g extra logs */ },
        OnMigrationError:       func(state states.State, data datasources.DatasourcePushRequest, err error) { /* Add your logic. E.g extra logs */ },
        OnMigrationStopped:     func(state states.State) { /* Add your logic. E.g extra logs */ },
    }, /*with replication*/ false)
    if err != nil {
        panic(err)
    }

}

Migration + Continuous Replication

func main() {

    // .... (init codes)

    // Start Migration + Replication
    err = pipeline.Start(&ctx, pipelines.PipelineConfig{
        MigrationParallelWorkers:      5,
        MigrationBatchSize:            10,

        ReplicationBatchSize:       20,
        ReplicationBatchWindowSecs: 1,

        OnMigrationStart:       func(state states.State) { /* Add your logic. E.g extra logs */ },
        OnMigrationProgress:    func(state states.State, count pipelines.DatasourcePushCount) { /* Add your logic. E.g extra logs */ },
        OnMigrationError:       func(state states.State, data datasources.DatasourcePushRequest, err error) { /* Add your logic. E.g extra logs */ },
        OnMigrationStopped:     func(state states.State) { /* Add your logic. E.g extra logs */ },

        OnReplicationStart:     func(state states.State) { /* Add your logic. E.g extra logs */ },
        OnReplicationProgress:  func(state states.State, count pipelines.DatasourcePushCount) { /* Add your logic. E.g extra logs */ },
        OnReplicationError:     func(state states.State, data datasources.DatasourcePushRequest, err error) { /* Add your logic. E.g extra logs */ },
        OnReplicationStopped:   func(state states.State) { /* Add your logic. E.g extra logs */ },
    }, /*with replication*/ true)
    if err != nil {
        panic(err)
    }
}

Continuous Replication Only

func main() {

    // .... (init codes)

    // Start Replication
    err = pipeline.Stream(&ctx, pipelines.PipelineConfig{
        ReplicationBatchSize:       20,
        ReplicationBatchWindowSecs: 1,

        OnReplicationStart:     func(state states.State) { /* Add your logic. E.g extra logs */ },
        OnReplicationProgress:  func(state states.State, count pipelines.DatasourcePushCount) { /* Add your logic. E.g extra logs */ },
        OnReplicationError:     func(state states.State, data datasources.DatasourcePushRequest, err error) { /* Add your logic. E.g extra logs */ },
        OnReplicationStopped:   func(state states.State) { /* Add your logic. E.g extra logs */ },
    })
    if err != nil {
        panic(err)
    }
}

Linting

Run this to catch lint issues

 docker compose --env-file ./tests/.env.dev  up lint

Testing

Test States

docker compose --env-file ./tests/.env.dev  up tester-state

Test Datasources

docker compose --env-file ./tests/.env.dev  up tester-ds

Test Pipelines

docker compose --env-file ./tests/.env.dev  up tester-pipe

Test Helpers

docker compose --env-file ./tests/.env.dev  up tester-helper

Contributing

See CONTRIBUTING.md

About

High-performant, easy-to-use data replication tool. Replicate data from any source to any destination with ease.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages