Skip to content

pgx not following intended import behaviour #1035

Open
@krishi-saripalli

Description

@krishi-saripalli

Describe the Bug
This is a follow up to issue #563

Despite following the guidlines about how to import drivers from database, I seem to be hitting the same problem with an unknown import error:

database driver: unknown driver pgx (forgotten import?)

I've also run the neccesary go get command with the pgx tag
go install -tags 'pgx' github.com/golang-migrate/migrate/v4/cmd/migrate@latest

"github.com/golang-migrate/migrate/v4"
	_ "github.com/golang-migrate/migrate/v4/database/pgx/v5"
	_ "github.com/golang-migrate/migrate/v4/source/file"
	
//more imports	
)


func main() {
	ctx := context.Background()
	port := ":8080" // Define the port as a variable for reuse
	lis, err := net.Listen("tcp", port)
	if err != nil {
		log.Fatalf("Failed to listen: %v", err)
	}
	//open db connection
	connStr := GetDbString()
	conn, err := pgx.Connect(ctx, connStr)
	if err != nil {
		log.Fatalf("Failed to connect to Postgres DB: %v", err)
	}
	log.Print("Successfully connected to %f", connStr)
	defer conn.Close(ctx)
	queries := db.New(conn)

	//Create server and register services
	grpcServer := grpc.NewServer()
	
	// Run migrations
	m, err := migrate.New(
		"file:///postgres/migrations",
		"pgx://test_db_user:test_db_password@db:5432/my_test_db")
	if err != nil {
		log.Fatalf("Migration creation failed: %v", err)  <------ failing here
	}
	if err := m.Up(); err != nil {
		if err != migrate.ErrNoChange {
			log.Fatalf("Migration failed: %v", err)
		}
	}
	log.Println("Migration completed successfully")

Steps to Reproduce
Steps to reproduce the behavior:

  1. My migrations look like '...'
  2. I ran migrate with the following options '....'
  3. See error

Expected Behavior
I would expect a succesful migration

Loaded Database Drivers
pgx

Go Version
go 1.21 linux/amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions