migrations_dynamodb

package module
v0.0.0-...-6d60812 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DynamoDBClient

type DynamoDBClient interface {
	Scan(ctx context.Context, input *dynamodb.ScanInput, optFns ...func(*dynamodb.Options)) (*dynamodb.ScanOutput, error)
	PutItem(ctx context.Context, input *dynamodb.PutItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.PutItemOutput, error)
	DeleteItem(ctx context.Context, input *dynamodb.DeleteItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.DeleteItemOutput, error)
	UpdateItem(ctx context.Context, input *dynamodb.UpdateItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.UpdateItemOutput, error)

	CreateTable(ctx context.Context, input *dynamodb.CreateTableInput, optFns ...func(*dynamodb.Options)) (*dynamodb.CreateTableOutput, error)
	DeleteTable(ctx context.Context, input *dynamodb.DeleteTableInput, optFns ...func(*dynamodb.Options)) (*dynamodb.DeleteTableOutput, error)
	ListTables(ctx context.Context, d *dynamodb.ListTablesInput, optFns ...func(*dynamodb.Options)) (*dynamodb.ListTablesOutput, error)
}

type Option

type Option func(*opts)

func WithLockID

func WithLockID(lockID string) Option

WithLockID sets the lock ID to be used by the DynamoDB lock.

func WithLockTableName

func WithLockTableName(lockTableName string) Option

WithLockTableName sets the lock table name to be used by the DynamoDB lock.

func WithTableName

func WithTableName(tableName string) Option

WithTableName sets the table name to record the database migrations ran.

type Target

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

func NewTarget

func NewTarget(client DynamoDBClient, opts ...Option) *Target

func (*Target) Add

func (t *Target) Add(ctx context.Context, id string) error

func (*Target) Create

func (t *Target) Create(ctx context.Context) error

Create will create the migrations table and the migrations lock table in the DynamoDB.

func (*Target) Current

func (t *Target) Current(ctx context.Context) (string, error)

Current will return the current migration ID. If there is no current migration, it will return a migrations.ErrNoCurrentMigration error. Also, this implementation uses Done, so all errors Done would return can be returned by this method.

func (*Target) Destroy

func (t *Target) Destroy(ctx context.Context) error

Destroy will delete the migrations table and the migrations lock table in the DynamoDB.

func (*Target) Done

func (t *Target) Done(ctx context.Context) ([]string, error)

Done will list all migrations IDs done in the target. If a dirty migration is found, it will return an `migrations.ErrDirtyMigration`. The result will sorted by ID.

func (*Target) FinishMigration

func (t *Target) FinishMigration(ctx context.Context, id string) error

FinishMigration will mark a migration as finished (dirty = false). If the migration does not exist, it will return an `migrations.ErrMigrationNotFound`.

func (*Target) Lock

func (t *Target) Lock(ctx context.Context) (migrations.Unlocker, error)

func (*Target) Remove

func (t *Target) Remove(ctx context.Context, id string) error

Remove will remove a migration from the target. If the migration does not exist, it returns an `migrations.ErrMigrationNotFound`.

func (*Target) StartMigration

func (t *Target) StartMigration(ctx context.Context, id string) error

StartMigration will mark a migration as started (dirty = true). If the migration does not exist, it will return an `migrations.ErrMigrationNotFound`.

type UnlockDynamoDBClient

type UnlockDynamoDBClient interface {
	DeleteItem(ctx context.Context, params *dynamodb.DeleteItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.DeleteItemOutput, error)
}

Jump to

Keyboard shortcuts

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