migrate

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DynamoDB = "AWS::DynamoDB::Table"
View Source
const MigrationTable = "dynamo_migrations"

Variables

View Source
var ErrTableAlreadyExists = errors.New("table already exists")

Functions

func SaveRecord

func SaveRecord(ctx context.Context, api MigrationApi, tableName string, record map[string]interface{}) (err error)

Types

type Attribute

type Attribute struct {
	Type types.ScalarAttributeType `json:"AttributeType" yaml:"AttributeType"`
	Name string                    `json:"AttributeName" yaml:"AttributeName"`
}

func NewBinaryAttribute added in v0.1.12

func NewBinaryAttribute(name string) Attribute

func NewNumberAttribute added in v0.1.12

func NewNumberAttribute(name string) Attribute

func NewStringAttribute added in v0.1.12

func NewStringAttribute(name string) Attribute

func (Attribute) Definition

func (attr Attribute) Definition() types.AttributeDefinition

func (Attribute) HashKey added in v0.1.12

func (attr Attribute) HashKey() KeySchema

func (Attribute) RangeKey added in v0.1.12

func (attr Attribute) RangeKey() KeySchema

type Attributes

type Attributes []Attribute

func (Attributes) Definitions

func (attrs Attributes) Definitions() []types.AttributeDefinition

func (Attributes) Map

func (attrs Attributes) Map() map[string]types.ScalarAttributeType

type FilesMigrate

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

func (*FilesMigrate) Read added in v0.1.3

func (v *FilesMigrate) Read(ctx context.Context) (schemas []Schema, err error)

func (*FilesMigrate) Run

func (v *FilesMigrate) Run(ctx context.Context, save SaveFunc) (err error)

type IndexOption added in v0.1.12

type IndexOption func(si *SecondaryIndex)

func WithIndexProjection added in v0.1.12

func WithIndexProjection(t types.ProjectionType, attrs ...string) IndexOption

func WithIndexThroughput added in v0.1.12

func WithIndexThroughput(read, write int64) IndexOption

type KeySchema

type KeySchema struct {
	Type types.KeyType `json:"KeyType" yaml:"KeyType"`
	Name string        `json:"AttributeName" yaml:"AttributeName"`
}

func NewHashKey added in v0.1.12

func NewHashKey(name string) KeySchema

func NewRangeKey added in v0.1.12

func NewRangeKey(name string) KeySchema

func (KeySchema) Element

func (k KeySchema) Element() *types.KeySchemaElement

type Keys

type Keys []KeySchema

func NewKeys added in v0.1.12

func NewKeys(hashKey KeySchema, rangeKey ...KeySchema) Keys

func (Keys) Elements

func (keys Keys) Elements() []types.KeySchemaElement

func (Keys) Map

func (keys Keys) Map() map[string]types.KeyType

type Migrate

type Migrate interface {
	Read(ctx context.Context) (schemas []Schema, err error)
	Run(ctx context.Context, save SaveFunc) error
}

func New

func New(api MigrationApi, dirPath ...string) Migrate

func Parse

func Parse(api MigrationApi, schema string) Migrate

type Migration

type Migration struct {
	ID string `json:"id" yaml:"id" dynamodbav:"id"`
}

type MigrationApi

type MigrationApi interface {
	DescribeTable(ctx context.Context, params *dynamodb.DescribeTableInput, optFns ...func(*dynamodb.Options)) (*dynamodb.DescribeTableOutput, error)
	CreateTable(ctx context.Context, params *dynamodb.CreateTableInput, optFns ...func(*dynamodb.Options)) (*dynamodb.CreateTableOutput, error)
	UpdateTimeToLive(ctx context.Context, params *dynamodb.UpdateTimeToLiveInput, optFns ...func(*dynamodb.Options)) (*dynamodb.UpdateTimeToLiveOutput, error)
	UpdateTable(ctx context.Context, params *dynamodb.UpdateTableInput, optFns ...func(*dynamodb.Options)) (*dynamodb.UpdateTableOutput, error)
	DescribeTimeToLive(ctx context.Context, params *dynamodb.DescribeTimeToLiveInput, optFns ...func(*dynamodb.Options)) (*dynamodb.DescribeTimeToLiveOutput, error)
	DeleteTable(ctx context.Context, params *dynamodb.DeleteTableInput, optFns ...func(*dynamodb.Options)) (*dynamodb.DeleteTableOutput, error)

	GetItem(ctx context.Context, params *dynamodb.GetItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.GetItemOutput, error)
	PutItem(ctx context.Context, params *dynamodb.PutItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.PutItemOutput, error)
}

type Projection

type Projection struct {
	Type           types.ProjectionType `json:"ProjectionType" yaml:"ProjectionType"`
	AttributeNames []string             `json:"NonKeyAttributes" yaml:"NonKeyAttributes"`
}

func NewProjection added in v0.1.12

func NewProjection(t types.ProjectionType, attrs ...string) *Projection

func (Projection) Element

func (p Projection) Element() *types.Projection

type ProvisionedThroughput

type ProvisionedThroughput struct {
	Read  int64 `json:"ReadCapacityUnits" yaml:"ReadCapacityUnits"`
	Write int64 `json:"WriteCapacityUnits" yaml:"WriteCapacityUnits"`
}

func (ProvisionedThroughput) Element

func (ProvisionedThroughput) Update

type Resource

type Resource struct {
	Type       string      `json:"Type" yaml:"Type"`
	Properties TableSchema `json:"Properties" yaml:"Properties"`
}

func (*Resource) Checksum

func (r *Resource) Checksum() (h [32]byte, err error)

type Resources

type Resources map[string]Resource

type SaveFunc

type SaveFunc func(ctx context.Context, api MigrationApi, tableName string, record map[string]interface{}) error

type Schema

type Schema struct {
	Table   TableSchema              `json:"schema" yaml:"schema"`
	Records []map[string]interface{} `json:"records" yaml:"records"`
	// contains filtered or unexported fields
}

func ParseJson

func ParseJson(name string, body []byte) (schemas []Schema, err error)

func ParseYaml

func ParseYaml(name string, body []byte) (schemas []Schema, err error)

type SchemaBuilder added in v0.1.11

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

func NewSchema added in v0.1.11

func NewSchema(name string) *SchemaBuilder

func (*SchemaBuilder) Attributes added in v0.1.11

func (b *SchemaBuilder) Attributes(attrs ...Attribute) *SchemaBuilder

func (*SchemaBuilder) BillingMode added in v0.1.11

func (b *SchemaBuilder) BillingMode(mode types.BillingMode) *SchemaBuilder

func (*SchemaBuilder) Build added in v0.1.11

func (*SchemaBuilder) Get added in v0.1.12

func (b *SchemaBuilder) Get() Schema

func (*SchemaBuilder) GlobalSecondaryIndex added in v0.1.11

func (b *SchemaBuilder) GlobalSecondaryIndex(indexes ...SecondaryIndex) *SchemaBuilder

func (*SchemaBuilder) Keys added in v0.1.11

func (b *SchemaBuilder) Keys(keys ...KeySchema) *SchemaBuilder

func (*SchemaBuilder) LocalSecondaryIndex added in v0.1.11

func (b *SchemaBuilder) LocalSecondaryIndex(indexes ...SecondaryIndex) *SchemaBuilder

func (*SchemaBuilder) TableClass added in v0.1.11

func (b *SchemaBuilder) TableClass(class types.TableClass) *SchemaBuilder

func (*SchemaBuilder) Throughput added in v0.1.11

func (b *SchemaBuilder) Throughput(read, write int64) *SchemaBuilder

func (*SchemaBuilder) TimeToLive added in v0.1.11

func (b *SchemaBuilder) TimeToLive(attr string, enabled bool) *SchemaBuilder

type SchemaBuilders added in v0.1.12

type SchemaBuilders []*SchemaBuilder

func (SchemaBuilders) Build added in v0.1.12

type SchemaMigrate

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

func (*SchemaMigrate) Read added in v0.1.3

func (v *SchemaMigrate) Read(ctx context.Context) (schemas []Schema, err error)

func (*SchemaMigrate) Run

