reshapehelper

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2023 License: MIT Imports: 10 Imported by: 0

README

Reshape Go helper

This is a Go helper library for the automated, zero-downtime schema migration tool Reshape. To achieve zero-downtime migrations, Reshape requires that your application runs a simple query when it opens a connection to the database to select the right schema. This library automates that process with a simple method which will return the correct query for your application.

Installation

TBD

Usage

The library includes a SchemaQuery method which will find all Reshape migration files and determine the right schema query to run. Here's an example of how to use it along with pgxpool:

import	(
	reshapehelper "github.com/leourbina/reshape-helper"
)

func main() {
	query := reshapehelper.SchemaQuery()

	config, err := pgxpool.ParseConfig(os.Getenv("DATABASE_URL"))
	if err != nil {
		// ...
	}
	config.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
		_, err := conn.Exec(ctx, query)
		if err != nil {
			// ...
		}
	}

	pool, err := pgxpool.ConnectConfig(context.Background(), config)
}

By default, SchemaQuery will look for migration files in /migrations but you can specify your own directories as well:

import	(
	reshapehelper "github.com/leourbina/reshape-helper"
)

func main() {
	query := reshapehelper.SchemaQuery(
		"src/users/migrations",
		"src/todos/migrations",
	)
}

License

Release under the MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DEFAULT_SEARCH_PATH string = `"$user", public`

Functions

func SearchQuery

func SearchQuery(dirs ...string) string

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL