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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址