github.com/goravel/framework@v1.13.9/database/console/migrate_status_command.go (about) 1 package console 2 3 import ( 4 _ "github.com/go-sql-driver/mysql" 5 _ "github.com/golang-migrate/migrate/v4/source/file" 6 "github.com/gookit/color" 7 8 "github.com/goravel/framework/contracts/config" 9 "github.com/goravel/framework/contracts/console" 10 "github.com/goravel/framework/contracts/console/command" 11 ) 12 13 type MigrateStatusCommand struct { 14 config config.Config 15 } 16 17 func NewMigrateStatusCommand(config config.Config) *MigrateStatusCommand { 18 return &MigrateStatusCommand{ 19 config: config, 20 } 21 } 22 23 // Signature The name and signature of the console command. 24 func (receiver *MigrateStatusCommand) Signature() string { 25 return "migrate:status" 26 } 27 28 // Description The console command description. 29 func (receiver *MigrateStatusCommand) Description() string { 30 return "Show the status of each migration" 31 } 32 33 // Extend The console command extend. 34 func (receiver *MigrateStatusCommand) Extend() command.Extend { 35 return command.Extend{ 36 Category: "migrate", 37 } 38 } 39 40 // Handle Execute the console command. 41 func (receiver *MigrateStatusCommand) Handle(ctx console.Context) error { 42 m, err := getMigrate(receiver.config) 43 if err != nil { 44 return err 45 } 46 if m == nil { 47 color.Yellowln("Please fill database config first") 48 return nil 49 } 50 51 version, dirty, err := m.Version() 52 if err != nil { 53 color.Redln("Migration status failed:", err.Error()) 54 55 return nil 56 } 57 58 if dirty { 59 color.Yellowln("Migration status: dirty") 60 color.Greenln("Migration version:", version) 61 62 return nil 63 } 64 65 color.Greenln("Migration status: clean") 66 color.Greenln("Migration version:", version) 67 68 return nil 69 }