https://github.com/h44z/lightmigrate
Lightweight database migragtion library for Golang
https://github.com/h44z/lightmigrate
database golang library migration
Last synced: 3 months ago
JSON representation
Lightweight database migragtion library for Golang
- Host: GitHub
- URL: https://github.com/h44z/lightmigrate
- Owner: h44z
- License: mit
- Created: 2022-01-13T15:21:42.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-22T21:19:52.000Z (almost 4 years ago)
- Last Synced: 2025-03-22T21:35:41.195Z (over 1 year ago)
- Topics: database, golang, library, migration
- Language: Go
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# LightMigrate - a lightweight database migration library
[](https://codecov.io/gh/h44z/lightmigrate)
[](https://opensource.org/licenses/MIT)
[](https://pkg.go.dev/github.com/h44z/lightmigrate)

[](https://goreportcard.com/report/github.com/h44z/lightmigrate)


[](https://github.com/h44z/lightmigrate/releases)
This library is heavily inspired by [golang-migrate](https://github.com/golang-migrate/migrate).
It currently lacks support for many database drivers and the CLI feature, this is still WIP.
But it is completely restructured to minimize the dependency footprint.
## Currently Supported databases
- [MongoDB](https://github.com/h44z/lightmigrate-mongodb)
- [MySQL / MariaDB](https://github.com/h44z/lightmigrate-mysql)
- [sqlite3](https://github.com/h44z/lightmigrate-sqlite)
## Usage example:
```go
fsys := os.DirFS("/app/data") // Migration File Source Root (/app/data/migration-files)
source, err := NewFsSource(fsys, "migration-files")
if err != nil {
t.Fatalf("unable to setup source: %v", err)
}
defer source.Close()
driver, err := test.NewMockDriver() // Database Driver (for example mongodb.NewDriver() or mysql.NewDriver())
if err != nil {
t.Fatalf("unable to setup driver: %v", err)
}
defer driver.Close()
migrator, err := NewMigrator(source, driver, WithVerboseLogging(true)) // The migrator instance
if err != nil {
t.Fatalf("unable to setup migrator: %v", err)
}
err = migrator.Migrate(3) // Migrate to schema version 3
if err != nil {
t.Fatalf("migration error: %v", err)
}
```