go get github.com/SharkFourSix/dsync- Choose a data source (check in sources) or implement your own.
- Create a
Migratorand pass the data source to the migrator
import (
"embed""testing""github.com/SharkFourSix/dsync""github.com/SharkFourSix/dsync/sources/postgresql"
)
//go:embed resources/migrationsvarefs embed.FSfuncDoMigrate(){
dsn:="postgres://postgres:toor@localhost:5433/test-db"// Create a migratorvarmigrator dsync.Migrator// Configure a data sourceds, err:=postgresql.New(dsn, &dsync.Config{
FileSystem: efs,
Basepath: BASEPATH,
TableName: "dsync_schema_migration",
})
iferr!=nil {
panic(err)
}
// Migrateerr=migrator.Migrate(ds)
iferr!=nil {
panic(err)
return
}
}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 | 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 |
- Add logging and configuration