github.com/goravel/framework@v1.13.9/database/console/migrate_make_command.go (about) 1 package console 2 3 import ( 4 "github.com/gookit/color" 5 6 "github.com/goravel/framework/contracts/config" 7 "github.com/goravel/framework/contracts/console" 8 "github.com/goravel/framework/contracts/console/command" 9 ) 10 11 type MigrateMakeCommand struct { 12 config config.Config 13 } 14 15 func NewMigrateMakeCommand(config config.Config) *MigrateMakeCommand { 16 return &MigrateMakeCommand{config: config} 17 } 18 19 // Signature The name and signature of the console command. 20 func (receiver *MigrateMakeCommand) Signature() string { 21 return "make:migration" 22 } 23 24 // Description The console command description. 25 func (receiver *MigrateMakeCommand) Description() string { 26 return "Create a new migration file" 27 } 28 29 // Extend The console command extend. 30 func (receiver *MigrateMakeCommand) Extend() command.Extend { 31 return command.Extend{ 32 Category: "make", 33 } 34 } 35 36 // Handle Execute the console command. 37 func (receiver *MigrateMakeCommand) Handle(ctx console.Context) error { 38 // It's possible for the developer to specify the tables to modify in this 39 // schema operation. The developer may also specify if this table needs 40 // to be freshly created, so we can create the appropriate migrations. 41 name := ctx.Argument(0) 42 if name == "" { 43 color.Redln("Not enough arguments (missing: name)") 44 45 return nil 46 } 47 48 // We will attempt to guess the table name if this the migration has 49 // "create" in the name. This will allow us to provide a convenient way 50 // of creating migrations that create new tables for the application. 51 table, create := TableGuesser{}.Guess(name) 52 53 //Write the migration file to disk. 54 migrateCreator := NewMigrateCreator(receiver.config) 55 if err := migrateCreator.Create(name, table, create); err != nil { 56 return err 57 } 58 59 color.Green.Printf("Created Migration: %s\n", name) 60 61 return nil 62 }