Skip to content

Go database schema migrator library (See `cristalhq/dbumper` tool)

License

Notifications You must be signed in to change notification settings

cristalhq/dbump

Repository files navigation

dbump

build-img pkg-img version-img

Go database schema migrator library (See cristalhq/dbumper tool).

Rationale

Most of the tools related to database migrations are bloated with the questionable features and dependecies. However, in most of the cases migrations are just files with queries to run. This library does this.

Features

  • Simple.
  • Clean and tested code.
  • Supports fs.FS and go:embed.
  • ZigZag mode to better test migrations.
  • Dependency-free (database connectors are optional).
  • Supported databases:
    • Postgres
    • MySQL
    • ClickHouse
    • or your own!

See GUIDE.md for more details.

Install

Go version 1.17+

go get github.com/cristalhq/dbump

Example

ctx := context.Background()

cfg := dbump.Config{
	Migrator: dbump_pg.NewMigrator(db),
	Loader:   dbump.NewFileSysLoader(embed, "/"),
	Mode:     dbump.ModeApplyAll,
}

err := dbump.Run(ctx, cfg)
if err != nil {
	panic(err)
}

Also see examples: example_test.go.

Documentation

See these docs.

License

MIT License.