diff --git a/cmd/goyco/commands/seed.go b/cmd/goyco/commands/seed.go index 44df0c4..43b0c65 100644 --- a/cmd/goyco/commands/seed.go +++ b/cmd/goyco/commands/seed.go @@ -57,10 +57,15 @@ func HandleSeedCommand(cfg *config.Config, name string, args []string) error { } return withDatabase(cfg, func(db *gorm.DB) error { - userRepo := repositories.NewUserRepository(db) - postRepo := repositories.NewPostRepository(db) - voteRepo := repositories.NewVoteRepository(db) - return runSeedCommand(userRepo, postRepo, voteRepo, fs.Args()) + return db.Transaction(func(tx *gorm.DB) error { + userRepo := repositories.NewUserRepository(db).WithTx(tx) + postRepo := repositories.NewPostRepository(db).WithTx(tx) + voteRepo := repositories.NewVoteRepository(db).WithTx(tx) + if err := runSeedCommand(userRepo, postRepo, voteRepo, fs.Args()); err != nil { + return err + } + return nil + }) }) }