startup

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2017 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package startup of the Tideland Go CouchDB Client provides a simple mechanism for a clean startup and maintenance of CouchDB databases.

The major function is

err := startup.Run(cdb, stepA, stepB, stepC)

Here cdb is the opened CouchDB and the steps is a variadic number of functions having the signature

func(cdb couchdb.CouchDB, v version.Version) (version.Version, error)

When Run() is called it first checks if the database already exists and if needed creates it. Then it adds a version document with the version 0.0.0. Now each step is called in order with the current version. It can check if it has to modify the database (e.g. add design and other document, add fields to existing documents, transform documents, etc.), perform those changes, and return the new version. So the version document will be updated and the next step performed.

Index

Constants

View Source
const (
	ErrIllegalVersion = iota + 1
	ErrStartupActionFailed
)

Error codes.

View Source
const DatabaseVersionID = "database-version"

DatabaseVersionID is used for the database version document.

Variables

This section is empty.

Functions

func Run

func Run(cdb couchdb.CouchDB, steps ...Step) error

Run checks and creates the database if needed and performs the individual steps.

Types

type DatabaseVersion

type DatabaseVersion struct {
	ID       string `json:"_id"`
	Revision string `json:"_rev,omitempty"`
	Version  string `json:"version"`
}

DatabaseVersion stores the current database version with the document ID "database-version".

type Step

type Step func() (version.Version, StepAction)

Step returns the version after a startup step and the action that shall be performed on the database. The returned action will only be performed, if the current if the new version is than the current version.

type StepAction

type StepAction func(cdb couchdb.CouchDB) error

StepAction is the concrete action of a step.

type Steps

type Steps []Step

Steps is just an ordered number of steps.

Jump to

Keyboard shortcuts

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