dbmigrator

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 6 Imported by: 0

README

dbmigrator

Go database migration library compatible with sql.DB

GoDoc Tests

This package provides method for database migration any stdlib's sql.DB compatibility database

Restrictions

  • Library does not care about version naming. Migrations runs in a lexical sort manner of filenames

    Semver/integer/timestamp typed versions requires different parse logics. Best run order was invented in unix's init.d : do lexical sort of files. Nothing good invented after that thing

  • Ensure you trust fs.FS content. Library executes it as is, without any validation

    Library does not care of migration folder content. It does not know any DB engine specific functions/syntax

  • Do not use transaction in migrations

    Library executes migration inside transactions to commit success upgrade in version table. There is no way to embed transaction in transaction

  • There is no downgrade feature and never release it

    Because once you upgraded it, no one can guarantee that other application instances wont downgrade it. That means you should do version check every transaction. I have never seen such braindead devs who wrote code like this

  • Try to migrate safety

    Do not break DB schemes by 1 migration. Use common way with at least 2 releases:

    1. release app version N+1 with new scheme without any breaking changes
    2. wait until rolling update completes
    3. release app version N+2 with removes unused parts of scheme

License

MIT licensed. See the included LICENSE file for details.

Documentation

Overview

Package dbmigrator provides method for database migration any stdlib's sql.DB compatibility database

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, fsys fs.FS, pool DBPool, versionSchemeName string) error

Types

type DBPool

type DBPool interface {
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}

Jump to

Keyboard shortcuts

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