storage

package
v0.0.0-...-61deab7 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2014 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

This file manages schema modification.

There are a couple pieces to this:

1 Each schema modification is in a self contained directory with the a directory name 2. Each modification must contain an 'upgrade.sql' 3. Each modification *may* contain a 'downgrade.sql' script 4. Failure to include a downgrade script means we cannot downgrade past a particular version.

Every revision is stored in a directory named:

rev.<SHA1_HEX>.<description>

Each directory contains:
	(mandatory) prev.txt		-- contains the revision code for the previous patch
	(mandatory) upgrade.sql		-- upgrade sql
	(optional) downgrade.sql	-- downgrade sql

Index

Constants

View Source
const (
	DB_VERSION = "20140707"
)

Variables

View Source
var AvailableStores = make(AvailableStorage)
View Source
var ErrDatabase = errors.New("Database Error")
View Source
var ErrUnknownDevice = errors.New("Unknown device")

Functions

func GetPatchDirectory

func GetPatchDirectory(patch_root, revision string) (result string, err error)

Types

type AvailableStorage

type AvailableStorage map[string]func(*util.MzConfig, util.Logger, util.Metrics) (Storage, error)

type DBRcs

type DBRcs struct {
	Db *sql.DB
	// contains filtered or unexported fields
}

func (*DBRcs) Changelog

func (self *DBRcs) Changelog(patch_root string) (err error)

func (*DBRcs) Close

func (self *DBRcs) Close() (err error)

func (*DBRcs) ComputeHistory

func (self *DBRcs) ComputeHistory(patch_root string) (err error)

func (*DBRcs) CreateNextRev

func (self *DBRcs) CreateNextRev(patch_root string, description string) (prev string, rev string, err error)

func (*DBRcs) CurrentDBVersion

func (self *DBRcs) CurrentDBVersion() (db_ver string, err error)

func (*DBRcs) Downgrade

func (self *DBRcs) Downgrade(patch_root, version string) (err error)

func (*DBRcs) FindLastVersion

func (self *DBRcs) FindLastVersion(patch_root string) (result string, err error)

func (*DBRcs) Init

func (self *DBRcs) Init(config *util.MzConfig) (err error)

func (*DBRcs) InitVersioning

func (self *DBRcs) InitVersioning() (err error)

func (*DBRcs) Upgrade

func (self *DBRcs) Upgrade(patch_root string, verbose bool) (err error)

type Device

type Device struct {
	ID                string // device Id
	User              string // userID
	Name              string
	PreviousPositions []Position
	HasPasscode       bool   // is device lockable
	LoggedIn          bool   // is the device logged in
	Secret            string // HAWK secret
	PushUrl           string // SimplePush URL
	Pending           string // pending command
	LastExchange      int32  // last time we did anything
	Accepts           string // commands the device accepts
	AccessToken       string // OAuth Access token
}

Device information

type DeviceList

type DeviceList struct {
	ID   string
	Name string
}

type Position

type Position struct {
	Latitude  float64
	Longitude float64
	Altitude  float64
	Accuracy  float64
	Time      int64
	Cmd       map[string]interface{}
}

Device position

type Storage

type Storage interface {
	Init() error
	RegisterDevice(string, *Device) (string, error)
	GetDeviceInfo(string) (*Device, error)
	GetPositions(string) ([]Position, error)
	GetPending(string) (string, string, error)
	GetUserFromDevice(string) (string, string, error)
	GetDevicesForUser(string, string) ([]DeviceList, error)
	StoreCommand(string, string, string) error
	SetAccessToken(string, string) error
	SetDeviceLock(string, bool) error
	SetDeviceLocation(string, *Position) error
	GcDatabase(string, string) error
	PurgePosition(string) error
	Touch(string) error
	DeleteDevice(string) error
	PurgeCommands(string) error
	Close()
	GetNonce() (string, error)
	CheckNonce(string) (bool, error)
}

func OpenInmemory

func OpenInmemory(config *util.MzConfig, logger util.Logger, metrics util.Metrics) (storage Storage, err error)

Open the database.

func OpenPostgres

func OpenPostgres(config *util.MzConfig, logger util.Logger, metrics util.Metrics) (storage Storage, err error)

Open the database.

type Unstructured

type Unstructured map[string]interface{}

Generic structure useful for JSON

Jump to

Keyboard shortcuts

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