A lightweight database management CLI/Library.
godb helps you manage your database with simple commands like create, migrate, drop, and more — inspired by tools
like Rails’ db:* commands.
- ✅ Interactive
godb initto scaffold.godb.yaml - ✅ Easily create and drop databases
- ✅ Run migrations using
migrateorgenerate migrate - ✅ Supports MySQL and PostgreSQL
- ✅ CLI and YAML-based — no magic involved
# Install godb into your project
go get -tool github.com/mickamy/godb/cmd/godb@latest
# or install it globally
go install github.com/mickamy/godb/cmd/godb@latestInitialize a project with:
godb initThis will walk you through DB config like:
# .godb.yaml
database:
driver: postgres
host: localhost
port: 5432
user: godb
password: password
name: godb
migrations:
dir: migrations
ext: sql
seq: falsegodb creategodb dropgodb migrateThis uses the migrate binary under the hood (with fallback to go tool migrate if available).
godb rollback --step=1This also uses the migrate binary under the hood.
godb g migration create_usersThis forwards to migrate create to create a new migration file.
migrations/000001_create_users.up.sql
migrations/000001_create_users.down.sql
You can also use godb as a Go package to manage your database programmatically:
go get github.com/mickamy/godb@latestimport (
"log"
"github.com/mickamy/godb/config"
)
cfg, err := config.Load()
if err != nil {
log.Fatal("failed to load config:", err)
}import (
"errors"
"log"
"github.com/mickamy/godb"
)
err := godb.Create(cfg)
if errors.Is(err, godb.ErrCreateDatabaseExists) {
log.Println("database already exists, skipping.")
} else if err != nil {
log.Fatal("failed to create database:", err)
}import (
"log"
"github.com/mickamy/godb"
)
if err := godb.Drop(cfg, false); err != nil {
log.Fatal("failed to drop database:", err)
}The second argument is a flag to terminate all the connections to the database before dropping it.
import (
"errors"
"log"
"github.com/mickamy/godb"
)
err := godb.Migrate(cfg)
if errors.Is(err, godb.ErrMigrateNoChange) {
log.Println"no new migrations to apply.")
} else if err != nil {
log.Fatal("migration failed:", err)
}
err = godb.Rollback(cfg, 1)
if errors.Is(err, godb.ErrMigrateNoChange) {
log.Println("no migrations to rollback.")
} else if err != nil {
log.Fatal("rollback failed:", err)
}You can use this to integrate database set-up into your own tooling, tests, or set-up scripts.
- ✅ MySQL
- ✅ PostgreSQL