Panel.go Migration Generator
Expert in generating GORM migrations for Panel.go database schema with proper indexes, constraints, and relationships.
Expertise
- GORM Migrations: AutoMigrate, CreateTable, AddColumn, AddIndex
- Data Types: String, Int, Bool, Time, JSON, UUID
- Constraints: Primary Key, Foreign Key, Unique, Not Null, Default
- Indexes: Single column, composite, unique indexes
- Relationships: Foreign keys, cascade deletes, on update
- Soft Deletes: GORM's DeletedAt field
- Timestamps: CreatedAt, UpdatedAt auto-management
Quick Patterns
Basic Entity
type Product struct {
ID uint `gorm:"primaryKey"`
Name string `gorm:"size:255;not null;index"`
Description string `gorm:"type:text"`
Price float64 `gorm:"type:decimal(10,2);not null"`
Stock int `gorm:"default:0;not null"`
CategoryID uint `gorm:"not null;index"`
Category *Category `gorm:"foreignKey:CategoryID;constraint:OnUpdate:CASCADE,OnDelete:RESTRICT"`
CreatedAt time.Time `gorm:"index"`
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
}
Run Migrations
func RunMigrations(db *gorm.DB) error {
return db.AutoMigrate(
&domain.User{},
&domain.Post{},
&domain.Category{},
)
}
Key Rules
- Always index foreign keys
- Use soft deletes (gorm.DeletedAt)
- Add timestamps (CreatedAt, UpdatedAt)
- Plural table names (users, posts)
- Define cascade rules (OnUpdate, OnDelete)
- Index searchable fields
Usage
When user asks to create a migration or entity:
- Create entity in
pkg/domain/{name}/entity.go
- Add GORM tags for constraints and indexes
- Define TableName() method
- Add to AutoMigrate in migrations.go
Anti-Patterns
❌ Don't skip indexes on foreign keys - Always index foreign keys
❌ Don't forget soft deletes - Use gorm.DeletedAt for audit trails
❌ Don't skip timestamps - Always add CreatedAt, UpdatedAt
❌ Don't use singular table names - Use plural (users, not user)
❌ Don't forget cascade rules - Define OnUpdate and OnDelete behavior
Sharp Edges
⚠️ Foreign Keys: Always define constraint behavior (CASCADE, RESTRICT, SET NULL)
⚠️ Indexes: Index all foreign keys and searchable fields
⚠️ Soft Deletes: Use gorm.DeletedAt, not custom deleted_at
⚠️ Table Names: Override TableName() for custom names
⚠️ Migration Order: Migrate parent tables before child tables
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: panel-go-migration3description: Generate GORM migrations for Panel.go database schema with proper indexes, constraints, and relationships. Use when creating database tables, adding columns, or defining entity structures. Use when this capability is needed.4---56# Panel.go Migration Generator78Expert in generating GORM migrations for Panel.go database schema with proper indexes, constraints, and relationships.910## Expertise1112- **GORM Migrations**: AutoMigrate, CreateTable, AddColumn, AddIndex13- **Data Types**: String, Int, Bool, Time, JSON, UUID14- **Constraints**: Primary Key, Foreign Key, Unique, Not Null, Default15- **Indexes**: Single column, composite, unique indexes16- **Relationships**: Foreign keys, cascade deletes, on update17- **Soft Deletes**: GORM's DeletedAt field18- **Timestamps**: CreatedAt, UpdatedAt auto-management1920## Quick Patterns2122### Basic Entity23```go24type Product struct {25 ID uint `gorm:"primaryKey"`26 Name string `gorm:"size:255;not null;index"`27 Description string `gorm:"type:text"`28 Price float64 `gorm:"type:decimal(10,2);not null"`29 Stock int `gorm:"default:0;not null"`30 CategoryID uint `gorm:"not null;index"`31 Category *Category `gorm:"foreignKey:CategoryID;constraint:OnUpdate:CASCADE,OnDelete:RESTRICT"`32 CreatedAt time.Time `gorm:"index"`33 UpdatedAt time.Time34 DeletedAt gorm.DeletedAt `gorm:"index"`35}36```3738### Run Migrations39```go40func RunMigrations(db *gorm.DB) error {41 return db.AutoMigrate(42 &domain.User{},43 &domain.Post{},44 &domain.Category{},45 )46}47```4849## Key Rules5051- **Always index foreign keys**52- **Use soft deletes** (gorm.DeletedAt)53- **Add timestamps** (CreatedAt, UpdatedAt)54- **Plural table names** (users, posts)55- **Define cascade rules** (OnUpdate, OnDelete)56- **Index searchable fields**5758## Usage5960When user asks to create a migration or entity:61621. Create entity in `pkg/domain/{name}/entity.go`632. Add GORM tags for constraints and indexes643. Define TableName() method654. Add to AutoMigrate in migrations.go6667## Anti-Patterns6869❌ **Don't skip indexes on foreign keys** - Always index foreign keys70❌ **Don't forget soft deletes** - Use gorm.DeletedAt for audit trails71❌ **Don't skip timestamps** - Always add CreatedAt, UpdatedAt72❌ **Don't use singular table names** - Use plural (users, not user)73❌ **Don't forget cascade rules** - Define OnUpdate and OnDelete behavior7475## Sharp Edges7677⚠️ **Foreign Keys**: Always define constraint behavior (CASCADE, RESTRICT, SET NULL)78⚠️ **Indexes**: Index all foreign keys and searchable fields79⚠️ **Soft Deletes**: Use gorm.DeletedAt, not custom deleted_at80⚠️ **Table Names**: Override TableName() for custom names81⚠️ **Migration Order**: Migrate parent tables before child tables8283---84> Converted and distributed by [TomeVault](https://tomevault.io/claim/ferdiunal) — claim your Tome and manage your conversions.85<!-- tomevault:4.0:skill_md:2026-04-13 -->