Documentation ¶
Index ¶
- Variables
- type Database
- type Mig
- func FromPgxV4(ms Migrations, conn *pgx4.Conn, opts ...Option) *Mig
- func FromPgxV4Pool(ms Migrations, pool *pgxPoolV4.Pool, opts ...Option) (*Mig, func(), error)
- func FromPgxV5(ms Migrations, conn *pgx5.Conn, opts ...Option) *Mig
- func FromPgxV5Pool(ms Migrations, pool *pgxPoolV5.Pool, opts ...Option) (*Mig, func(), error)
- func New(ms Migrations, db Database, opts ...Option) *Mig
- type Migration
- type Migrations
- type Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidVersion = errors.New("invalid migration version prefix") ErrDuplicateVersion = errors.New("duplicate version") )
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database interface { Lock(ctx context.Context) error CreateSchemaMigrationsTable(ctx context.Context) error LastVersion(ctx context.Context) (uint64, error) SetLastVersion(ctx context.Context, lastVersion uint64) error RunMigration(ctx context.Context, query string) error Unlock(ctx context.Context) error }
type Mig ¶
type Mig struct {
// contains filtered or unexported fields
}
func FromPgxV4 ¶ added in v0.1.0
func FromPgxV4(ms Migrations, conn *pgx4.Conn, opts ...Option) *Mig
Example ¶
package main import ( "context" "os" "path/filepath" pgx4 "github.com/jackc/pgx/v4" "go.acim.net/mig" ) const dsn = "postgres://postgres@localhost:5432/mig" func main() { wd, err := os.Getwd() if err != nil { panic(err) } migrations, err := mig.FromDir(filepath.Join(wd, "migrations")) if err != nil { panic(err) } ctx := context.Background() conn, err := pgx4.Connect(ctx, dsn) if err != nil { panic(err) } migrator := mig.FromPgxV4(migrations, conn, mig.WithCustomTable("bob")) if err := migrator.Migrate(ctx); err != nil { panic(err) } }
Output:
func FromPgxV4Pool ¶ added in v0.1.0
Example ¶
package main import ( "context" "os" "path/filepath" pgx4pool "github.com/jackc/pgx/v4/pgxpool" "go.acim.net/mig" ) const dsn = "postgres://postgres@localhost:5432/mig" func main() { wd, err := os.Getwd() if err != nil { panic(err) } migrations, err := mig.FromDir(filepath.Join(wd, "migrations")) if err != nil { panic(err) } ctx := context.Background() pool, err := pgx4pool.Connect(ctx, dsn) if err != nil { panic(err) } migrator, cleanup, err := mig.FromPgxV4Pool(migrations, pool, mig.WithCustomTable("alice")) if err != nil { panic(err) } defer cleanup() if err := migrator.Migrate(ctx); err != nil { panic(err) } }
Output:
func FromPgxV5 ¶ added in v0.1.0
func FromPgxV5(ms Migrations, conn *pgx5.Conn, opts ...Option) *Mig
Example ¶
package main import ( "context" "os" "path/filepath" pgx5 "github.com/jackc/pgx/v5" "go.acim.net/mig" ) const dsn = "postgres://postgres@localhost:5432/mig" func main() { wd, err := os.Getwd() if err != nil { panic(err) } migrations, err := mig.FromDir(filepath.Join(wd, "migrations")) if err != nil { panic(err) } ctx := context.Background() conn, err := pgx5.Connect(ctx, dsn) if err != nil { panic(err) } migrator := mig.FromPgxV5(migrations, conn, mig.WithCustomTable("trudy")) if err := migrator.Migrate(ctx); err != nil { panic(err) } }
Output:
func FromPgxV5Pool ¶ added in v0.1.0
Example ¶
package main import ( "context" "os" "path/filepath" "time" pgx5pool "github.com/jackc/pgx/v5/pgxpool" "go.acim.net/mig" ) const dsn = "postgres://postgres@localhost:5432/mig" func main() { wd, err := os.Getwd() if err != nil { panic(err) } migrations, err := mig.FromDir(filepath.Join(wd, "migrations")) if err != nil { panic(err) } ctx := context.Background() pool, err := pgx5pool.New(ctx, dsn) if err != nil { panic(err) } migrator, cleanup, err := mig.FromPgxV5Pool(migrations, pool, mig.WithCustomTable("eve"), mig.WithAcquireConnectionTimeout(time.Second)) if err != nil { panic(err) } defer cleanup() if err := migrator.Migrate(ctx); err != nil { panic(err) } }
Output:
type Migrations ¶
type Migrations []Migration
func FromDir ¶ added in v0.1.0
func FromDir(path string) (Migrations, error)
func FromEmbedFS ¶
func FromEmbedFS(fs embed.FS, path string) (Migrations, error)
func (*Migrations) Len ¶
func (ms *Migrations) Len() int
func (*Migrations) Less ¶
func (ms *Migrations) Less(i, j int) bool
func (*Migrations) Swap ¶
func (ms *Migrations) Swap(i, j int)
Click to show internal directories.
Click to hide internal directories.