Skip to content

SharkFourSix/dsync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dsync Go Report Card

Getting Started

go get github.com/SharkFourSix/dsync

Usage

  1. Choose a data source (check in sources) or implement your own.
  2. Create a Migrator and pass the data source to the migrator
import (
	"embed"
	"testing"

	"github.com/SharkFourSix/dsync"
	"github.com/SharkFourSix/dsync/sources/postgresql"
)

//go:embed resources/migrations
var efs embed.FS

func DoMigrate(){
    dsn := "postgres://postgres:toor@localhost:5433/test-db"
    
    // Create a migrator
    var migrator dsync.Migrator

    // Configure a data source
	ds, err := postgresql.New(dsn, &dsync.Config{
		FileSystem: efs,
		Basepath:   BASEPATH,
		TableName:  "dsync_schema_migration",
	})

	if err != nil {
        panic(err)
	}

    // Migrate
	err = migrator.Migrate(ds)
	if err != nil {
		panic(err)
		return
	}
}

Things To Know

  • File names must use the following convention to be included when scanning:

    \d+__\w+.sql.

  • An error will be returned otherwise when the version part of the file name does not contain a number.

  • A migration script will not be included if it does not end with .sql extension

  • Migrations are only recorded in the database when successfull

  • Custom migration table name to allow different migrations for difference DB clients.

  • Supports out of order migrations

Database sources

Database Data source Status
Postgres github.com/SharkFourSix/dsync/sources/postgresql Done
MySQL github.com/SharkFourSix/dsync/sources/mysql Done
SQLite github.com/SharkFourSix/dsync/sources/sqlite Done

TODO

  • Add logging and configuration