github.com/wawandco/ox@v0.13.6-0.20230809142027-913b3d837f2a/plugins/tools/soda/up.go (about)

     1  package soda
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/gobuffalo/pop/v6"
     7  )
     8  
     9  // Run will run migrations on the current folder, it will look for the
    10  // migrations folder and attempt to run the migrations using internal
    11  // pop tooling
    12  func (mu *Command) RunUp() error {
    13  	pop.SetLogger(mu.Log)
    14  
    15  	conn := pop.Connections[mu.connectionName]
    16  	if conn == nil {
    17  		return ErrCouldNotFindConnection
    18  	}
    19  
    20  	mig, err := pop.NewMigrationBox(mu.migrations, conn)
    21  	if err != nil {
    22  		return err
    23  	}
    24  
    25  	_, err = mig.UpTo(mu.steps)
    26  	return err
    27  }
    28  
    29  func (mu *Command) Reset(ctx context.Context, conn *pop.Connection) error {
    30  	pop.SetLogger(mu.Log)
    31  
    32  	mig, err := pop.NewMigrationBox(mu.migrations, conn)
    33  	if err != nil {
    34  		return err
    35  	}
    36  
    37  	_, err = mig.UpTo(mu.steps)
    38  	return err
    39  }
    40  
    41  func (mu *Command) RunBeforeTest(ctx context.Context, root string, args []string) error {
    42  	pop.SetLogger(mu.Log)
    43  
    44  	conn := pop.Connections["test"]
    45  	if conn == nil {
    46  		return ErrCouldNotFindConnection
    47  	}
    48  
    49  	mig, err := pop.NewMigrationBox(mu.migrations, conn)
    50  	if err != nil {
    51  		return err
    52  	}
    53  
    54  	err = mig.Up()
    55  	return err
    56  }