docs
Schema Migration

Schema Migration

Generate and manage database tables from Go struct definitions.

AutoMigrate

Creates tables for one or more models. Safe to call on startup — only creates tables that don't exist:

err := db.AutoMigrate(ctx, &User{}, &Post{}, &Comment{})

CreateTable

Creates a single table:

err := db.CreateTable(ctx, &User{})

HasTable

Check if a table exists:

exists, err := db.HasTable(ctx, &User{})
if exists {
    // table is present
}

DropTable

⚠️

DropTable permanently deletes the table and all its data. This cannot be undone.

err := db.DropTable(ctx, &OldModel{})