package migrate
import "github.com/pressly/goose/v3/internal/migrate"
Package migrate defines a Migration struct and implements the migration logic for executing Go and SQL migrations.
- For Go migrations, only *sql.Tx and *sql.DB are supported. *sql.Conn is not supported.
- For SQL migrations, all three are supported.
Lastly, SQL migrations are lazily parsed. This means that the SQL migration is parsed the first time it is executed.
Index ¶
- func ParseSQL(fsys fs.FS, debug bool, migrations []*Migration) error
- type Go
- type Migration
- func (m *Migration) GetSQLStatements(direction bool) ([]string, error)
- func (m *Migration) IsEmpty(direction bool) bool
- func (m *Migration) Run(ctx context.Context, tx *sql.Tx, direction bool) error
- func (m *Migration) RunConn(ctx context.Context, conn *sql.Conn, direction bool) error
- func (m *Migration) RunNoTx(ctx context.Context, db *sql.DB, direction bool) error
- func (m *Migration) UseTx() bool
- type MigrationType
- type SQL
Functions ¶
func ParseSQL ¶
ParseSQL parses all SQL migrations in BOTH directions. If a migration has already been parsed, it will not be parsed again.
Important: This function will mutate SQL migrations.
Types ¶
type Go ¶
type Go struct { // We used an explicit bool instead of relying on a pointer because registered funcs may be nil. // These are still valid Go and versioned migrations, but they are just empty. // // For example: goose.AddMigration(nil, nil) UseTx bool // Only one of these func pairs will be set: UpFn, DownFn func(context.Context, *sql.Tx) error // -- or -- UpFnNoTx, DownFnNoTx func(context.Context, *sql.DB) error }
func (*Go) IsEmpty ¶
type Migration ¶
type Migration struct { // Fullpath is the full path to the migration file. // // Example: /path/to/migrations/123_create_users_table.go Fullpath string // Version is the version of the migration. Version int64 // Type is the type of migration. Type MigrationType // A migration is either a Go migration or a SQL migration, but never both. // // Note, the SQLParsed field is used to determine if the SQL migration has been parsed. This is // an optimization to avoid parsing the SQL migration if it is never required. Also, the // majority of the time migrations are incremental, so it is likely that the user will only want // to run the last few migrations, and there is no need to parse ALL prior migrations. // // Exactly one of these fields will be set: Go *Go // -- or -- SQLParsed bool SQL *SQL }
func (*Migration) GetSQLStatements ¶
func (*Migration) IsEmpty ¶
func (*Migration) Run ¶
Run runs the migration inside of a transaction.
func (*Migration) RunConn ¶
RunConn runs the migration without a transaction using the provided connection.
func (*Migration) RunNoTx ¶
RunNoTx runs the migration without a transaction.
func (*Migration) UseTx ¶
type MigrationType ¶
type MigrationType int
const ( TypeGo MigrationType = iota + 1 TypeSQL )
func (MigrationType) String ¶
func (t MigrationType) String() string
type SQL ¶
func (*SQL) IsEmpty ¶
Source Files ¶
doc.go migration.go parse.go run.go
- Version
- v3.15.1
- Published
- Oct 10, 2023
- Platform
- windows/amd64
- Imports
- 10 packages
- Last checked
- 48 minutes ago –
Tools for package owners.