
Queen¶
Migrations are defined as code, not files — type safety, IDE support, and easy testing included.
What are Queen?¶
Queen defines migrations as Go structs instead of external files. This gives you compile-time validation, type safety, and the ability to use Go functions for complex data transformations -- all within your application code.
Features¶
Migrations as Code -- Type-safe Go structs with compile-time validation. No external files to manage.
SQL and Go Functions -- Pure SQL for schema changes, Go functions for complex data transformations. Both run inside transactions.
Gap Detection -- Automatically detect and resolve missing, skipped, or unregistered migrations.
6 Databases -- PostgreSQL, MySQL, SQLite, ClickHouse, CockroachDB, MS SQL Server.
Checksum Validation -- Automatic SHA-256 checksums detect when applied migrations are modified.
Rich Metadata -- Track who applied each migration, when, on which host, and how long it took.
Quick Start¶
package main
import (
"context"
"database/sql"
"log"
"github.com/honeynil/queen"
"github.com/honeynil/queen/drivers/postgres"
_ "github.com/jackc/pgx/v5/stdlib"
)
func main() {
db, _ := sql.Open("pgx", "postgres://localhost/mydb?sslmode=disable")
defer db.Close()
q := queen.New(postgres.New(db))
defer q.Close()
q.MustAdd(queen.M{
Version: "001",
Name: "create_users",
UpSQL: `CREATE TABLE users (id SERIAL PRIMARY KEY, email VARCHAR(255) UNIQUE)`,
DownSQL: `DROP TABLE users`,
})
if err := q.Up(context.Background()); err != nil {
log.Fatal(err)
}
}
Next Steps¶
- Installation -- Install Queen and set up your project.
- First Migration -- Step-by-step guide to your first migration.
- Migrations Guide -- Create SQL, Go, and mixed migrations.
- CLI Reference -- Use the command-line tool.
- Drivers -- Connect to your database.