Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"embed"
"errors"
"fmt"
"io"
"io/fs"
"os"
Expand Down Expand Up @@ -117,6 +118,34 @@ func MigrationToolWithError(conn string, down bool, opts Opts, embeds ...embed.F
return err
}

func MigrationToolWithErrorCtx(ctx context.Context, conn string, down bool, opts Opts, embeds ...embed.FS) error {
resultCh := make(chan error, 1)
go func() {
m, err := Get(ctx, conn, opts, embeds...)
if err != nil {
resultCh <- err
return
}
if m == nil {
resultCh <- errors.New("migration is nil")
return
}

if down {
resultCh <- m.Down()
} else {
resultCh <- m.Up()
}
}()

select {
case err := <-resultCh:
return err
case <-ctx.Done():
return fmt.Errorf("migration operation timed out: %w", ctx.Err())
}
}

func PrepareCockroach(conn string) string {
return strings.Replace(conn, "postgres://", "cockroach://", 1)
}