Skip to content

cybertec-postgresql/pgx-migrator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Reference Go Report Card Coverage Status

pgx-migrator

Simple pgx oriented PostgreSQL schema migration library for Go based on lopezator/migrator.

Features

  • Simple code
  • Usage as a library, embeddable and extensible on your behalf
  • Made to use with jackc/pgx
  • Go code migrations, either transactional or transaction-less, using pgx.Tx (migrator.Migration) or pgx.Conn and pgx.Pool (migrator.MigrationNoTx)
  • No need to use //go:embed or others, since all migrations are just Go code

Usage

Customize this to your needs by changing the driver and/or connection settings.

QuickStart:

package main

import (

	pgx "github.com/jackc/pgx/v5"
	migrator "github.com/cybertec-postgresql/pgx-migrator"
)

func main() {
    // Configure migrations
    m, err := migrator.New(
        migrator.Migrations(
            &migrator.Migration{
                Name: "Create table foo",
                Func: func(ctx context.Context, tx pgx.Tx) error {
                    _, err := tx.Exec(ctx, "CREATE TABLE foo (id INT PRIMARY KEY)")
                    return err
                },
            },
        ),
    )
    if err != nil {
        panic(err)
    }
   
    // Open database connection
    conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
    if err != nil {
        panic(err)
    }
    
    // Migrate up
    if err := m.Migrate(conn); err != nil {
        panic(err)
    }
}

Contributors 2

  •  
  •  

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy