storage

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeBoltDB   = "boltdb"
	TypePostgres = "postgres"
)

Allowed database storage types.

Variables

This section is empty.

Functions

func PreInit

func PreInit(pathConfigFile string) error

PreInit runs preinit function.

Types

type BoltDB

type BoltDB struct {
	// contains filtered or unexported fields
}

BoltDB represents a collection of buckets persisted to a file on disk.

func (*BoltDB) CheckMigration

func (b *BoltDB) CheckMigration(projectName, dbName, version string) (bool, error)

CheckMigration checks the migration was done successfully.

func (*BoltDB) Close

func (b *BoltDB) Close() error

Close releases all database resources. All transactions must be closed before closing the database.

func (*BoltDB) CreateProjectDB

func (b *BoltDB) CreateProjectDB(projectName, dbName string) error

CreateProjectDB creates a new bucket for project and database if it doesn't already exist.

func (*BoltDB) Delete

func (b *BoltDB) Delete(post *Migrate) error

Delete calls migration down.

func (*BoltDB) GetLast

func (b *BoltDB) GetLast(projectName, dbName string, skipNoRollback bool, limit *int) ([]Migrate, error)

GetLast gets a list of recent migrations.

func (*BoltDB) Init

func (b *BoltDB) Init(cfg *Config) error

Init creates and opens a database at the given path. If the file does not exist then it will be created automatically.

func (*BoltDB) PreInit

func (b *BoltDB) PreInit(cfg *Config) error

PreInit creates dir fo database file is not exists.

func (*BoltDB) Up

func (b *BoltDB) Up(post *Migrate) error

Up runs migration up.

type Config

type Config struct {
	StorageType string `yaml:"storage_type"`
	Path        string `yaml:"path"`
	DSN         string `yaml:"dsn"`
	Schema      string `yaml:"schema"`
}

Config contains storage credentials information.

type Migrate

type Migrate struct {
	Project   string
	Database  string
	Version   string
	ApplyTime int64
	RollFlag  bool
}

Migrate is the model for table migration.

type PostgreSQL

type PostgreSQL struct {
	// contains filtered or unexported fields
}

PostgreSQL is a database handle representing a pool of zero or more underlying connections.

func (*PostgreSQL) CheckMigration

func (p *PostgreSQL) CheckMigration(projectName, dbName, version string) (bool, error)

CheckMigration checks the migration was done successfully.

func (*PostgreSQL) Close

func (p *PostgreSQL) Close() error

Close closes the database and prevents new queries from starting. Close then waits for all queries that have started processing on the server to finish.

func (*PostgreSQL) CreateProjectDB

func (*PostgreSQL) CreateProjectDB(string, string) error

CreateProjectDB does nothing. Function is not needed for postgres. Introduced to implement the Storage interface.

func (*PostgreSQL) Delete

func (p *PostgreSQL) Delete(post *Migrate) error

Delete calls migration down.

func (*PostgreSQL) GetLast

func (p *PostgreSQL) GetLast(projectName, dbName string, skipNoRollback bool, limit *int) ([]Migrate, error)

GetLast gets a list of recent migrations.

func (*PostgreSQL) Init

func (p *PostgreSQL) Init(cfg *Config) error

Init opens a database specified by its database driver name and a driver-specific data source name.

func (*PostgreSQL) PreInit

func (p *PostgreSQL) PreInit(cfg *Config) error

PreInit creates migrago table.

func (*PostgreSQL) Up

func (p *PostgreSQL) Up(post *Migrate) error

Up runs migration up.

type Storage

type Storage interface {
	PreInit(cfg *Config) error
	Init(cfg *Config) error
	Close() error
	CreateProjectDB(projectName, dbName string) error
	CheckMigration(projectName, dbName, version string) (bool, error)
	Up(post *Migrate) error
	GetLast(projectName, dbName string, skipNoRollback bool, limit *int) ([]Migrate, error)
	Delete(post *Migrate) error
}

Storage describes methods for working with a migration storage.

func New

func New(pathConfigFile string) (Storage, error)

New creates instance for work with migrations.

Jump to

Keyboard shortcuts

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