go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/db/migration/step.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package migration 9 10 import ( 11 "context" 12 "database/sql" 13 14 "go.charczuk.com/sdk/db" 15 ) 16 17 // NewStep returns a new Step, given a GuardFunc and an Action 18 func NewStep(guard GuardFunc, action Action) *Step { 19 return &Step{ 20 Guard: guard, 21 Body: action, 22 } 23 } 24 25 // Step is a guarded action. The GuardFunc will decide whether to execute this Action 26 type Step struct { 27 Guard GuardFunc 28 Body Action 29 } 30 31 // Action implements the Actionable interface and runs the body if the provided guard passes. 32 func (ga *Step) Action(ctx context.Context, c *db.Connection, tx *sql.Tx) error { 33 return ga.Guard(ctx, c, tx, ga.Body) 34 }