github.com/postmates/migrate@v3.0.2-0.20200730201548-1a6ead3e680d+incompatible/database/redshift/redshift.go (about)

     1  package redshift
     2  
     3  import (
     4  	"net/url"
     5  
     6  	"github.com/mattes/migrate/database"
     7  	"github.com/mattes/migrate/database/postgres"
     8  )
     9  
    10  // init registers the driver under the name 'redshift'
    11  func init() {
    12  	db := new(Redshift)
    13  	db.Driver = new(postgres.Postgres)
    14  
    15  	database.Register("redshift", db)
    16  }
    17  
    18  // Redshift is a wrapper around the PostgreSQL driver which implements Redshift-specific behavior.
    19  //
    20  // Currently, the only different behaviour is the lack of locking in Redshift.  The (Un)Lock() method(s) have been overridden from the PostgreSQL adapter to simply return nil.
    21  type Redshift struct {
    22  	// The wrapped PostgreSQL driver.
    23  	database.Driver
    24  }
    25  
    26  // Open implements the database.Driver interface by parsing the URL, switching the scheme from "redshift" to "postgres", and delegating to the underlying PostgreSQL driver.
    27  func (driver *Redshift) Open(dsn string) (database.Driver, error) {
    28  	parsed, err := url.Parse(dsn)
    29  	if err != nil {
    30  		return nil, err
    31  	}
    32  
    33  	parsed.Scheme = "postgres"
    34  	psql, err := driver.Driver.Open(parsed.String())
    35  	if err != nil {
    36  		return nil, err
    37  	}
    38  
    39  	return &Redshift{Driver: psql}, nil
    40  }
    41  
    42  // Lock implements the database.Driver interface by not locking and returning nil.
    43  func (driver *Redshift) Lock() error { return nil }
    44  
    45  // Unlock implements the database.Driver interface by not unlocking and returning nil.
    46  func (driver *Redshift) Unlock() error { return nil }