kvmigrator

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 5 Imported by: 0

README

KV Migrator

This project aims to develop a framework for migrating data stored inside key-value databases.

It is inspired by other migration frameworks in the Go ecosystem which often are aimed towards relational databases.

kvmigrator tries to fill this gap by explicitly focussing on key-value databases. For now development focuses on supporting primarily Redis but theoretically supporting other kv databases should be possible in the future.

Project Status: As long as this readme does not explicitly state any compatibility promises, please don't expect any support activity. As of now consider this project is an experiment. Still, contributions and feedback are welcome.

Contributing

Testing

Currently, tests require a running redis instance available via 127.0.0.1:6379. These tests modify data withing the database so be sure to not accidentally use the wrong database.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisMigration

type RedisMigration struct {
	// ID is the identifier of this migration. It is used by the
	// framework to keep track of pending and finished migrations.
	//
	// It is recommended that you use something like "00000001-init" and
	// "00000002-next-migration" as identifier since this format allows you
	// to both sort your migrations based on the ID (see SortMigrationsByID) and
	// generally identify what your migration does.
	ID string

	// Up is the function implementing the actual migration logic.
	Up RedisUpFunc
}

RedisMigration is a single migration to be run on a database.

func NewRedisMigration

func NewRedisMigration(ID string, up RedisUpFunc) *RedisMigration

func SortMigrationsByID added in v0.3.0

func SortMigrationsByID(migrations []*RedisMigration) []*RedisMigration

SortMigrationsByID sorts the given migrations based on comparing their IDs.

strings.Compare is used as comparator. Look at the tests of this function if you want to see examples of how this is sorted.

The input slice is not modified in-place but instead a new, sorted slice is returned.

Once this module reaches v1 its sorting algorithm should not be changed.

func SortRedisMigrations added in v0.3.0

func SortRedisMigrations(migrations []*RedisMigration, cmp func(a, b *RedisMigration) int) []*RedisMigration

SortRedisMigrations is a helper function to sort the given migrations. You can supply your own comparator function to be used for sorting.

The input slice is not modified in-place but instead a new, sorted slice is returned.

type RedisMigrator

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

RedisMigrator runs migrations (RedisMigration) for a given redis.Client.

func NewRedisMigrator

func NewRedisMigrator(client *redis.Client, prefix string) *RedisMigrator

NewRedisMigrator creates a new migrator using the given client.

The given prefix is used for internal keys which the migrator maintains to manage migrations.

func (*RedisMigrator) AddMigrations

func (migrator *RedisMigrator) AddMigrations(m ...*RedisMigration) *RedisMigrator

func (*RedisMigrator) Migrate

func (migrator *RedisMigrator) Migrate(ctx context.Context) error

func (*RedisMigrator) SetKeyPrefix

func (migrator *RedisMigrator) SetKeyPrefix(prefix string) *RedisMigrator

SetKeyPrefix sets the prefix used on all keys used to manage migrations.

type RedisUpFunc

type RedisUpFunc = func(ctx context.Context, client *redis.Client) error

Jump to

Keyboard shortcuts

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