Add CLI support for model generation
This commit is contained in:
parent
1295b207bb
commit
2698f0845e
@ -1,8 +0,0 @@
|
|||||||
package entity
|
|
||||||
|
|
||||||
type User struct {
|
|
||||||
ID uint
|
|
||||||
|
|
||||||
Name string `gorm:"column:name"`
|
|
||||||
Email string `gorm:"column:email"`
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package migrations
|
|
||||||
|
|
||||||
import (
|
|
||||||
"gorm.io/gorm/configs"
|
|
||||||
"gorm.io/gorm/internal/models"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Up migrates table User
|
|
||||||
func UpUser() {
|
|
||||||
configs.DB.AutoMigrate(&models.User{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Down rolls back table User
|
|
||||||
func DownUser() {
|
|
||||||
configs.DB.Migrator().DropTable(&models.User{})
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package migrations
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func MigrateAll() {
|
|
||||||
fmt.Println("Running migrations...")
|
|
||||||
UpUser()
|
|
||||||
// Add other migrations here
|
|
||||||
fmt.Println("Migrations completed!")
|
|
||||||
}
|
|
||||||
|
|
||||||
func RollbackAll() {
|
|
||||||
fmt.Println("Rolling back migrations...")
|
|
||||||
DownUser()
|
|
||||||
// Add other rollbacks here
|
|
||||||
fmt.Println("Rollback completed!")
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
type User struct {
|
|
||||||
ID uint `gorm:"primaryKey"`
|
|
||||||
CreatedAt time.Time
|
|
||||||
UpdatedAt time.Time
|
|
||||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
|
||||||
|
|
||||||
Name string `gorm:"column:name"`
|
|
||||||
Email string `gorm:"column:email"`
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user