-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create go command migrate and seeder
- Loading branch information
Showing
4 changed files
with
69 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/Caknoooo/go-gin-clean-starter/migrations" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func Commands(db *gorm.DB) { | ||
migrate := false | ||
seed := false | ||
|
||
for _, arg := range os.Args[1:] { | ||
if arg == "--migrate" { | ||
migrate = true | ||
} | ||
if arg == "--seed" { | ||
seed = true | ||
} | ||
} | ||
|
||
if migrate { | ||
if err := migrations.Migrate(db); err != nil { | ||
log.Fatalf("error migration: %v", err) | ||
} | ||
log.Println("migration completed successfully") | ||
} | ||
|
||
if seed { | ||
if err := migrations.Seeder(db); err != nil { | ||
log.Fatalf("error migration seeder: %v", err) | ||
} | ||
log.Println("seeder completed successfully") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters