schema

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const AssetDebug = false

AssetDebug is true if the assets were built with the debug flag enabled.

Variables

View Source
var (
	ErrDirtySchema    = errors.New("schema is dirty requiring a manual migration")
	ErrVariadicDSN    = errors.New("specify zero or 1 dsn urls for configuration")
	ErrNoDatabaseURL  = errors.New("improperly configured: no database dsn")
	ErrNotInitialized = errors.New("schema package not initialized")
)

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDigest

func AssetDigest(name string) ([sha256.Size]byte, error)

AssetDigest returns the digest of the file with the given name. It returns an error if the asset could not be found or the digest could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"}, AssetDir("data/img") would return []string{"a.png", "b.png"}, AssetDir("foo.txt") and AssetDir("notexist") would return an error, and AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func AssetString

func AssetString(name string) (string, error)

AssetString returns the asset contents as a string (instead of a []byte).

func Close

func Close()

Close the migrator and any open sources (errors are ignored)

func Configure

func Configure(vdsn ...string) (err error)

Configure the schema package to perform migration work. This must be called first.

func Digests

func Digests() (map[string][sha256.Size]byte, error)

Digests returns a map of all known files and their checksums.

func Down

func Down(dsn ...string) (err error)

Down moves the database active schema version all the way down to 0

func Drop

func Drop(dsn ...string) (err error)

Drop deletes everything in the database

func Force

func Force(dsn ...string) (err error)

Force sets the database to the current required version regardless of the current active state and resets the dirty flag.

func Migrate

func Migrate(dsn ...string) (err error)

Migrate the database to the latest schema version

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func MustAssetString

func MustAssetString(name string) string

MustAssetString is like AssetString but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory.

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively.

func Verify

func Verify(dsn ...string) (err error)

Verify checks to ensure the database is ready with schema embedded in the binary

func Wait

func Wait(ctx context.Context, dsn ...string) (err error)

Wait until the schema has been migrated to the required version or until the context is canceled, whichever comes first.

Types

type Version

type Version struct {
	Required uint `json:"required,omitempty"`
	Current  uint `json:"current,omitempty"`
	Dirty    bool `json:"dirty,omitempty"`
}

func CurrentVersion

func CurrentVersion(dsn ...string) (*Version, error)

Current version returns the current state of the database

Jump to

Keyboard shortcuts

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