plover

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT Imports: 5 Imported by: 0

README

Plover

builds.sr.ht status

In app SQL migration runner for SQLite3.

Usage

Here's an example:

import (
	"context"
	"database/sql"
	"log"

	"git.sr.ht/~nds/plover"
	_ "github.com/mattn/go-sqlite3"
)


func main() {
    db, err := sql.Open("sqlite3", ":memory:")
    if err != nil {
        log.Fatalf("Failed to open in-memory database: %v", err)
    }

    if err := plover.Migrate(context.Background(), os.DirFS("."), db, "migrations"); err != nil {
        log.Fatalf("Failed to run migrations: %v", err)
    }

    // App code...
}

You can find more detailed documentation here: https://pkg.go.dev/git.sr.ht/~nds/plover

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, filesystem fs.FS, db *sql.DB, dir string) error

Migrate runs the migrations recording them in the `migrations` table.

For more details on how the migrations are run see `MigrateWithTable`.

func MigrateWithTable added in v1.1.0

func MigrateWithTable(ctx context.Context, filesystem fs.FS, db *sql.DB, dir, table string) error

Migrate runs the migrations in the directory on the given filesystem against the provided database.

Record of the migrations running will be stored in the specified table which is created if necessary. Note tha there is no escaping done on the table name so if it comes from untrusted input you need to escape it yourself using the database driver specific methods.

Each migration is transactional but running all the migrations is not. If the migrations fail part way through the ones that have already successfully run won't be rolled back. Their record of running will have been stored though so the migration won't be re-run on retry.

Types

This section is empty.

Jump to

Keyboard shortcuts

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