migro

Models and migrations for Go. migro brings the ergonomics of AdonisJS Lucid, Knex and Laravel’s artisan to Go, on top of GORM.

You get a schema builder, a query builder, generic models, Laravel-style migration files, seeders and factories, events, read replicas and sharding, and a CLI you run next to your application:

migro make:migration create_users_table
migro migration:run
migro migration:rollback --step=2
migro db:seed

What is in the box

Piece What it gives you
Schema builder t.String("email").Unique(), indexes, ForeignID(...).Constrained(), Morphs(...), one definition for every database
Query builder Knex-style query.Table(db, "users").Where(...).Get(ctx) for tables without a model
Models Eloquent and Lucid style: orm.New[User](db), instance Save/Delete, dirty tracking, mass assignment, serialization, aggregates
Relations Typed relation fields (HasMany[Post], BelongsToMany[Role], MorphTo, …), With/WithCount/Has, pivot Attach/Sync, morph map
Query scopes Reusable Apply(Published, By(1)) local scopes and model-level global scopes
Mutators and casting Hashed, encrypted, enum, date and typed JSON columns; custom mutators and accessors
Serialization and Resources ToMap/JSON with MakeVisible/DateFormat, and hand-shaped API resources with pagination
Collections Filter, KeyBy, GroupBy, Load, Fresh on every multi-row result
Migrations Files like 20260101120000_create_users_table.go with Up and Down, batches, locking, --pretend
Command line make:*, migration:*, db:seed, production prompt, several connections
Seeders and factories Lucid-style factories with states and relations, environment-aware seeders
Events An event bus plus before:create, after:update and other model lifecycle events
Pool, replicas, sharding Knex-style pool options, read replicas, key-based sharding
Schema diff Generate a migration from the difference between your models and the database

Databases

PostgreSQL, CockroachDB, Redshift, MySQL, MariaDB, SQLite (pure Go), SQL Server and Oracle (pure Go). Each is a separate import, so you only compile the driver you use. See Database notes for what is verified against live servers and what is not.

Where to start

  1. Installation: requirements and the two things to install.
  2. Getting started: a small project from an empty folder to a seeded database, about ten minutes.
  3. How it works: the mental model, so the rest of the guide makes sense.

Then pick the page you need from the sidebar. If you want to help, read Contributing.

migro is young. The latest release is v0.1.0, and while the version starts with 0 the API may still change between minor versions, so pin the version in go.mod and read the release notes before upgrading.