func (v *SchemaMigrate) Run(ctx context.Context, save SaveFunc) (err error)

type Schemas added in v0.1.12

type Schemas []Schema

func GetSchemas added in v0.1.12

func GetSchemas(builders ...*SchemaBuilder) Schemas

func (Schemas) GetSchemas added in v0.1.12

func (src Schemas) GetSchemas(ctx context.Context) ([]Schema, error)

type SecondaryIndex

type SecondaryIndex struct {
	Name       string                 `json:"IndexName" yaml:"IndexName"`
	Keys       Keys                   `json:"KeySchema" yaml:"KeySchema"`
	Projection *Projection            `json:"Projection" yaml:"Projection"`
	Throughput *ProvisionedThroughput `json:"ProvisionedThroughput,omitempty" yaml:"ProvisionedThroughput,omitempty"`
}

func NewSecondaryIndex added in v0.1.12

func NewSecondaryIndex(name string, keys Keys, opts ...IndexOption) SecondaryIndex

func (SecondaryIndex) CreateGlobal

func (s SecondaryIndex) CreateGlobal() types.GlobalSecondaryIndex

func (SecondaryIndex) CreateLocal

func (s SecondaryIndex) CreateLocal() types.LocalSecondaryIndex

type SecondaryIndexes

type SecondaryIndexes []SecondaryIndex

func (SecondaryIndexes) GlobalIndexes

func (indexes SecondaryIndexes) GlobalIndexes() []types.GlobalSecondaryIndex

func (SecondaryIndexes) LocalIndexes

func (indexes SecondaryIndexes) LocalIndexes() []types.LocalSecondaryIndex

func (SecondaryIndexes) UpdateGlobals

type TableSchema

type TableSchema struct {
	TableName            string                   `json:"TableName" yaml:"TableName"`
	Attributes           Attributes               `json:"AttributeDefinitions" yaml:"AttributeDefinitions"`
	Keys                 Keys                     `json:"KeySchema" yaml:"KeySchema"`
	Throughput           ProvisionedThroughput    `json:"ProvisionedThroughput" yaml:"ProvisionedThroughput"`
	BillingMode          types.BillingMode        `json:"BillingMode" yaml:"BillingMode"`
	GlobalSecondaryIndex SecondaryIndexes         `json:"GlobalSecondaryIndexes,omitempty" yaml:"GlobalSecondaryIndexes,omitempty"`
	LocalSecondaryIndex  SecondaryIndexes         `json:"LocalSecondaryIndexes,omitempty" yaml:"LocalSecondaryIndexes,omitempty"`
	TableClass           types.TableClass         `json:"TableClass" yaml:"TableClass"`
	TimeToLive           *TimeToLiveSpecification `json:"TimeToLiveSpecification,omitempty" yaml:"TimeToLiveSpecification,omitempty"`
	// contains filtered or unexported fields
}

func (TableSchema) Create

func (t TableSchema) Create(ctx context.Context, api MigrationApi) (out *dynamodb.CreateTableOutput, err error)

func (TableSchema) Delete

func (t TableSchema) Delete(ctx context.Context, api MigrationApi) (out *dynamodb.DeleteTableOutput, err error)

func (TableSchema) Exists

func (t TableSchema) Exists(ctx context.Context, api MigrationApi) (out *dynamodb.DescribeTableOutput, err error)

func (TableSchema) Update

type TableSchemaOption added in v0.1.12

type TableSchemaOption func(ts *TableSchema)

func WithTableNamePrefix added in v0.1.12

func WithTableNamePrefix(prefix string) TableSchemaOption

type Template

type Template struct {
	Version   string `json:"AWSTemplateFormatVersion" yaml:"AWSTemplateFormatVersion"`
	Resources `json:"Resources" yaml:"Resources"`
}

type TimeToLiveSpecification

type TimeToLiveSpecification struct {
	AttributeName string `json:"AttributeName" yaml:"AttributeName"`
	Enabled       bool   `json:"Enabled" yaml:"Enabled"`
}

func (TimeToLiveSpecification) Element

Jump to

Keyboard shortcuts

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