Skip to Content

gofasta g model

Generates a GORM database model file and a SQL migration pair (up + down) with the specified fields and types. The model includes standard fields (ID, CreatedAt, UpdatedAt, DeletedAt) automatically, plus any custom fields you define.

Use this command when you need only the model and migration without the full scaffold. For a complete resource with all layers, use gofasta g scaffold instead.

Usage

gofasta g model <Name> [field:type ...]

This command has no flags.

Field Types

TypeGo TypeGORM Tag
stringstringtype:varchar(255);not null
textstringtype:text
intinttype:integer;not null
floatfloat64type:decimal(10,2);not null
boolbooltype:boolean;default:false
uuiduuid.UUIDtype:uuid
timetime.Timetype:timestamp

The datetime alias can be used in place of time.

Examples

Generate a Product model:

gofasta g model Product name:string price:float

Generate a model with multiple field types:

gofasta g model Article title:string body:text published:bool view_count:int

What It Generates

Running gofasta g model Product name:string price:float creates three files:

FileDescription
app/models/product.model.goGORM database model
db/migrations/000006_create_products.up.sqlCreate table migration
db/migrations/000006_create_products.down.sqlDrop table migration

Generated Code

// app/models/product.model.go package models import ( "time" "github.com/google/uuid" "gorm.io/gorm" ) type Product struct { ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"` Name string `gorm:"type:varchar(255);not null" json:"name"` Price float64 `gorm:"type:decimal(10,2);not null" json:"price"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"` }

The model automatically includes:

  • A UUID primary key with auto-generation
  • CreatedAt and UpdatedAt timestamps managed by GORM
  • DeletedAt for soft deletes with an index
  • JSON tags using snake_case naming
  • GORM tags for column type definitions

Database Driver Compatibility

Field type mappings adapt automatically based on the database driver configured in config/config.yaml:

Field TypePostgresMySQLSQLiteSQL ServerClickHouse
stringVARCHAR(255)VARCHAR(255)TEXTNVARCHAR(255)String
textTEXTLONGTEXTTEXTNVARCHAR(MAX)String
intINTEGERINTINTEGERINTInt64
floatDECIMAL(10,2)DECIMAL(10,2)REALDECIMAL(10,2)Float64
boolBOOLEANTINYINT(1)INTEGERBITUInt8
uuidUUIDCHAR(36)TEXTUNIQUEIDENTIFIERUUID
timeTIMESTAMPDATETIMEDATETIMEDATETIME2DateTime
Last updated on